Python maya.cmds.addAttr() Examples
The following are 30
code examples of maya.cmds.addAttr().
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: uExport.py From uExport with zlib License | 7 votes |
def msgConnect(attribFrom, attribTo, debug=0): # TODO needs a mode to dump all current connections (overwrite/force) objFrom, attFrom = attribFrom.split('.') objTo, attTo = attribTo.split('.') if debug: print 'msgConnect>>> Locals:', locals() if not attrExists(attribFrom): cmds.addAttr(objFrom, longName=attFrom, attributeType='message') if not attrExists(attribTo): cmds.addAttr(objTo, longName=attTo, attributeType='message') # check that both atts, if existing are msg atts for a in (attribTo, attribFrom): if cmds.getAttr(a, type=1) != 'message': cmds.warning('msgConnect: Attr, ' + a + ' is not a message attribute. CONNECTION ABORTED.') return False try: return cmds.connectAttr(attribFrom, attribTo, f=True) except Exception as e: print e return False
Example #3
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 7 votes |
def cvLocator(self, ctrlName, r=1, d=1, guide=False, *args): """Create and return a cvLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize. """ curveInstance = self.getControlInstance("Locator") curve = curveInstance.cvMain(False, "Locator", ctrlName, r, d, '+Y', (0, 0, 0), 1, guide) if guide: # create an attribute to be used as guide by module: cmds.addAttr(curve, longName="nJoint", attributeType='long') cmds.setAttr(curve+".nJoint", 1) # colorize curveShape: self.colorShape([curve], 'blue') # shapeSize setup: shapeSizeCluster = self.shapeSizeSetup(curve) return [curve, shapeSizeCluster] return curve #@utils.profiler
Example #4
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 #5
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def getBaseCtrl(self, sCtrlType, sAttrName, sCtrlName, fRadius, iDegree = 1, iSection = 8): nCtrl = None self.ctrlCreated = False try: nCtrl= self.masterGrp.getAttr(sAttrName) except pymel.MayaAttributeError: try: nCtrl = pymel.PyNode(self.prefix + sCtrlName) except pymel.MayaNodeError: if (sCtrlName != (self.prefix + "Option_Ctrl")): nCtrl = pymel.PyNode(self.ctrls.cvControl(sCtrlType, sCtrlName, r=fRadius, d=iDegree, dir="+X")) else: nCtrl = pymel.PyNode(self.ctrls.cvCharacter(sCtrlType, sCtrlName, r=(fRadius*0.2))) self.ctrlCreated = True finally: #Since there is no connection between the master and the node found, create the connection self.masterGrp.addAttr(sAttrName, attributeType='message') nCtrl.message.connect(self.masterGrp.attr(sAttrName)) return nCtrl
Example #6
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 #7
Source File: dpEye.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def createEyelidJoints(self, side, lid, middle, cvEyelidLoc, jointLabelNumber, *args): ''' Create the eyelid joints to be used in the needed setup. Returns EyelidBaseJxt and EyelidJnt created for rotate and skinning. ''' # declating a concatenated name used for base to compose: baseName = side+self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle # creating joints: eyelidBaseZeroJxt = cmds.joint(name=baseName+"_Base_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidBaseJxt = cmds.joint(name=baseName+"_Base_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidZeroJxt = cmds.joint(name=baseName+"_Zero_Jxt", rotationOrder="yzx", scaleCompensate=False) eyelidJnt = cmds.joint(name=baseName+"_Jnt", rotationOrder="yzx", scaleCompensate=False) cmds.addAttr(eyelidJnt, longName='dpAR_joint', attributeType='float', keyable=False) utils.setJointLabel(eyelidJnt, jointLabelNumber, 18, self.userGuideName+"_"+self.langDic[self.langName][lid]+"_"+self.langDic[self.langName]['c042_eyelid']+middle) cmds.select(eyelidZeroJxt) eyelidSupportJxt = cmds.joint(name=baseName+"_Jxt", rotationOrder="yzx", scaleCompensate=False) cmds.setAttr(eyelidSupportJxt+".translateX", self.ctrlRadius*0.1) # positioning and orienting correctely eyelid joints: cmds.delete(cmds.aimConstraint(cvEyelidLoc, eyelidBaseZeroJxt, aimVector=(0,0,1), worldUpType="objectrotation", worldUpObject=self.eyelidJxt)) cmds.delete(cmds.parentConstraint(cvEyelidLoc, eyelidZeroJxt, mo=False)) cmds.setAttr(eyelidZeroJxt+".rotateX", 0) cmds.setAttr(eyelidZeroJxt+".rotateY", 0) cmds.setAttr(eyelidZeroJxt+".rotateZ", 0) cmds.select(self.eyelidJxt) return eyelidBaseJxt, eyelidJnt
Example #8
Source File: twoboneik.py From cmt with MIT License | 6 votes |
def __create_config_control(self, parent): self.config_control = cmds.createNode( "transform", name="{}_config_ctrl".format(self.name) ) if parent: cmds.parent(self.config_control, parent) common.opm_parent_constraint(self.end_joint, self.config_control) common.lock_and_hide(self.config_control, "trsv") cmds.addAttr( self.config_control, ln="ikFk", minValue=0.0, maxValue=1.0, defaultValue=0.0, keyable=True, )
Example #9
Source File: mayascenemodel.py From cross3d with MIT License | 6 votes |
def _createResolutionComboBox(self): userProps = cross3d.UserProps(self._nativePointer) # Local models have a resolution metadata. # Maybe it's not a good idea. if resolutionAttr in userProps: del userProps[resolutionAttr] resolutions = ':'.join(userProps.get('resolutions', [])) # Object should support referencing, but referencing hasn't been setup, so create the structure. cmds.addAttr(self._nativeName(), longName=resolutionAttr, attributeType="enum", enumName=resolutions) # Make the attribute viewable, but not keyable in the channelBox try: cmds.setAttr(self._attrName(), keyable=False, channelBox=True) # Consume a runtime error if the resolution attribute was in the reference. This is only a # issue with some of our first models, Asset Exporter will remove them from future exports. except RuntimeError as error: pattern = r"setAttr: The attribute '[^']+' is from a referenced file, thus the keyable state cannot be changed." if not re.match(pattern, error.message): raise
Example #10
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #11
Source File: dge.py From cmt with MIT License | 5 votes |
def publish_container_attributes(self): self.add_notes(self.container, self.expression_string) external_connections = cmds.container( self.container, q=True, connectionList=True ) external_connections = set(external_connections) container_nodes = set(cmds.container(self.container, q=True, nodeList=True)) for var, value in self.kwargs.items(): if not isinstance(value, string_types): continue # To connect multiple attributes to a bound container attribute, we # need to create an intermediary attribute that is bound and connected # to the internal attributes attr_type = attribute_type(value) kwargs = {"dt": attr_type} if attr_type == "matrix" else {"at": attr_type} cmds.addAttr(self.container, ln="_{}".format(var), **kwargs) published_attr = "{}._{}".format(self.container, var) cmds.container(self.container, e=True, publishAndBind=[published_attr, var]) cmds.connectAttr(value, published_attr) # Reroute connections into the container to go through the published # attribute if value in external_connections: connected_nodes = set(cmds.listConnections(value, s=False, plugs=True)) for connection in connected_nodes: node_name = connection.split(".")[0] if node_name in container_nodes: cmds.connectAttr(published_attr, connection, force=True) source_plug = cmds.listConnections(value, d=False, plugs=True) if source_plug: source_plug = source_plug[0] node_name = source_plug.split(".")[0] if node_name in container_nodes: cmds.connectAttr(source_plug, published_attr, force=True) cmds.connectAttr(published_attr, value, force=True) cmds.container(self.container, e=True, current=False)
Example #12
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #13
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #14
Source File: cartoony.py From cmt with MIT License | 5 votes |
def create(self): self.anim_node = cmds.createNode("transform", name=self.name) self.driven_node = cmds.createNode( "transform", name="{}_driven".format(self.name) ) for attr in ["{}{}".format(x, y) for x in "trs" for y in "xyz"] + ["v"]: cmds.setAttr("{}.{}".format(self.anim_node, attr), lock=True, keyable=False) cmds.setAttr( "{}.{}".format(self.driven_node, attr), lock=True, keyable=False ) for attr in ATTRIBUTES: names = get_name_combinations(attr["name"], attr.get("tokens", [])) for name in names: cmds.addAttr(self.anim_node, ln=name, keyable=True, at="float") cmds.addAttr(self.driven_node, ln=name, keyable=True, at="float") blend = cmds.createNode( "blendWeighted", name="{}_blendWeighted".format(name) ) cmds.connectAttr( "{}.{}".format(self.anim_node, name), "{}.input[0]".format(blend) ) cmds.setAttr("{}.weight[0]".format(blend), 1.0) cmds.connectAttr( "{}.output".format(blend), "{}.{}".format(self.driven_node, name) ) self.blend_weighted[name] = blend
Example #15
Source File: mayascenemodel.py From cross3d with MIT License | 5 votes |
def _modifiedAttrs(self): """ Returns a dictionary of modifications made to this referenced model. For referneced models return info describing the modifications made by the referencing system. """ modified = {} if self.isReferenced(): fullName = self.path() refNode = cmds.referenceQuery(fullName, referenceNode=True) # Build the setAttr pattern pattern = r'setAttr {node}.(?P<attr>[^ ]+)'.format(node = fullName.replace('|', r'\|')) setAttrRegex = re.compile(pattern) # TODO: Add patterns for other mel commands like addAttr, etc for s in cmds.referenceQuery(refNode, editStrings=True): # Process setAttr match = setAttrRegex.match(s) if match: key = match.groupdict()['attr'] if s.endswith('"'): # Found a string. Note, this does not include escaped quotes. openingQuote = s[::-1].find('"', 1) value = s[-openingQuote:-1] else: # its not a string value = s.split(' ')[-1] modified.setdefault(key, {}).setdefault('setAttr', {}).update(value=value, command=s) return modified
Example #16
Source File: mayascenemodel.py From cross3d with MIT License | 5 votes |
def addResolution(self, name='', path='', load=False): if self.isReferenced(): reses = self.userProps().get('resolutions', OrderedDict()) reses[name] = path self.userProps()['resolutions'] = reses # Update the enum cmds.addAttr(self._attrName(), edit=True, enumName=':'.join(self.resolutions())) if load: self.setResolution(name) return True return False
Example #17
Source File: transformstack.py From cmt with MIT License | 5 votes |
def create_transform_stack(node, suffixes=None): """Creates a transform stack above the given node. Any previous transform stack will be deleted. :param node: Node to parent into a transform stack. :param suffixes: List of suffixes to add to the created transforms :return: A list of the transform nodes created starting from top to bottom. """ previous_parent = get_stack_parent(node) delete_stack(node) stack_transforms = [] for i, suffix in enumerate(suffixes): name = "{}{}".format(node, suffix) transform = cmds.createNode("transform", name=name) stack_transforms.append(transform) cmds.addAttr(transform, ln=STACK_ATTRIBUTE, at="message") cmds.connectAttr( "{}.message".format(node), "{}.{}".format(transform, STACK_ATTRIBUTE) ) cmds.delete(cmds.parentConstraint(node, transform)) if previous_parent: cmds.parent(transform, previous_parent) previous_parent = transform cmds.parent(node, previous_parent) stack_transforms.append(node) logger.info("Created transform stack {}".format("|".join(stack_transforms))) return stack_transforms
Example #18
Source File: mayascene.py From cross3d with MIT License | 5 votes |
def _createNativeModel(self, name='Model', nativeObjects=[], referenced=False): name = 'Model' if not name else name # Create a "model" namespace and add the locator to it # TODO: Make this a context currentNamespace = cmds.namespaceInfo(currentNamespace=True) namespace = cmds.namespace(addNamespace=name) cmds.namespace(setNamespace=namespace) # Create the transform node then the shape node so the transform is properly named parent = cmds.createNode('transform', name='Model') #name = cmds.createNode('locator', name='{}Shape'.format(name), parent=parent) output = cross3d.SceneWrapper._asMOBject(parent) userProps = cross3d.UserProps(output) userProps['model'] = True if referenced: userProps['referenced'] = referenced # Create the Active_Resolution enum if it doesn't exist # cmds.addAttr(name, longName="Active_Resolution", attributeType="enum", enumName="Offloaded:") # userProps['Resolutions'] = OrderedDict(Offloaded='') cmds.namespace(setNamespace=currentNamespace) # Add each of nativeObjects to the model namespace if nativeObjects: for nativeObject in nativeObjects: nativeObject = cross3d.SceneWrapper._getTransformNode(nativeObject) objName = cross3d.SceneWrapper._mObjName(nativeObject) # cmds.parent(objName, cross3d.SceneWrapper._mObjName(nativeParent)) nameInfo = cross3d.SceneWrapper._namespace(nativeObject) newName = '{namespace}:{name}'.format(namespace=namespace, name=nameInfo['name']) cmds.rename(objName, newName) nativeObjects.append(output) return output
Example #19
Source File: uExport.py From uExport with zlib License | 5 votes |
def getFbxExportPropertiesDict(self): if not attrExists(self.node + '.fbxPropertiesDict'): cmds.addAttr(self.node, longName='fbxPropertiesDict', dt='string') self.fbxPropertiesDict = {'animInterpolation':'quaternion', 'upAxis':'default', 'triangulation':False} cmds.setAttr(self.node + '.fbxPropertiesDict', json.dumps(self.fbxPropertiesDict), type='string') return self.fbxPropertiesDict else: self.fbxPropertiesDict = json.loads(cmds.getAttr(self.node + '.fbxPropertiesDict')) return self.fbxPropertiesDict ## Properties ######################################################################## #return and set the rendermeshes per LOD
Example #20
Source File: uExport.py From uExport with zlib License | 5 votes |
def lodNum(self): att = self.node + '.lodNum' if attrExists(att): return cmds.getAttr(att) else: cmds.addAttr(self.node, ln='lodNum', at='byte') cmds.setAttr(att, 4) return cmds.getAttr(att)
Example #21
Source File: uExport.py From uExport with zlib License | 5 votes |
def lodNum(self, meshes): att = self.node + '.lodNum' if attrExists(att): return cmds.setAttr(att) else: cmds.addAttr(self.node, ln='lodNum', at='byte') cmds.setAttr(att, 4) return cmds.setAttr(att) #return ALL lod geometry
Example #22
Source File: assetImporter4.py From tutorials with MIT License | 5 votes |
def load(self, obj): """ load(string/Asset obj) Imports an Asset by a given name or Asset into Maya """ if isinstance(obj, Asset): assets = [obj] else: assets = self.list(name) self._print("Loading %d assets..." % len(assets)) cmds.select(clear=True) for asset in assets: before = set(cmds.ls(assemblies=True, r=True)) cmds.file(asset.scene, namespace=asset.name, r=True, gl=True, loadReferenceDepth="all") after = set(cmds.ls(assemblies=True, r=True)) newStuff = after.difference(before) for item in newStuff: cmds.addAttr(item, longName=self.ATTR_ASSET_NAME, dataType="string") cmds.addAttr(item, longName=self.ATTR_ASSET_SHOW, dataType="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_NAME), asset.name, type="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_SHOW), asset.show, type="string") self._print("=> Loaded: %s" % asset) cmds.select(list(newStuff), add=True)
Example #23
Source File: assetImporter2.py From tutorials with MIT License | 5 votes |
def load(self, obj): """ load(string/Asset obj) Imports an Asset by a given name or Asset into Maya """ if isinstance(obj, Asset): assets = [obj] else: assets = self.list(name) self._print("Loading %d assets..." % len(assets)) cmds.select(clear=True) for asset in assets: before = set(cmds.ls(assemblies=True, r=True)) cmds.file(asset.scene, namespace=asset.name, r=True, gl=True, loadReferenceDepth="all") after = set(cmds.ls(assemblies=True, r=True)) newStuff = after.difference(before) for item in newStuff: cmds.addAttr(item, longName=self.ATTR_ASSET_NAME, dataType="string") cmds.addAttr(item, longName=self.ATTR_ASSET_SHOW, dataType="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_NAME), asset.name, type="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_SHOW), asset.show, type="string") self._print("=> Loaded: %s" % asset) cmds.select(list(newStuff), add=True)
Example #24
Source File: assetImporter3.py From tutorials with MIT License | 5 votes |
def load(self, obj): """ load(string/Asset obj) Imports an Asset by a given name or Asset into Maya """ if isinstance(obj, Asset): assets = [obj] else: assets = self.list(name) self._print("Loading %d assets..." % len(assets)) cmds.select(clear=True) for asset in assets: before = set(cmds.ls(assemblies=True, r=True)) cmds.file(asset.scene, namespace=asset.name, r=True, gl=True, loadReferenceDepth="all") after = set(cmds.ls(assemblies=True, r=True)) newStuff = after.difference(before) for item in newStuff: cmds.addAttr(item, longName=self.ATTR_ASSET_NAME, dataType="string") cmds.addAttr(item, longName=self.ATTR_ASSET_SHOW, dataType="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_NAME), asset.name, type="string") cmds.setAttr("%s.%s" % (item, self.ATTR_ASSET_SHOW), asset.show, type="string") self._print("=> Loaded: %s" % asset) cmds.select(list(newStuff), add=True)
Example #25
Source File: dge.py From cmt with MIT License | 5 votes |
def add_notes(self, node, op_str): node = node.split(".")[0] attrs = cmds.listAttr(node, ud=True) or [] if "notes" not in attrs: cmds.addAttr(node, ln="notes", dt="string") keys = self.kwargs.keys() keys.sort() notes = "Node generated by dge\n\nExpression:\n {}\n\nOperation:\n {}\n\nkwargs:\n {}".format( self.expression_string, op_str, "\n ".join(["{}: {}".format(x, self.kwargs[x]) for x in keys]), ) cmds.setAttr("{}.notes".format(node), notes, type="string")
Example #26
Source File: BlendTransforms.py From BlendTransforms with The Unlicense | 5 votes |
def BT_Setup(set = None): if not set: return False transforms = cmds.listConnections(set +'.dagSetMembers') if not transforms: return False if not cmds.attributeQuery('Blend_Node', n = set, ex = True): cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string') else: return False btNode = cmds.createNode("BlendTransforms") cmds.setAttr(set +'.Blend_Node', btNode, type = "string") for i in range(0, len(transforms)): baseMatrix = cmds.xform(transforms[i], q = True, m = True) baseScale = cmds.getAttr(transforms[i] +'.scale')[0] baseRotOffset = [0.0, 0.0, 0.0] if cmds.objectType(transforms[i], isType = 'joint'): baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0] btAttr = 'transforms[' +str(i) +'].baseMatrix' btScaleAttr = 'transforms[' +str(i) +'].baseScale' btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset' BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr) BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr) BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr) BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i]) return True
Example #27
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def addControlInfo(self, cvNode, className=True, size=True, degree=True, direction=True, rot=True, dpGuide=False, *args): """ Add some information in the curve transform node of the control. """ cmds.addAttr(cvNode, longName="dpControl", attributeType='bool') cmds.setAttr(cvNode+".dpControl", 1) if dpGuide: cmds.addAttr(cvNode, longName="dpGuide", attributeType='bool') cmds.setAttr(cvNode+".dpGuide", 1) cmds.addAttr(cvNode, longName="version", dataType='string') cmds.setAttr(cvNode+".version", self.dpUIinst.dpARVersion, type="string") if self.cvID: cmds.addAttr(cvNode, longName="controlID", dataType='string') cmds.setAttr(cvNode+".controlID", self.cvID, type="string") if className: cmds.addAttr(cvNode, longName="className", dataType='string') cmds.setAttr(cvNode+".className", self.guideModuleName, type="string") if size: cmds.addAttr(cvNode, longName="size", attributeType='float') cmds.setAttr(cvNode+".size", self.cvSize) if degree: cmds.addAttr(cvNode, longName="degree", attributeType='short') cmds.setAttr(cvNode+".degree", self.cvDegree) if direction: cmds.addAttr(cvNode, longName="direction", dataType='string') cmds.setAttr(cvNode+".direction", self.cvDirection, type="string") if rot: cmds.addAttr(cvNode, longName="cvRotX", attributeType='double') cmds.addAttr(cvNode, longName="cvRotY", attributeType='double') cmds.addAttr(cvNode, longName="cvRotZ", attributeType='double') cmds.setAttr(cvNode+".cvRotX", self.cvRot[0]) cmds.setAttr(cvNode+".cvRotY", self.cvRot[1]) cmds.setAttr(cvNode+".cvRotZ", self.cvRot[2])
Example #28
Source File: dpAutoRig.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def getBaseGrp(self, sAttrName, sGrpName): nGrpNode = None try: nGrpNode = self.masterGrp.getAttr(sAttrName) except pymel.MayaAttributeError: try: nGrpNode = pymel.PyNode(sGrpName) except pymel.MayaNodeError: nGrpNode = pymel.createNode("transform", name=sGrpName) finally: #Since there is no connection between the master and the node found, create the connection self.masterGrp.addAttr(sAttrName, attributeType='message') nGrpNode.message.connect(self.masterGrp.attr(sAttrName)) return nGrpNode
Example #29
Source File: ml_pivot.py From ml_tools with MIT License | 5 votes |
def editPivotHandle(self): qt_maya_window.installEventFilter(self.keypressFilter) #create transform self.pivotHandle = mc.group(em=True, name='Adjust_Pivot') mc.setAttr(self.pivotHandle+'.rotate', lock=True) mc.setAttr(self.pivotHandle+'.rx', keyable=False) mc.setAttr(self.pivotHandle+'.ry', keyable=False) mc.setAttr(self.pivotHandle+'.rz', keyable=False) mc.setAttr(self.pivotHandle+'.scale', lock=True) mc.setAttr(self.pivotHandle+'.sx', keyable=False) mc.setAttr(self.pivotHandle+'.sy', keyable=False) mc.setAttr(self.pivotHandle+'.sz', keyable=False) mc.setAttr(self.pivotHandle+'.visibility', lock=True, keyable=False) mc.setAttr(self.pivotHandle+'.displayHandle', True) self.pivotHandle = mc.parent(self.pivotHandle, self.node)[0] mc.addAttr(self.pivotHandle, ln='ml_pivot_handle', at='bool', keyable=False) #set initial position mc.setAttr(self.pivotHandle+'.translate', *mc.getAttr(self.node+'.rotatePivot')[0]) #lock it so you don't delete it or something. mc.lockNode(self.pivotHandle, lock=True) self.scriptJob = mc.scriptJob(event=['SelectionChanged', self.cleanup], runOnce=True) mc.setToolTo('Move') mc.inViewMessage( amg='After moving the pivot, press <hl>Return</hl> to bake or <hl>Esc</hl> to cancel.', pos='midCenterTop', fade=True, fadeStayTime=4000, dragKill=True)
Example #30
Source File: dpSuspension.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def createGuide(self, *args): Base.StartClass.createGuide(self) # Custom GUIDE: cmds.addAttr(self.moduleGrp, longName="flip", attributeType='bool') cmds.setAttr(self.moduleGrp+".flip", 0) cmds.addAttr(self.moduleGrp, longName="fatherB", dataType='string') cmds.setAttr(self.moduleGrp+".moduleNamespace", self.moduleGrp[:self.moduleGrp.rfind(":")], type='string') self.cvALoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLocA", r=0.3, d=1, guide=True) self.connectShapeSize(shapeSizeCH) self.jAGuide = cmds.joint(name=self.guideName+"_jAGuide", radius=0.001) cmds.setAttr(self.jAGuide+".template", 1) cmds.parent(self.jAGuide, self.moduleGrp, relative=True) self.cvBLoc, shapeSizeCH = self.ctrls.cvJointLoc(ctrlName=self.guideName+"_JointLocB", r=0.3, d=1, guide=True) self.connectShapeSize(shapeSizeCH) cmds.parent(self.cvBLoc, self.cvALoc) cmds.setAttr(self.cvBLoc+".tz", 3) cmds.setAttr(self.cvBLoc+".rotateX", 180) self.jBGuide = cmds.joint(name=self.guideName+"_jBGuide", radius=0.001) cmds.setAttr(self.jBGuide+".template", 1) cmds.transformLimits(self.cvBLoc, tz=(0.01, 1), etz=(True, False)) self.ctrls.setLockHide([self.cvBLoc], ['tx', 'ty', 'rx', 'ry', 'rz', 'sx', 'sy', 'sz']) cmds.parent(self.cvALoc, self.moduleGrp) cmds.parent(self.jBGuide, self.jAGuide) cmds.parentConstraint(self.cvALoc, self.jAGuide, maintainOffset=False, name=self.jAGuide+"_ParentConstraint") cmds.parentConstraint(self.cvBLoc, self.jBGuide, maintainOffset=False, name=self.jBGuide+"_ParentConstraint") cmds.scaleConstraint(self.cvALoc, self.jAGuide, maintainOffset=False, name=self.jAGuide+"_ScaleConstraint") cmds.scaleConstraint(self.cvBLoc, self.jBGuide, maintainOffset=False, name=self.jBGuide+"_ScaleConstraint")