Skip to content

Accept relative paths in the model xml when loading from xml #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mujoco_py/cymj.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ def load_model_from_path(str path):
raise Exception('Failed to load XML file: %s. mj_loadXML error: %s' % (path, errstr,))
return WrapMjModel(model)

def load_model_from_xml(str xml_str):
def load_model_from_xml(str xml_str, str path=None):
"""
Loads and returns a PyMjModel model from a string containing XML markup.
Saves the XML string used to create the returned model in `model.xml`.
"""
cdef char errstr[300]
cdef mjModel *model
with wrap_mujoco_warning():
with tempfile.NamedTemporaryFile(suffix=".xml", delete=True) as fp:
with tempfile.NamedTemporaryFile(suffix=".xml", dir=path, delete=True) as fp:
fp.write(xml_str.encode())
fp.flush()
model = mj_loadXML(fp.name.encode(), NULL, errstr, 300)
Expand Down