Exporting a reference using Python.

Referencing in Maya is great in theory but there are a lot of bugs in practice. The scene needs to be set up in a certain way to ensure that the referencing works properly. This can be done by hand of course but can get tedious. Here are some useful bits of python code that can be used to speed up the process.

'''Reference publisher'''
import maya.cmds as cmds

#Save the original file. Stored in a variable for later recollection.
fName = cmds.file(save=True) 

#Delete any keyframes in the scene
select(all=True)
cutKey() 

#Delete any display layers in the scene
delete('displayLayer1')
delete('displayLayer2')

#Set any attributes to their default values
setAttr('item1.rotateY', 0)

#Select items to be exported
select('Top_Node')

#Export the selected items.
cmds.file('C:/project/cg/scenes/MasterFile.mb',exportSelected=True, type='mayaBinary')

#Open the original scene to continue working
cmds.file(fName, force=True, open=True)

Leave a Reply

Your email address will not be published. Required fields are marked *