Skip to content

Commit

Permalink
Document element name lookup in MjSpec.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 725258206
Change-Id: I5c9a85d25787eb38e9e8c3854eda2581700e188e
  • Loading branch information
yuvaltassa authored and copybara-github committed Feb 10, 2025
1 parent e54f3c2 commit a6dd5f0
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions doc/python.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^
Expand All @@ -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``
--------------------------
Expand Down

0 comments on commit a6dd5f0

Please sign in to comment.