def getOverrides(layer, typed=None): ''' :example from renderLibrary.utils import studioMaya studioMaya.getOverrides('batman', typed=OpenMaya.MFn.kMesh) ''' selectLayer(layer) mcommand_result = OpenMaya.MCommandResult() command = 'editRenderLayerAdjustment -q -layer %s;' % layer OpenMaya.MGlobal.executeCommand(command, mcommand_result, False, False) plugs = [] mcommand_result.getResult(plugs) if not typed: return plugs _plugs = [] for plug in plugs: mn = mayaNode.Connect(node=plug) mplug = mn.getMPlug() dagpath = OpenMaya.MDagPath() dagpath.getAPathTo(mplug.node(), dagpath) if not dagpath.hasFn(typed): continue _plugs.append(plug) return _plugs
def getRenderSteup(): ''' :description get the current render steup whether Legacy or New Render Setup 1 = (new) Render Setup is active 0 = Legacy Render Layers is active :example from renderLibrary.utils import studioMaya studioMaya.getRenderSteup() ''' mcommand_result = OpenMaya.MCommandResult() command = 'optionVar -q \"renderSetupEnable\";' OpenMaya.MGlobal.executeCommand(command, mcommand_result, False, False) mscript_util = OpenMaya.MScriptUtil() index_ptr = mscript_util.asIntPtr() mcommand_result.getResult(index_ptr) _value = mscript_util.getInt(index_ptr) setups = { 0: 'Legacy Render Layers', 1: 'Render Setup' } OpenMaya.MGlobal.displayInfo('current render: %s' % setups.get(_value)) return _value
def assignToMaterial(self, objects, shading_group): mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand('sets -e -forceElement %s %s;' % ( shading_group, ' '.join(objects)), mcommand_result, True, True) results = [] mcommand_result.getResult(results) return results
def getRenderEngine(): mcommand_result = OpenMaya.MCommandResult() command = 'getAttr \"defaultRenderGlobals.currentRenderer\"', OpenMaya.MGlobal.executeCommand(command, mcommand_result, False, False) render_engine = mcommand_result.stringResult() OpenMaya.MGlobal.displayInfo('current render engine: %s' % render_engine) return render_engine
def addTocontainer(self, children): parent = core.PyNode(self.parent).name() children = [core.PyNode(each).name() for each in children] mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand( 'container -e -an {\"%s\"} \"%s\"' % ('\", \"'.join( children), parent), mcommand_result, True, True) return True
def input_connections(self, node): mcommand_result = OpenMaya.MCommandResult() mel_command = 'listConnections -s on -d off -p on \"%s\"' % (node) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) inputs = [] mcommand_result.getResult(inputs) return inputs
def list_knode_types(self, node_type): mcommand_result = OpenMaya.MCommandResult() mel_command = 'listNodeTypes \"%s\"' % node_type OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) return results
def get_knode_types(self, typed): mcommand_result = OpenMaya.MCommandResult() mel_command = 'listNodeTypes \"%s\"' % typed OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) knode_types = [] mcommand_result.getResult(knode_types) return knode_types
def getSkincluster(self, geometry): if isinstance(geometry, OpenMaya.MDagPath): geometry = geometry.fullPathName().encode().split('|')[-1] mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand( 'findRelatedSkinCluster(\"%s\");' % geometry, mcommand_result, True, True) results = [] mcommand_result.getResult(results) return results[0].encode()
def output_connections(self, node): mcommand_result = OpenMaya.MCommandResult() mel_command = 'listConnections -s off -d on -p on \"%s\"' % (node) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) outputs = [] mcommand_result.getResult(outputs) if outputs: return outputs[0] return None
def freeze_transformations(self, node): if not isinstance(node, str): node = self.get_name(node) mcommand_result = OpenMaya.MCommandResult() mel_command = 'makeIdentity -apply true -t 1 -r 1 -s 1 -n 0 -pn 1 \"%s\"' % node OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) return results
def has_plugin_loaded(self, plugin): mcommand_result = OpenMaya.MCommandResult() mel_command = 'pluginInfo -q -loaded \"%s\"' % plugin OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) util = OpenMaya.MScriptUtil() util.createFromInt(0) id_pointer = util.asIntPtr() mcommand_result.getResult(id_pointer) return OpenMaya.MScriptUtil(id_pointer).asBool()
def create_shading_engine(self, name): # mfn_dependency_node= OpenMaya.MFnDependencyNode() # mfn_dependency_node.create('shadingEngine') # mfn_dependency_node.setName(name) mcommand_result = OpenMaya.MCommandResult() mel_command = 'sets -renderable true -noSurfaceShader true -empty -name \"%s\"' % name OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) return results[0]
def get_layer_adjustment(self, layer): if isinstance(layer, OpenMaya.MObject): self.render_Layer.setObject(layer) layer = self.render_Layer.name() mcommand_result = OpenMaya.MCommandResult() mel_command = 'editRenderLayerAdjustment -q -layer %s;' % layer OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) override_utils = [] mcommand_result.getResult(override_utils) return override_utils
def create(self, name, clear=False): name = name.split('|')[-1] if clear: OpenMaya.MGlobal.clearSelectionList() mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand('cluster -n %s' % name, mcommand_result, True, True) OpenMaya.MGlobal.clearSelectionList() results = [] mcommand_result.getResult(results) cluster, clusterHandle = results return cluster.encode(), clusterHandle.encode()
def getAllConnections(): # Travarsing the Dependency Graph to find all the connection of Car:Seats_SHD mfnDependencyNode = makeDependencyNode(nodeName) object_name = mfnDependencyNode.name().encode() mcommand_result = om1.MCommandResult() om1.MGlobal.executeCommand('listHistory %s' % object_name, mcommand_result, False, True) results = [] mcommand_result.getResult(results) for each_result in results: connections.append(each_result.encode()) return connections
def remove_nodes(self, mobject_arry): nodes = [] for x in range(mobject_arry.length()): if not self.object_exists(mobject_arry[x]): continue name = self.get_name(mobject_arry[x]) nodes.append(name) mcommand_result = OpenMaya.MCommandResult() mel_command = 'delete %s' % ' '.join(nodes) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results)
def remove_node(self, mobject): if isinstance(mobject, unicode): mobject = mobject.encode() if not isinstance(mobject, str): mobject = self.get_name(mobject) if not self.object_exists(mobject): return mcommand_result = OpenMaya.MCommandResult() mel_command = 'delete \"%s\"' % mobject OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results)
def get_maya_settings(self): mel_commands = { 'unit': 'currentUnit -q -linear -f;', 'angular': 'currentUnit -q -angle -f;', 'time': 'currentUnit -q -time -f', 'axis': 'upAxis -q -axis;' } maya_settings = {} for k, mel_command in mel_commands.items(): mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) maya_settings.setdefault(k, mcommand_result.stringResult()) return maya_settings
def assign_to_shading_engine(self, objects, shading_group): mcommand_result = OpenMaya.MCommandResult() exists_objects = [] for object in objects: if not self.object_exists(object): continue exists_objects.append(object.encode()) mel_command = 'sets -e -forceElement %s %s;' % ( shading_group, ' '.join(exists_objects)) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) return results
def unParent(self, object): if not object: return if isinstance(object, OpenMaya.MDagPath): object = object.fullPathName().encode() if isinstance(object, OpenMaya.MObject): mfn_dag_node = OpenMaya.MFnDagNode(object) object = mfn_dag_node.fullPathName().encode() mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand('parent -w %s' % object, mcommand_result, True, True) OpenMaya.MGlobal.clearSelectionList() results = [] mcommand_result.getResult(results) return results
def set_parent(self, child, parent): if isinstance(child, OpenMaya.MObject): child = OpenMaya.MFnDagNode(child) if isinstance(parent, OpenMaya.MObject): parent = OpenMaya.MFnDagNode(parent) self.unparent(child) mcommand_result = OpenMaya.MCommandResult() mel_command = 'parent \"%s\" \"%s\" ' % (child.fullPathName(), parent.fullPathName()) print mel_command OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) mobject = self.get_mobject(results[0]) return mobject
def create_knode(self, name, node_type): node_types = self.get_shading_node_types() if node_type not in node_types: warnings.warn( 'node type <%s> not found in the hyper shade library' % node_type) return current_dg_type = self.shader_node_bundles[node_types[node_type]] mcommand_result = OpenMaya.MCommandResult() mel_command = 'shadingNode -%s \"%s\" -n \"%s\"' % (current_dg_type, node_type, name) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) results = [] mcommand_result.getResult(results) mobject = self.get_mobject(results[0]) return mobject
def list_attributes(self, node, default=False): mcommand_result = OpenMaya.MCommandResult() mel_command = 'listAttr -r -w -u -m -hd \"%s\"' % (node) OpenMaya.MGlobal.executeCommand(mel_command, mcommand_result, False, True) outputs = [] mcommand_result.getResult(outputs) mplug_array = OpenMaya.MPlugArray() for output in outputs: mplug = self.get_mplug('%s.%s' % (node, output)) if default: mplug_array.append(mplug) else: if mplug.isDefaultValue(): continue mplug_array.append(mplug) return mplug_array
def getSceneScaleFactor(self): cmdResult = OpenMaya.MCommandResult() sScale = OpenMaya.MGlobal.executeCommand('currentUnit -q -linear', cmdResult, False, False) sceneUnits = cmdResult.stringResult() #self.log('Found scene units: ' + sceneUnits ) if sceneUnits == "cm": return 0.01 elif sceneUnits == "mm": return 0.001 elif sceneUnits == "in": return 0.0254 elif sceneUnits == "ft": return 0.3048 elif sceneUnits == "yd": return 0.9144 else: return 1.0
def GetDagTransform(dag): ft = om.MFnDagNode(dag.transform()) a = om.MCommandResult() om.MGlobal.executeCommand('getAttr '+ft.findPlug('translate').name(), a) translate3 = om.MDoubleArray() a.getResult(translate3) print 'translate ', translate3 om.MGlobal.executeCommand('getAttr '+ft.findPlug('rotate').name(), a) rotate3 = om.MDoubleArray() a.getResult(rotate3) print 'rotate ', rotate3 om.MGlobal.executeCommand('getAttr '+ft.findPlug('scale').name(), a) scale3 = om.MDoubleArray() a.getResult(scale3) print 'scale ', scale3 return (translate3, rotate3, scale3)
def parentTo(self, source, target): if not source or not target: return if isinstance(source, OpenMaya.MDagPath): source = source.fullPathName().encode() if isinstance(source, OpenMaya.MObject): mfn_dag_node = OpenMaya.MFnDagNode(source) source = mfn_dag_node.fullPathName().encode() if isinstance(target, OpenMaya.MDagPath): target = target.fullPathName().encode() if isinstance(target, OpenMaya.MObject): mfn_dag_node = OpenMaya.MFnDagNode(target) target = mfn_dag_node.fullPathName().encode() mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand('parent %s %s' % (source, target), mcommand_result, True, True) OpenMaya.MGlobal.clearSelectionList() results = [] mcommand_result.getResult(results) return results
def getNetworks(self, object): if not object: return if isinstance(object, OpenMaya.MObject): mfn_dependency_node = OpenMaya.MFnDependencyNode(object) object = mfn_dependency_node.name().encode() mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand( 'listHistory %s' % object, mcommand_result, True, True) results = [] mcommand_result.getResult(results) networks = [] for each_result in results: py_node = core.PyNode(each_result) if py_node.type() in self.unknown_types: continue if each_result in networks: continue networks.append(each_result.encode()) return networks
def getRenderMembers(layer, typed=None): ''' :example from renderLibrary.utils import studioMaya studioMaya.getRenderMembers('batman', typed=OpenMaya.MFn.kMesh) ''' selectLayer(layer) mcommand_result = OpenMaya.MCommandResult() command = 'editRenderLayerMembers -q %s;' % layer OpenMaya.MGlobal.executeCommand(command, mcommand_result, False, False) members = [] mcommand_result.getResult(members) if not typed: return members _members = [] for member in members: mn = mayaNode.Connect(node=member) dagpath = mn.getDagPath() if not dagpath.hasFn(typed): continue _members.append(dagpath.fullPathName()) return _members
def findShaderNodes(self, mobject): mfn_dependency_node = OpenMaya.MFnDependencyNode(mobject) object_name = mfn_dependency_node.name().encode() mcommand_result = OpenMaya.MCommandResult() OpenMaya.MGlobal.executeCommand('listHistory %s' % object_name, mcommand_result, True, True) results = [] mcommand_result.getResult(results) assign_objects = self.getAssignObjects(mobject) results = [] mcommand_result.getResult(results) networks = [] for each_result in results: py_node = core.PyNode(each_result) if py_node.type() in self.unknown_types: continue if py_node.name() in self.default_nodes: continue if py_node.name() in assign_objects: continue if each_result in networks: continue networks.append(each_result.encode()) return networks, assign_objects