本文整理匯總了Python中maya.cmds.createNode方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.createNode方法的具體用法?Python cmds.createNode怎麽用?Python cmds.createNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.createNode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: lock
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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")
示例2: maintained_selection
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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)
示例3: dpIsolate
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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])
示例4: twistBoneMatrix
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def twistBoneMatrix(nodeA, nodeB, twistBoneName, twistBoneMD=None, axis='Z', inverse=True, *args):
""" Create matrix nodes and quaternion to extract rotate.
nodeA = father transform node
nodeB = child transform node
Returns the final multiplyDivide node created or given.
Reference:
https://bindpose.com/maya-matrix-nodes-part-2-node-based-matrix-twist-calculator/
"""
twistBoneMM = cmds.createNode("multMatrix", name=twistBoneName+"_ExtractAngle_MM")
twistBoneDM = cmds.createNode("decomposeMatrix", name=twistBoneName+"_ExtractAngle_DM")
twistBoneQtE = cmds.createNode("quatToEuler", name=twistBoneName+"_ExtractAngle_QtE")
cmds.connectAttr(nodeB+".worldMatrix[0]", twistBoneMM+".matrixIn[0]", force=True)
if inverse:
cmds.connectAttr(nodeA+".worldInverseMatrix[0]", twistBoneMM+".matrixIn[1]", force=True)
else:
cmds.connectAttr(nodeA+".worldMatrix[0]", twistBoneMM+".matrixIn[1]", force=True)
cmds.connectAttr(twistBoneMM+".matrixSum", twistBoneDM+".inputMatrix", force=True)
cmds.connectAttr(twistBoneDM+".outputQuat.outputQuat"+axis, twistBoneQtE+".inputQuat.inputQuat"+axis, force=True)
cmds.connectAttr(twistBoneDM+".outputQuat.outputQuatW", twistBoneQtE+".inputQuat.inputQuatW", force=True)
if twistBoneMD:
cmds.connectAttr(twistBoneQtE+".outputRotate.outputRotate"+axis, twistBoneMD+".input2"+axis, force=True)
else:
twistBoneMD = cmds.createNode("multiplyDivide", name=twistBoneName+"_MD")
cmds.connectAttr(twistBoneQtE+".outputRotate.outputRotate"+axis, twistBoneMD+".input2"+axis, force=True)
return twistBoneMD
示例5: __normalizeSlideAttributes
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def __normalizeSlideAttributes(self):
normalized = []
attributes = [
"slide_center",
"slide_shift",
"slide_shift_min",
"slide_shift_max"
]
# loop attributes
for attr in attributes:
mdl = cmds.createNode(
"multDoubleLinear",
n="{0}_{1}_norm_mdl".format(self.name, attr)
)
cmds.setAttr("{0}.input1".format(mdl), 0.1)
cmds.connectAttr(
"{0}.{1}".format(self.slideControl, attr),
"{0}.input2".format(mdl)
)
normalized.append("{0}.output".format(mdl))
return normalized
示例6: from_value
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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)
示例7: scalar_dynamic
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def scalar_dynamic (self, scal):
'''
This function performs a scalar multiplication
This function is called dynamic because it uses a connection to get
the value for the multiplication, in short it is a NScalar instance (aka a vec1)
that gets used three times to multiply the current vector
:scal: NScalar, a scalar class instance
:return: NVec instance
'''
assert type(scal) == NScalar, "__sub__ ERROR: input parameter needs to be of type NScalar"
mult = cmds.createNode("multiplyDivide", n= self._generator.next()+ '_scalarDyn')
cmds.connectAttr(scal.attribute_name , mult + '.input2X')
cmds.connectAttr(scal.attribute_name , mult + '.input2Y')
cmds.connectAttr(scal.attribute_name , mult + '.input2Z')
cmds.connectAttr(self.attribute_name, mult + '.input1')
return NVec.with_generator(mult+ '.output', self._generator)
示例8: scalar_static
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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)
示例9: dot
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def dot(self, vecB):
"""
This function performs a dot product
Args:
:vecB: NVec, the second class for the operation
:return: NVec instance
"""
assert type(vecB) == NVec, "__sub__ ERROR: input parameter needs to be of type NVec"
vecProd = cmds.createNode("vectorProduct", n = self._generator.next()+ "_dot")
cmds.connectAttr(self.attribute_name , vecProd + '.input1')
cmds.connectAttr(vecB.attribute_name , vecProd + '.input2')
return NVec.with_generator(vecProd+ '.output', self._generator)
示例10: cross
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def cross(self,vecB):
"""
Cross product function
Args:
:vecB: NVec, the second class for the operation
:return: NVec instance
"""
assert type(vecB) == NVec, "__sub__ ERROR: input parameter needs to be of type NVec"
vecProd = cmds.createNode("vectorProduct", n = self._generator.next()+ "_cross")
cmds.setAttr(vecProd + '.operation', 2)
cmds.connectAttr(self.attribute_name , vecProd + '.input1')
cmds.connectAttr(vecB.attribute_name , vecProd + '.input2')
return NVec.with_generator(vecProd+ '.output', self._generator)
示例11: __sub__
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
def __sub__(self,vecB):
"""
Subtraction operator for NVec
Args:
:vecB: NVec, the second class for the operation
:return: NVec instance
"""
assert type(vecB) == NVec, "__sub__ ERROR: input parameter needs to be of type NVec"
pma = cmds.createNode("plusMinusAverage", n = self._generator.next()+ "_sub")
cmds.connectAttr(vecB.attribute_name, pma + '.input3D[0]')
cmds.connectAttr(self.attribute_name, pma + '.input3D[1]')
cmds.setAttr(pma + '.operation',2)
return NVec.with_generator(pma+ '.output3D', self._generator)
示例12: convertSkelSettingsToNN
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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')
示例13: test_rouge_mode
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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)
示例14: exists
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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
示例15: isA
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import createNode [as 別名]
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)