def createOptions(): """ override this with your own function to set defaults """ import mtoa.aovs as aovs import mtoa.hooks as hooks # the shared option ensures that it is only created if it does not exist options = pm.createNode('aiOptions', skipSelect=True, shared=True, name='defaultArnoldRenderOptions') filterNode = pm.createNode('aiAOVFilter', name='defaultArnoldFilter', skipSelect=True, shared=True) driverNode = pm.createNode('aiAOVDriver', name='defaultArnoldDriver', skipSelect=True, shared=True) displayDriverNode = pm.createNode('aiAOVDriver', name='defaultArnoldDisplayDriver', skipSelect=True, shared=True) if (filterNode or driverNode) and not options: options = pm.PyNode('defaultArnoldRenderOptions') # options previously existed, so we need to upgrade upgradeAOVOutput(options, filterNode, driverNode) # if we're just creating the options node, then be sure to connect up the driver and filter if filterNode: # newly created default filter hooks.setupFilter(filterNode) else: filterNode = pm.PyNode('defaultArnoldFilter') if driverNode: # newly created default driver hooks.setupDriver(driverNode) else: driverNode = pm.PyNode('defaultArnoldDriver') if options: # newly created options hooks.setupDefaultAOVs(aovs.AOVInterface(options)) hooks.setupOptions(options) pm.setAttr('defaultArnoldRenderOptions.version', str(cmds.pluginInfo( 'mtoa', query=True, version=True))) else: options = pm.PyNode('defaultArnoldRenderOptions') if displayDriverNode: # options exist, but not display driver: upgrade from older version of mtoa hooks.setupDefaultAOVs(aovs.AOVInterface(options)) if displayDriverNode: # newly created default driver displayDriverNode.aiTranslator.set('maya') # GUI only displayDriverNode.outputMode.set(0) hooks.setupDriver(displayDriverNode) displayDriverNode.message.connect(options.drivers, nextAvailable=True) elif not options.drivers.inputs(): pm.connectAttr('defaultArnoldDisplayDriver.message', options.drivers, nextAvailable=True) try: pm.connectAttr('%s.message' % filterNode.name(), '%s.filter' % options.name(), force=True) except: pass try: pm.connectAttr('%s.message' % driverNode.name(), '%s.driver' % options.name(), force=True) except: pass
def outputChangedCallback(self, aovOutputAttr, newValue, outputType, defaultNode): """ change callback for both filter and driver menus outputType: either 'aiAOVDriver' or 'aiAOVFilter' """ conn = aovOutputAttr.inputs() if newValue.startswith('<'): isDefault = True pm.connectAttr(defaultNode + '.message', aovOutputAttr, force=True) outputNode = pm.PyNode(defaultNode) pm.select(outputNode) if conn and not conn[0].outputs(): utils.safeDelete(conn[0]) else: isDefault = False if conn and conn[0].outputs(): # other AOVs are dependent on existing filter/driver. create and connect a new one outputNode = pm.createNode(outputType) pm.connectAttr(outputNode.message, aovOutputAttr, force=True) else: outputNode = conn[0] newValue = newValue.strip('<>') outputNode.aiTranslator.set(newValue) if outputType == 'aiAOVFilter': self.filterNode = outputNode hooks.setupFilter(outputNode, self.aovItem.aovName()) menu = self.filterMenu else: self.driverNode = outputNode hooks.setupDriver(outputNode, self.aovItem.aovName()) menu = self.driverMenu transAttr = outputNode.attr('aiTranslator') if not isDefault: # change the selected menu item when the translator attribute changes for our driver/filter pm.scriptJob(attributeChange=[ transAttr, lambda: self.translatorChanged(transAttr, menu) ], replacePrevious=True, parent=menu) else: # delete pre-existing scriptJob pm.scriptJob(attributeChange=[transAttr, lambda: self.dummy()], replacePrevious=True, parent=menu) self.aovItem.outputsChanged = True
def outputChangedCallback(self, aovOutputAttr, newValue, outputType, defaultNode): """ change callback for both filter and driver menus outputType: either 'aiAOVDriver' or 'aiAOVFilter' """ conn = aovOutputAttr.inputs() if newValue.startswith('<'): isDefault=True pm.connectAttr(defaultNode + '.message', aovOutputAttr, force=True) outputNode = pm.PyNode(defaultNode) pm.select(outputNode) if conn and not conn[0].outputs(): utils.safeDelete(conn[0]) else: isDefault=False if conn and conn[0].outputs(): # other AOVs are dependent on existing filter/driver. create and connect a new one outputNode = pm.createNode(outputType) pm.connectAttr(outputNode.message, aovOutputAttr, force=True) else: outputNode = conn[0] newValue = newValue.strip('<>') outputNode.aiTranslator.set(newValue) if outputType == 'aiAOVFilter': self.filterNode = outputNode hooks.setupFilter(outputNode, self.aovItem.aovName()) menu = self.filterMenu else: self.driverNode = outputNode hooks.setupDriver(outputNode, self.aovItem.aovName()) menu = self.driverMenu transAttr = outputNode.attr('aiTranslator') if not isDefault: # change the selected menu item when the translator attribute changes for our driver/filter pm.scriptJob(attributeChange=[transAttr, lambda: self.translatorChanged(transAttr, menu)], replacePrevious=True, parent=menu) else: # delete pre-existing scriptJob pm.scriptJob(attributeChange=[transAttr, lambda: self.dummy()], replacePrevious=True, parent=menu) self.aovItem.outputsChanged = True
def createOptions(): """ override this with your own function to set defaults """ import mtoa.aovs as aovs import mtoa.hooks as hooks # the shared option ensures that it is only created if it does not exist options = pm.createNode('aiOptions', skipSelect=True, shared=True, name='defaultArnoldRenderOptions') filterNode = pm.createNode('aiAOVFilter', name='defaultArnoldFilter', skipSelect=True, shared=True) driverNode = pm.createNode('aiAOVDriver', name='defaultArnoldDriver', skipSelect=True, shared=True) displayDriverNode = pm.createNode('aiAOVDriver', name='defaultArnoldDisplayDriver', skipSelect=True, shared=True) if (filterNode or driverNode) and not options: options = pm.PyNode('defaultArnoldRenderOptions') # options previously existed, so we need to upgrade upgradeAOVOutput(options, filterNode, driverNode) # if we're just creating the options node, then be sure to connect up the driver and filter if filterNode: # newly created default filter hooks.setupFilter(filterNode) else: filterNode = pm.PyNode('defaultArnoldFilter') if driverNode: # newly created default driver hooks.setupDriver(driverNode) else: driverNode = pm.PyNode('defaultArnoldDriver') if options: # newly created options hooks.setupDefaultAOVs(aovs.AOVInterface(options)) hooks.setupOptions(options) pm.setAttr('defaultArnoldRenderOptions.version', str(cmds.pluginInfo('mtoa', query=True, version=True))) else: options = pm.PyNode('defaultArnoldRenderOptions') if displayDriverNode: # options exist, but not display driver: upgrade from older version of mtoa hooks.setupDefaultAOVs(aovs.AOVInterface(options)) if displayDriverNode: # newly created default driver displayDriverNode.aiTranslator.set('maya') # GUI only displayDriverNode.outputMode.set(0) hooks.setupDriver(displayDriverNode) displayDriverNode.message.connect(options.drivers, nextAvailable=True) elif not options.drivers.inputs(): pm.connectAttr('defaultArnoldDisplayDriver.message', options.drivers, nextAvailable=True) try: pm.connectAttr('%s.message' % filterNode.name(), '%s.filter' % options.name(), force=True) except: pass try: pm.connectAttr('%s.message' % driverNode.name(), '%s.driver' % options.name(), force=True) except: pass