Skip to content

Instantly share code, notes, and snippets.

@yunho-c
Created August 9, 2025 18:41
Show Gist options
  • Select an option

  • Save yunho-c/42622ba7f7623e240cd560fbaa1321f9 to your computer and use it in GitHub Desktop.

Select an option

Save yunho-c/42622ba7f7623e240cd560fbaa1321f9 to your computer and use it in GitHub Desktop.

Revisions

  1. yunho-c created this gist Aug 9, 2025.
    18 changes: 18 additions & 0 deletions urdf2mjcf.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    import argparse
    import mujoco
    from pathlib import Path


    def main():
    parser = argparse.ArgumentParser(description="Convert a URDF file to a MuJoCo XML file.")
    parser.add_argument("input_file", help="The input URDF file path.")
    # parser.add_argument("output_file", help="The output XML file path.")
    args = parser.parse_args()

    model = mujoco.MjModel.from_xml_path(args.input_file)
    # mujoco.mj_saveLastXML(args.output_file, model)
    mujoco.mj_saveLastXML(args.input_file.replace(".urdf", ".xml"), model)


    if __name__ == "__main__":
    main()