Documentation
IPS_FindObjectIDByName
int IPS_FindObjectIDByName (string $Name, int $ParentID)
Parameters
| Name | Object name to search for |
| ParentID | ID of the object whose direct children are searched |
Returns
ID of the first found object, otherwise 1 (invalid ID)
Description
The function searches the direct children of the object with the ID ParentID for an object with the name Name and returns its ID. Deeper nested objects are not searched. The comparison is exact (case-sensitive), the object type does not matter. 0 (root) is also allowed as ParentID.
Unlike IPS_GetObjectIDByName, the function does not fail if no matching object exists, but returns the invalid ID 1.
If no object is found, the result is 1, not FALSE or 0. Valid object IDs are always greater than or equal to 10000, so the result should be compared with 1 explicitly.
As names are not unique, the ID of the first found object is returned if several objects share the same name. For a unique search, IPS_FindObjectIDByIdent should be used.
If Name is an empty string, the function fails with "Name cannot be empty". If the object ParentID does not exist, it fails with "Object #... does not exist".
Example
$id = IPS_FindObjectIDByName("Temperature", 12345);
if ($id === 1) {
echo "No object with the name 'Temperature' found";
} else {
echo "Found: #" . $id;
}