Returns the integer ID of a specified MuJoCo object. Args: name: String specifying the name of the object to query. object_type: The type of the object. Can be either a lowercase string (e.g. 'body', 'geom') or an `mjtObj` enum value. Returns: An integer object ID
(self, name, object_type)
| 337 | del self._ptr |
| 338 | |
| 339 | def name2id(self, name, object_type): |
| 340 | """Returns the integer ID of a specified MuJoCo object. |
| 341 | |
| 342 | Args: |
| 343 | name: String specifying the name of the object to query. |
| 344 | object_type: The type of the object. Can be either a lowercase string |
| 345 | (e.g. 'body', 'geom') or an `mjtObj` enum value. |
| 346 | |
| 347 | Returns: |
| 348 | An integer object ID. |
| 349 | |
| 350 | Raises: |
| 351 | Error: If `object_type` is not a valid MuJoCo object type, or if no object |
| 352 | with the corresponding name and type was found. |
| 353 | """ |
| 354 | if isinstance(object_type, str): |
| 355 | object_type = _str2type(object_type) |
| 356 | obj_id = mujoco.mj_name2id(self.ptr, object_type, name) |
| 357 | if obj_id == -1: |
| 358 | raise Error("Object of type {!r} with name {!r} does not exist.".format( |
| 359 | _type2str(object_type), name)) |
| 360 | return obj_id |
| 361 | |
| 362 | def id2name(self, object_id, object_type): |
| 363 | """Returns the name associated with a MuJoCo object ID, if there is one. |