def createArrow(name=None, thickness=0.1, length=2, vector=[1,0,0], point=[0,0,0]): ''' Creates an arrow in the direction of the vector Example: arrow = createArrow(vector=[0,1,0], length=4) ''' if not name: name = 'arrow_CTRL' #calc length for thickness ratio = length/thickness cyl = cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[length/2, 0, 0], ch=0)[0] cone = cmds.cone(radius=thickness*2, sections=4, ch=0, pivot=(length*1.0005,0,0))[0] xform = cmds.createNode('transform', ss=1, name=name) shapes = [] transforms = [] for node in [cone,cyl]: shapes.append(cmds.listRelatives(node, fullPath=1, shapes=1)[0]) transforms.append(node) cmds.parent(shapes, xform, r=1, s=1) rotateBy = cmds.angleBetween(euler=True, v1=(1,0,0), v2=vector) cmds.rotate(rotateBy[0], rotateBy[1], rotateBy[2], xform) cmds.xform(xform, t=point) cmds.delete(transforms) return xform
def create(self, objnum, shape="cone"): if shape == "cone": node = cmds.cone(ch=False, n='herdmemb') else: node = cmds.duplicate(shape, ic=True, n='herdmemb') cmds.addAttr(node, sn='fad', ln='frameAdjust', dv=0, k=True) values = herds().values() cmds.expression(s=("$herdvar = " + str(random.random() - 0.5) + " * " + self.leader + ".rnds + " + str(objnum) + ";\n" + "$randfac = " + self.leader + ".stry;\n" + "$foc = " + self.leader + ".lf;\n" + "if( $foc != 0 ) {\n" + "$randfac *= min( 1.0,abs($herdvar)*(1-$foc)/($foc*"+ str(values["population"]) +") );}\n" + "$herdvar = $herdvar * -" + self.leader + ".frameOffset + frame +" + node[0] + ".frameAdjust;\n" + "$offset = " + str(random.random() - 0.45) + " * $randfac;\n" + node[0] + ".tx = $offset + `getAttr -time $herdvar " + self.leader + ".tx`;\n" + "$offset = " + str(random.random() - 0.45) + " * $randfac;\n" + node[0] + ".ty = $offset + `getAttr -time $herdvar " + self.leader + ".ty`;\n" + "$offset = " + str(random.random() - 0.45) + " * $randfac;\n" + node[0] + ".tz = $offset + `getAttr -time $herdvar " + self.leader + ".tz`;\n" ), n=(node[0] + "_herd_exp")) # Turns off the checker for finding cycles - throws up lots of warnings without it. cmds.cycleCheck(e=True, all=False) self.node = node[0] self.point() return node
def convert_joint(curr_joint, group_name, root_jnt=True): scale_size = mc.jointDisplayScale(q=True) * 2.0 _children = mc.listRelatives(curr_joint, c=True) if _children is not None: for node in _children: if mc.nodeType(node) == 'joint': convert_joint(node, group_name, root_jnt=False) parent = mc.listRelatives(curr_joint, p=True) if parent is None or root_jnt: return _name_ball = curr_joint + group_name + "_ball" new_ball = mc.sphere(n=_name_ball) _name_cone = curr_joint + group_name + "_joint" new_cone = mc.cone(p=(0, 0, 0), ax=(1, 0, 0), ssw=0, esw=360, r=0.5, hr=4, d=1, ut=0, tol=0.01, s=8, nsp=4, ch=1, n=_name_cone) mc.move(-1, 0, 0, _name_cone + ".scalePivot", _name_cone + ".rotatePivot", r=True) mc.parent(new_cone, group_name) mc.parent(new_ball, group_name) xform1 = mc.xform(curr_joint, q=True, ws=True, t=True) xform2 = mc.xform(parent[0], q=True, ws=True, t=True) dist = 0.0 for i in range(len(xform1)): dist += (xform1[i] - xform2[i]) * (xform1[i] - xform2[i]) dist = (dist**0.5) / 2.0 mc.scale(scale_size, scale_size, scale_size, new_ball, r=True) bbox = mc.exactWorldBoundingBox(new_ball) bbox_size = ((((bbox[3] - bbox[0])**2 + (bbox[4] - bbox[1])**2 + (bbox[5] - bbox[2])**2)**0.5) / 4.0) * 2.0 mc.scale(dist, bbox_size, bbox_size, new_cone, r=True) mc.pointConstraint(parent[0], new_cone, weight=1) mc.pointConstraint(parent[0], new_ball, weight=1) mc.aimConstraint(curr_joint, new_cone, aim=(1, 0, 0), u=(0, 1, 0), wu=(0, 1, 0), weight=1) create_node(group_name, new_ball[0], 'ball') create_node(group_name, new_cone[0], 'edge')
def createArrow(name=None, thickness=0.1, length=2, vector=[1, 0, 0], point=[0, 0, 0]): ''' Creates an arrow in the direction of the vector Example: arrow = createArrow(vector=[0,1,0], length=4) ''' if not name: name = 'arrow_CTRL' #calc length for thickness ratio = length / thickness cyl = cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[length / 2, 0, 0], ch=0)[0] cone = cmds.cone(radius=thickness * 2, sections=4, ch=0, pivot=(length * 1.0005, 0, 0))[0] xform = cmds.createNode('transform', ss=1, name=name) shapes = [] transforms = [] for node in [cone, cyl]: shapes.append(cmds.listRelatives(node, fullPath=1, shapes=1)[0]) transforms.append(node) cmds.parent(shapes, xform, r=1, s=1) rotateBy = cmds.angleBetween(euler=True, v1=(1, 0, 0), v2=vector) cmds.rotate(rotateBy[0], rotateBy[1], rotateBy[2], xform) cmds.xform(xform, t=point) cmds.delete(transforms) return xform
def createLRA(node=None, matrix=None, name=None, color=True, thickness=0.1, length=2, vector=[1,0,0], point=[0,0,0], arrowRadiusMult=2): ''' Creates an LRA at the origin, or at a node, or a mmx Example: createLRA(length=2, thickness=0.05, arrowRadiusMult=3) ''' if not name: name = 'arrow_CTRL' nodes = [] x,y,z = [],[],[] #calc length for thickness ratio = length/thickness xform = cmds.createNode('transform', ss=1, name=name) x.append(cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[length/2, 0, 0], ch=0, axis=[1,0,0])[0]) x.append(cmds.cone(radius=thickness*arrowRadiusMult, sections=4, ch=0, pivot=(length*1.0005,0,0))[0]) y.append(cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[0, length/2, 0], ch=0, axis=[0,1,0])[0]) y.append(cmds.cone(radius=thickness*arrowRadiusMult, sections=4, ch=0, pivot=(0,length*1.0005,0), axis=[0,1,0])[0]) z.append(cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[0, 0, length/2], ch=0, axis=[0,0,1])[0]) z.append(cmds.cone(radius=thickness*arrowRadiusMult, sections=4, ch=0, pivot=(0,0,length*1.0005), axis=[0,0,1])[0]) nodes.extend(x) nodes.extend(y) nodes.extend(z) if color: for node in x: colorControl(node, name='red_m', color=(1,0,0)) for node in y: colorControl(node, name='green_m', color=(0,1,0)) for node in z: colorControl(node, name='blue_m', color=(0,0,1)) shapes = [] transforms = [] for node in nodes: shapes.append(cmds.listRelatives(node, fullPath=1, shapes=1)[0]) transforms.append(node) cmds.parent(shapes, xform, r=1, s=1) rotateBy = cmds.angleBetween(euler=True, v1=(1,0,0), v2=vector) cmds.rotate(rotateBy[0], rotateBy[1], rotateBy[2], xform) cmds.xform(xform, t=point) cmds.delete(transforms) return xform
def makePrimitiveJoint(currentJoint): SJsize = mc.jointDisplayScale(q=True) * SS_scale children = mc.listRelatives(currentJoint, c=True) if (children != None) : for node in children : if(mc.nodeType(node) == "joint") : makePrimitiveJoint(node) else : SJballEndName = currentJoint + SS_group + "_SJballEnd" solidEndBall = mc.sphere(n=SJballEndName) mc.parent(solidEndBall, SS_group) mc.scale(SJsize, SJsize, SJsize, solidEndBall, r=True) mc.pointConstraint(currentJoint, solidEndBall, weight=1) createMDN(solidEndBall, 'ball') elif (children == None) : SJballEndName = currentJoint + SS_group + "_SJballEnd" solidEndBall = mc.sphere(n=SJballEndName) mc.parent(solidEndBall, SS_group) mc.scale(SJsize, SJsize, SJsize, solidEndBall, r=True) mc.pointConstraint(currentJoint, solidEndBall, weight=1) createMDN(solidEndBall, 'ball') SJname = currentJoint + SS_group + "_SJ" SJballName = currentJoint + SS_group + "_SJball" parent = mc.listRelatives(currentJoint, p=True) if (parent != None) and (currentJoint != SS_root_jnt): parentJoint = parent[0] solidBall = mc.sphere(n=SJballName) solidJoint = mc.cone(p=(0,0,0), ax=(1,0,0), ssw=0, esw=360, r=0.5, hr=4, d=1, ut=0, tol=0.01, s=8, nsp=4, ch=1, n=SJname) mc.move(-1, 0, 0, SJname+".scalePivot", SJname+".rotatePivot", r=True) mc.parent(solidJoint, SS_group) mc.parent(solidBall, SS_group) xform1 = mc.xform(currentJoint, q=True, ws=True, t=True) xform2 = mc.xform(parentJoint, q=True, ws=True, t=True) dist = 0.0 for i in range(len(xform1)):dist += (xform1[i]-xform2[i])*(xform1[i]-xform2[i]) dist = (dist ** 0.5) / 2.0 mc.scale(SJsize, SJsize, SJsize, solidBall, r=True) bbox = mc.exactWorldBoundingBox(solidBall) bboxSize = ((((bbox[3]-bbox[0])**2+(bbox[4]-bbox[1])**2+(bbox[5]-bbox[2])**2)**0.5)/4.0)*SS_edgeScale mc.scale(dist, bboxSize, bboxSize, solidJoint, r=True) mc.pointConstraint(parentJoint, solidJoint, weight=1) mc.pointConstraint(parentJoint, solidBall, weight=1) mc.aimConstraint(currentJoint, solidJoint, aim=(1,0,0), u=(0,1,0), wu=(0,1,0), weight=1) createMDN(solidBall, 'ball') createMDN(solidJoint, 'edge')
def createLRA(node=None, matrix=None, name=None, color=True, thickness=0.1, length=2, vector=[1, 0, 0], point=[0, 0, 0], arrowRadiusMult=2): ''' Creates an LRA at the origin, or at a node, or a mmx Example: createLRA(length=2, thickness=0.05, arrowRadiusMult=3) ''' if not name: name = 'arrow_CTRL' nodes = [] x, y, z = [], [], [] #calc length for thickness ratio = length / thickness xform = cmds.createNode('transform', ss=1, name=name) x.append( cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[length / 2, 0, 0], ch=0, axis=[1, 0, 0])[0]) x.append( cmds.cone(radius=thickness * arrowRadiusMult, sections=4, ch=0, pivot=(length * 1.0005, 0, 0))[0]) y.append( cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[0, length / 2, 0], ch=0, axis=[0, 1, 0])[0]) y.append( cmds.cone(radius=thickness * arrowRadiusMult, sections=4, ch=0, pivot=(0, length * 1.0005, 0), axis=[0, 1, 0])[0]) z.append( cmds.cylinder(radius=thickness, sections=4, heightRatio=ratio, pivot=[0, 0, length / 2], ch=0, axis=[0, 0, 1])[0]) z.append( cmds.cone(radius=thickness * arrowRadiusMult, sections=4, ch=0, pivot=(0, 0, length * 1.0005), axis=[0, 0, 1])[0]) nodes.extend(x) nodes.extend(y) nodes.extend(z) if color: for node in x: colorControl(node, name='red_m', color=(1, 0, 0)) for node in y: colorControl(node, name='green_m', color=(0, 1, 0)) for node in z: colorControl(node, name='blue_m', color=(0, 0, 1)) shapes = [] transforms = [] for node in nodes: shapes.append(cmds.listRelatives(node, fullPath=1, shapes=1)[0]) transforms.append(node) cmds.parent(shapes, xform, r=1, s=1) rotateBy = cmds.angleBetween(euler=True, v1=(1, 0, 0), v2=vector) cmds.rotate(rotateBy[0], rotateBy[1], rotateBy[2], xform) cmds.xform(xform, t=point) cmds.delete(transforms) return xform
def HI(self): cmds.cone()
from maya import cmds objectList = [cmds.polyCube(), cmds.circle(), cmds.cone()] for obj in objectList: obj
def cone(*args, **kwargs): res = cmds.cone(*args, **kwargs) if not kwargs.get('query', kwargs.get('q', False)): res = _factories.maybeConvert(res, _general.PyNode) return res
import maya.cmds as cmds cmds.createNode( 'revolve', n='gravityWell' ) cmds.sphere( n='loxTank' ) cmds.cone( n='noseCone' ) cmds.cone( n='fin' ) cmds.pointConstraint( 'fin', 'noseCone', n='weld' ) angle = cmds.getAttr('gravityWell.esw') # Result: 360 # type = cmds.getAttr('loxTank.translate',type=True) # Result: double3 # lock = cmds.getAttr('noseCone.translateX',lock=True) # Result: 0 # finZ = cmds.getAttr('fin.translateZ',time=12) # Result: 0.0 # size = cmds.getAttr('weld.target',size=True) # Result: 1 # size = cmds.getAttr('weld.target',settable=True) # Result: 0 # matrix = cmds.getAttr('loxTank.matrix') # Result: 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 1.0 # cmds.createNode('file',n='file1') cmds.setAttr( 'file1.ftn', '$TMPDIR/smile.gif',type='string' ) s = cmds.getAttr('file1.ftn') # Result: $TMPDIR/smile.gif # s = cmds.getAttr('file1.ftn',x=True) # Result: /var/tmp/smile.gif # # Get the list of all used indices on a multi attribute cmds.getAttr('initialShadingGroup.dagSetMembers', multiIndices=True)
if dataFromUser >= 50 mx.nurbsCube () else: mx.sphere() import maya.cmds as mx dataFromUser = input (‘Please enter number only’) print (dataFromUser) if dataFromUser = =1: mx.nurbsCube() elif dataFromUser = =2: mx.sphere() elif dataFromUser = =3: mx.cylinder() elif dataFromUser = =4: mx.cone() elif dataFromUser = =5: mx.torus() else: mx. plane() 2nd Part The For Loop EX. import maya.cmds as mx for i in range (1 , 10): print (‘this is i = ’str(i)) Make box and move EX. import maya.cmds as mx # your name nameOfItems = [‘Box2’ , ‘Box3’ , ‘Box4’ , ‘Box5’] # for i in range (1 , 10):
def WepIk_Control(): In = cmds.playbackOptions(q=True, min=True) Out = cmds.playbackOptions(q=True, max=True) oSel = cmds.ls(sl=True) oPos_Rot = oSel[1] oWep = oSel[2] oLoc = cmds.spaceLocator(n="Kensaki")[0] oLoc_temp = cmds.spaceLocator(n="Kensaki_World")[0] oLoc_parent = cmds.spaceLocator(n="Kensaki_Pos")[0] cmds.pointConstraint(oPos_Rot, oLoc_parent) cmds.orientConstraint(oWep, oLoc_parent) Be_list = [] Be_list.append(oLoc_parent + '.tx') Be_list.append(oLoc_parent + '.ty') Be_list.append(oLoc_parent + '.tz') cmds.bakeResults(Be_list, sm=True, t=(In, Out), pok=True, sb="1", dic=True, sac=False) cmds.parent(oLoc, oLoc_parent) oVer = cmds.xform(oSel[0], q=True, ws=True, t=True) X = oVer[0] Y = oVer[1] Z = oVer[2] cmds.setAttr(oLoc_temp + ".translateX", X) cmds.setAttr(oLoc_temp + ".translateY", Y) cmds.setAttr(oLoc_temp + ".translateZ", Z) cmds.pointConstraint(oLoc_temp, oLoc) cmds.delete(oLoc_temp) cmds.select(cl=True) oBone = cmds.joint(p=(0, 0, 0), n="handjoint") oWepBone = cmds.joint(p=(50, 0, 0), n="weaponjoint") cmds.pointConstraint(oWep, oBone) point = cmds.pointConstraint(oLoc, oWepBone) cmds.delete(point) oIk = cmds.ikHandle(n="ikHandle_weapon", sol="ikRPsolver", startJoint=oBone) Dummy_1 = cmds.spaceLocator(n="dummy_UPV1") Dummy_2 = cmds.spaceLocator(n="dummy_UPV2") cmds.parent(Dummy_2, Dummy_1) cmds.pointConstraint(oWep, Dummy_1) cmds.select(cl=True) cmds.orientConstraint(oWep, Dummy_1) cmds.setAttr("dummy_UPV2.translateY", 60) oLoc_wep = cmds.spaceLocator(n="weapon_root") Pos_Cont = cmds.sphere(n="weapon_POS", r=6, nsp=2, s=2)[0] cmds.setAttr(Pos_Cont + ".overrideEnabled", 1) cmds.setAttr(Pos_Cont + ".overrideColor", 13) cmds.setAttr(Pos_Cont + ".showManipDefault", 1) cmds.setAttr(Pos_Cont + "Shape.overrideEnabled", 1) cmds.setAttr(Pos_Cont + "Shape.overrideShading", 0) cmds.setAttr(Pos_Cont + "Shape.overrideColor", 13) oCone = cmds.cone(n="weapon_UPV", r=7, hr=2, s=4, nsp=2)[0] cmds.setAttr(oCone + ".overrideEnabled", 1) cmds.setAttr(oCone + ".overrideColor", 6) cmds.setAttr(oCone + ".showManipDefault", 1) cmds.parent(Pos_Cont, oLoc_wep) cmds.parent(oCone, oLoc_wep) cmds.pointConstraint(oPos_Rot, oLoc_wep) Del_Pos = cmds.pointConstraint(Dummy_2, oCone) Del_Pos2 = cmds.pointConstraint(oLoc, Pos_Cont) cmds.pointConstraint(Pos_Cont, oIk[0]) cmds.poleVectorConstraint(oCone, oIk[0]) At_list = [] At_list.append(oCone + '.tx') At_list.append(oCone + '.ty') At_list.append(oCone + '.tz') At_list.append(Pos_Cont + '.tx') At_list.append(Pos_Cont + '.ty') At_list.append(Pos_Cont + '.tz') cmds.bakeResults(At_list, sm=True, t=(In, Out), pok=True, sb="1", dic=True, sac=False) oHand_wep = cmds.spaceLocator(n="cnv_hand") cmds.parent(oHand_wep, oBone) point2 = cmds.pointConstraint(oWep, oHand_wep) ori2 = cmds.orientConstraint(oWep, oHand_wep) cmds.delete(point2, ori2) ori3 = cmds.orientConstraint(oHand_wep, oWep) cmds.select(cl=True) cmds.delete(Del_Pos, Del_Pos2) cmds.group(oLoc_parent, oLoc_wep, oBone, oIk[0], Dummy_1, n="Kensaki")