Search code examples
pythonmaya

How to export/duplicate object to existing maya file


I have a Maya object which I want to export into an existing Maya file.

I know that I can export a selected object into a new Maya file.

cmds.file('filename', type='mayaBinary', exportSelected=True)

but I want to export into an existing one.

How can I do that?


Solution

  • You can't append anything to a maya file, and the best way to do is maybe like this

    cmds.file('/tmp/tmp.mb', type='mayaBinary', exportSelected=True)
    cmds.file(new=True,f=True)
    cmds.file('/your/old/file.mb', open=True, f=True)
    cmds.filec('/tmp/tmp.mb', import=True, mergeNamespacesOnClash=True)
    cmds.file(save=True)