Document element name lookup in MjSpec.

PiperOrigin-RevId: 725258206
Change-Id: I5c9a85d25787eb38e9e8c3854eda2581700e188e
This commit is contained in:
Yuval Tassa
2025-02-10 10:09:35 -08:00
committed by Copybara-Service
parent e54f3c222d
commit a6dd5f086f
+13 -7
View File
@@ -587,14 +587,19 @@ Convenience methods
The Python bindings provide a number of convenience methods and attributes not directly available in the C API in order
to make model editing easier:
Finding elements
^^^^^^^^^^^^^^^^
The ``MjSpec`` object has methods like ``find_body(), find_joint(), find_site(), ...`` for every type of name-able
:ref:`mjtObj` type. These methods take a name string and return the element with that name or ``None`` if it does not
exist.
Element lists
^^^^^^^^^^^^^
Lists of all elements in a spec can be accessed using named properties, using the plural form. For example,
``spec.meshes`` returns a list of all meshes in the spec.
The following properties are implemented: ``sites``, ``geoms``, ``joints``, ``lights``, ``cameras``, ``bodies``,
``frames``, ``materials``, ``meshes``, ``pairs``, ``equalities``, ``tendons``, ``actuators``, ``skins``, ``textures``,
``texts``, ``tuples``, ``flexes``, ``hfields``, ``keys``, ``numerics``, ``excludes``, ``sensors``, ``plugins``.
``spec.meshes`` returns a list of all meshes in the spec. The following properties are implemented: ``sites``,
``geoms``, ``joints``, ``lights``, ``cameras``, ``bodies``, ``frames``, ``materials``, ``meshes``, ``pairs``,
``equalities``, ``tendons``, ``actuators``, ``skins``, ``textures``, ``texts``, ``tuples``, ``flexes``, ``hfields``,
``keys``, ``numerics``, ``excludes``, ``sensors``, ``plugins``.
Tree traversal
^^^^^^^^^^^^^^
@@ -611,8 +616,9 @@ Recursive search:
``body.find_all(mujoco.mjtObj.mjOBJ_SITE)`` or ``body.find_all('site')`` will return a list of all sites under the
body.
Additionally, the parent body of a given element - including bodies and frames - can be accessed via the ``parent``
property. For example, the parent of a site can be accessed via ``site.parent``.
Parent:
The parent body of a given element -- including bodies and frames -- can be accessed via the ``parent`` property.
For example, the parent of a site can be accessed via ``site.parent``.
Relationship to ``PyMJCF``
--------------------------