From a7fed25fdd1284bff7eed17c8bd71db38f92c57f Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Tue, 10 Dec 2024 08:03:58 -0800 Subject: [PATCH] Document how to save `MjSpec` to XML. Fixes #2075 PiperOrigin-RevId: 704712337 Change-Id: I51c1a14c5c48ffc8e37d9e31162a3e70a3b10313 --- doc/python.rst | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/python.rst b/doc/python.rst index 5a97f377..ddaeb0a1 100644 --- a/doc/python.rst +++ b/doc/python.rst @@ -479,6 +479,7 @@ Below is a minimal usage example, more examples can be found in the Model Editin import mujoco spec = mujoco.MjSpec() + spec.modelname = "my model" body = spec.worldbody.add_body( pos=[1, 2, 3], quat=[0, 1, 0, 0], @@ -503,9 +504,30 @@ The ``MjSpec`` object wraps the :ref:`mjSpec` struct and can be constructed in t Note the ``from_string()`` and ``from_file()`` methods can only be called at construction time. -Attachments +Save to XML ----------- +Compiled ``MjSpec`` objects can be saved to XML string with the ``to_xml()`` method: + +.. code-block:: python + + print(spec.to_xml()) + +.. code-block:: XML + + + + + + + + + + + +Attachment +---------- + It is possible to combine multiple specs by using attachments. The following options are possible: - Attach a body from the child spec to a frame in the parent spec: ``body.attach_body(body, prefix, suffix)``, returns