Python maya.cmds.createNode() Examples
The following are 30
code examples of maya.cmds.createNode().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: pipeline.py From core with MIT License | 7 votes |
def lock(): """Lock scene Add an invisible node to your Maya scene with the name of the current file, indicating that this file is "locked" and cannot be modified any further. """ if not cmds.objExists("lock"): with lib.maintained_selection(): cmds.createNode("objectSet", name="lock") cmds.addAttr("lock", ln="basename", dataType="string") # Permanently hide from outliner cmds.setAttr("lock.verticesOnlySet", True) fname = cmds.file(query=True, sceneName=True) basename = os.path.basename(fname) cmds.setAttr("lock.basename", basename, type="string")
Example #2
Source File: nVec.py From mMath with MIT License | 6 votes |
def scalar_static(self, value): """ This is a static scalar multiplication of the vector By static it means it multiplies by a fixed value which is not dynamic like an attribute connection Args: :value: float,int, the value for which we wist to scale the vector for :return: NVec instance """ mult = cmds.createNode("multiplyDivide", n= self._generator.next()+ '_scalarStatic') cmds.setAttr(mult + '.input2X',value) cmds.setAttr(mult + '.input2Y',value) cmds.setAttr(mult + '.input2Z',value) cmds.connectAttr(self.attribute_name, mult + '.input1') return NVec.with_generator(mult+ '.output', self._generator)
Example #3
Source File: lib.py From core with MIT License | 6 votes |
def maintained_selection(): """Maintain selection during context Example: >>> scene = cmds.file(new=True, force=True) >>> node = cmds.createNode("transform", name="Test") >>> cmds.select("persp") >>> with maintained_selection(): ... cmds.select("Test", replace=True) >>> "Test" in cmds.ls(selection=True) False """ previous_selection = cmds.ls(selection=True) try: yield finally: if previous_selection: cmds.select(previous_selection, replace=True, noExpand=True) else: cmds.select(clear=True)
Example #4
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def __eq__(self, other): """Compare plug to `other` Example: >>> node = createNode("transform") >>> node["visibility"] == True True >>> node["visibility"] == node["nodeState"] False >>> node["visibility"] != node["nodeState"] True """ if isinstance(other, Plug): other = other.read() return self.read() == other
Example #5
Source File: nVec.py From mMath with MIT License | 6 votes |
def from_value(cls, value, base_name): """ Generating a scalar vector from a value This function generates a node and a channel used to host the value and attach the channel to a NScalar vector class Args: :value: float,int, the value of the NScalar :base_name: str, the name we will use for the node + "_vec", the attribute name will be generated with base_name + "_from_value" """ node = cmds.createNode("transform", n= base_name + '_vec') attr_name = base_name + "_from_value" cmds.addAttr(node, ln = attr_name, at="float", k=1) cmds.setAttr(node + '.' + attr_name, value) return cls(node + '.' + attr_name , base_name)
Example #6
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def asMatrix(self, time=None): """Return plug as MMatrix Example: >>> node1 = createNode("transform") >>> node2 = createNode("transform", parent=node1) >>> node1["translate"] = (0, 5, 0) >>> node2["translate"] = (0, 5, 0) >>> plug1 = node1["matrix"] >>> plug2 = node2["worldMatrix"][0] >>> mat1 = plug1.asMatrix() >>> mat2 = plug2.asMatrix() >>> mat = mat1 * mat2 >>> tm = TransformationMatrix(mat) >>> list(tm.translation()) [0.0, 15.0, 0.0] """ context = om.MDGContext.kNormal if time is not None: context = om.MDGContext(om.MTime(time, om.MTime.uiUnit())) return om.MFnMatrixData(self._mplug.asMObject(context)).matrix()
Example #7
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def __floordiv__(self, other): """Disconnect attribute via A // B Example: >>> nodeA = createNode("transform") >>> nodeB = createNode("transform") >>> nodeA["tx"] >> nodeB["tx"] >>> nodeA["tx"] = 5 >>> nodeB["tx"] == 5 True >>> nodeA["tx"] // nodeB["tx"] >>> nodeA["tx"] = 0 >>> nodeB["tx"] == 5 True """ self.disconnect(other)
Example #8
Source File: dpIsolate.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def dpIsolate(self, attrName, nodeList, *args): """ Function to run isolate setup. """ # get father zero out transform node zeroGrp = cmds.listRelatives(nodeList[2], allParents=True, type="transform")[0] # create parent constraint pConst = cmds.parentConstraint(nodeList[0], nodeList[1], zeroGrp, maintainOffset=True, skipTranslate=["x", "y", "z"])[0] # add isolate attribute to selected control cmds.addAttr(nodeList[2], longName=attrName, defaultValue=1.0, minValue=0, maxValue=1, keyable=True) # create reverse node reverseNode = cmds.createNode('reverse', name=nodeList[2]+"_"+attrName.capitalize()+"_Rev") # do isolate connections cmds.connectAttr(nodeList[2]+"."+attrName, pConst+"."+nodeList[0]+"W0", force=True) cmds.connectAttr(nodeList[2]+"."+attrName, reverseNode+".inputX", force=True) cmds.connectAttr(reverseNode+".outputX", pConst+"."+nodeList[1]+"W1", force=True) cmds.select(nodeList[2])
Example #9
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def extend(self, values): """Append multiple values to the end of an array Arguments: values (tuple): If values, create a new entry and append it. If cmdx.Plug's, create a new entry and connect it. Example: >>> node = createNode("transform") >>> node["myArray"] = Double(array=True) >>> node["myArray"].extend([1.0, 2.0, 3.0]) >>> node["myArray"][0] 1.0 >>> node["myArray"][-1] 3.0 """ for value in values: self.append(value)
Example #10
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def asTransformationMatrix(self, time=None): """Return plug as TransformationMatrix Example: >>> node = createNode("transform") >>> node["translateY"] = 12 >>> node["rotate"] = 1 >>> tm = node["matrix"].asTm() >>> map(round, tm.rotation()) [1.0, 1.0, 1.0] >>> list(tm.translation()) [0.0, 12.0, 0.0] """ return TransformationMatrix(self.asMatrix(time)) # Alias
Example #11
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def __bool__(self): """if plug: Example: >>> node = createNode("transform") >>> node["tx"] = 10 >>> if node["tx"]: ... True ... True """ return bool(self.read()) # Python 3
Example #12
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def clear(self): """Clear transient state A node may cache previously queried values for performance at the expense of memory. This method erases any cached values, freeing up memory at the expense of performance. Example: >>> node = createNode("transform") >>> node["translateX"] = 5 >>> node["translateX"] 5.0 >>> # Plug was reused >>> node["translateX"] 5.0 >>> # Value was reused >>> node.clear() >>> node["translateX"] 5.0 >>> # Plug and value was recomputed """ self._state["plugs"].clear() self._state["values"].clear()
Example #13
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def mapFrom(self, other, time=None): """Return TransformationMatrix of `other` relative self Example: >>> a = createNode("transform") >>> b = createNode("transform") >>> a["translate"] = (0, 5, 0) >>> b["translate"] = (0, -5, 0) >>> delta = a.mapFrom(b) >>> delta.translation()[1] 10.0 >>> a = createNode("transform") >>> b = createNode("transform") >>> a["translate"] = (0, 5, 0) >>> b["translate"] = (0, -15, 0) >>> delta = a.mapFrom(b) >>> delta.translation()[1] 20.0 """ a = self["worldMatrix"][0].asMatrix(time) b = other["worldInverseMatrix"][0].asMatrix(time) delta = a * b return TransformationMatrix(delta)
Example #14
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def addChild(self, child, index=Last): """Add `child` to self Arguments: child (Node): Child to add index (int, optional): Physical location in hierarchy, defaults to cmdx.Last Example: >>> parent = createNode("transform") >>> child = createNode("transform") >>> parent.addChild(child) """ mobject = child._mobject self._fn.addChild(mobject, index)
Example #15
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def update(self, attrs): """Apply a series of attributes all at once This operates similar to a Python dictionary. Arguments: attrs (dict): Key/value pairs of name and attribute Examples: >>> node = createNode("transform") >>> node.update({"tx": 5.0, ("ry", Degrees): 30.0}) >>> node["tx"] 5.0 """ for key, value in attrs.items(): self[key] = value
Example #16
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def isA(self, type): """Evaluate whether self is of `type` Arguments: type (int): MFn function set constant Example: >>> node = createNode("transform") >>> node.isA(kTransform) True >>> node.isA(kShape) False """ return self._mobject.hasFn(type)
Example #17
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def pop(self, key): """Delete an attribute Arguments: key (str): Name of attribute to delete Example: >>> node = createNode("transform") >>> node["myAttr"] = Double() >>> node.pop("myAttr") >>> node.hasAttr("myAttr") False """ del self[key]
Example #18
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def exists(self): """The node exists in both memory *and* scene Example: >>> node = createNode("joint") >>> node.exists True >>> cmds.delete(str(node)) >>> node.exists False >>> node.destroyed False >>> _ = cmds.file(new=True, force=True) >>> node.exists False >>> node.destroyed True """ return not self._removed
Example #19
Source File: test_performance.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def test_rouge_mode(): """CMDX_ROGUE_MODE is faster""" node = cmdx.createNode("transform") Compare("norogue", "createNode", node.name) with environment("CMDX_ROGUE_MODE"): node = cmdx.createNode("transform") Compare("rogue", "createNode", node.name) rogue_vs_norogue = ( timings["createNode"]["norogue"]["percall"] / timings["createNode"]["rogue"]["percall"] ) assert_greater(rogue_vs_norogue, 0.9)
Example #20
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def addAttr(self, attr): """Add a new dynamic attribute to node Arguments: attr (Plug): Add this attribute Example: >>> node = createNode("transform") >>> attr = Double("myAttr", default=5.0) >>> node.addAttr(attr) >>> node["myAttr"] == 5.0 True """ if isinstance(attr, _AbstractAttribute): attr = attr.create() self._fn.addAttribute(attr)
Example #21
Source File: uExport.py From uExport with zlib License | 6 votes |
def convertSkelSettingsToNN(delete=1): orig = 'SkeletonSettings_Cache' if cmds.objExists(orig): if cmds.nodeType(orig) == 'unknown': new = cmds.createNode('network') for att in cmds.listAttr(orig): if not cmds.attributeQuery(att, node=new, exists=1): typ = cmds.attributeQuery(att, node=orig, at=1) if typ == 'typed': cmds.addAttr(new, longName=att, dt='string') if cmds.getAttr(orig + '.' + att): cmds.setAttr(new + '.' + att, cmds.getAttr(orig + '.' + att), type='string') elif typ == 'enum': cmds.addAttr(new, longName=att, at='enum', enumName=cmds.attributeQuery(att, node=orig, listEnum=1)[0]) cmds.delete(orig) cmds.rename(new, 'SkeletonSettings_Cache')
Example #22
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def deleteAttr(self, attr): """Delete `attr` from node Arguments: attr (Plug): Attribute to remove Example: >>> node = createNode("transform") >>> node["myAttr"] = Double() >>> node.deleteAttr("myAttr") >>> node.hasAttr("myAttr") False """ if not isinstance(attr, Plug): attr = self[attr] attribute = attr._mplug.attribute() self._fn.removeAttribute(attribute)
Example #23
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def dagPath(self): """Return a om.MDagPath for this node Example: >>> _ = cmds.file(new=True, force=True) >>> parent = createNode("transform", name="Parent") >>> child = createNode("transform", name="Child", parent=parent) >>> path = child.dagPath() >>> str(path) 'Child' >>> str(path.pop()) 'Parent' """ return om.MDagPath.getAPathTo(self._mobject)
Example #24
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def shortestPath(self): """Return shortest unique path to node Example: >>> _ = cmds.file(new=True, force=True) >>> parent = createNode("transform", name="myParent") >>> child = createNode("transform", name="myChild", parent=parent) >>> child.shortestPath() u'myChild' >>> child = createNode("transform", name="myChild") >>> # Now `myChild` could refer to more than a single node >>> child.shortestPath() u'|myChild' """ return self._fn.partialPathName()
Example #25
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def assembly(self): """Return the top-level parent of node Example: >>> parent1 = createNode("transform") >>> parent2 = createNode("transform") >>> child = createNode("transform", parent=parent1) >>> grandchild = createNode("transform", parent=child) >>> child.assembly() == parent1 True >>> parent2.assembly() == parent2 True """ path = self._fn.getPath() root = None for level in range(path.length() - 1): root = path.pop() return self.__class__(root.node()) if root else self
Example #26
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def type(self): """Return type name Example: >>> node = createNode("choice") >>> node.type() u'choice' """ return self._fn.typeName
Example #27
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def __int__(self): """Return plug as int Example: >>> node = createNode("transform") >>> int(node["visibility"]) 1 """ return int(self.read())
Example #28
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def asDouble(self): """Return plug as double (Python float) Example: >>> node = createNode("transform") >>> node["translateX"] = 5.0 >>> node["translateX"].asDouble() 5.0 """ return self._mplug.asDouble()
Example #29
Source File: lib.py From core with MIT License | 5 votes |
def unique_name(name, format="%02d", namespace="", prefix="", suffix=""): """Return unique `name` The function takes into consideration an optional `namespace` and `suffix`. The suffix is included in evaluating whether a name exists - such as `name` + "_GRP" - but isn't included in the returned value. If a namespace is provided, only names within that namespace are considered when evaluating whether the name is unique. Arguments: format (str, optional): The `name` is given a number, this determines how this number is formatted. Defaults to a padding of 2. E.g. my_name01, my_name02. namespace (str, optional): Only consider names within this namespace. suffix (str, optional): Only consider names with this suffix. Example: >>> name = cmds.createNode("transform", name="MyName") >>> cmds.objExists(name) True >>> unique = unique_name(name) >>> cmds.objExists(unique) False """ iteration = 1 unique = prefix + (name + format % iteration) + suffix while cmds.objExists(namespace + ":" + unique): iteration += 1 unique = prefix + (name + format % iteration) + suffix if suffix: return unique[:-len(suffix)] return unique
Example #30
Source File: cmdx.py From cmdx with BSD 2-Clause "Simplified" License | 5 votes |
def type(self): """Retrieve API type of plug as string Example: >>> node = createNode("transform") >>> node["translate"].type() 'kAttribute3Double' >>> node["translateX"].type() 'kDoubleLinearAttribute' """ return self._mplug.attribute().apiTypeStr