Python maya.cmds.spaceLocator() Examples
The following are 30
code examples of maya.cmds.spaceLocator().
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: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 6 votes |
def middlePoint(self, a, b, createLocator=False, *args): """ Find the point location in the middle of two items. Return the middle point position as a vector and a locator in it if want. """ if cmds.objExists(a) and cmds.objExists(b): # get xform datas: aPos = cmds.xform(a, query=True, worldSpace=True, rotatePivot=True) bPos = cmds.xform(b, query=True, worldSpace=True, rotatePivot=True) # calculating the result position: resultPosX = ( aPos[0] + bPos[0] )/2 resultPosY = ( aPos[1] + bPos[1] )/2 resultPosZ = ( aPos[2] + bPos[2] )/2 resultPos = [resultPosX, resultPosY, resultPosZ] if createLocator: middleLoc = cmds.spaceLocator(name=a+"_"+b+"_Middle_Loc", position=resultPos)[0] cmds.xform(middleLoc, centerPivots=True) return [resultPos, middleLoc] return[resultPos]
Example #2
Source File: test_cmt_spaceswitch.py From cmt with MIT License | 6 votes |
def test_seamless_switch(self): target = cmds.spaceLocator()[0] driver1 = cmds.spaceLocator()[0] cmds.setAttr("{}.t".format(driver1), 10, 0, 5) driver2 = cmds.spaceLocator()[0] cmds.setAttr("{}.t".format(driver2), -5, 2, 1) cmds.setAttr("{}.r".format(driver2), 40, 0, 0) ss.create_space_switch( target, [(driver1, "local"), (driver2, "world")], "space" ) cmds.setAttr("{}.rx".format(driver1), 30) m1 = cmds.getAttr("{}.worldMatrix[0]".format(target)) ss.switch_space(target, "space", 1) m2 = cmds.getAttr("{}.worldMatrix[0]".format(target)) self.assertListAlmostEqual(m1, m2)
Example #3
Source File: test_cmt_rbf.py From cmt with MIT License | 6 votes |
def test_create(self): loc1 = cmds.spaceLocator()[0] node = rbf.RBF.create( inputs=["{}.t{}".format(loc1, x) for x in "xyz"], outputs=["{}.s{}".format(loc1, x) for x in "xyz"], ) inputs = node.inputs() self.assertEqual(inputs, ["{}.translate{}".format(loc1, x) for x in "XYZ"]) outputs = node.outputs() self.assertEqual(outputs, ["{}.scale{}".format(loc1, x) for x in "XYZ"]) node.add_sample(input_values=[5, 4, 6], output_values=[2, 1, 2]) node.add_sample(input_values=[-5, -6, -4], output_values=[0.5, 2, 3]) cmds.setAttr("{}.t".format(loc1), 0, 0, 0) s = cmds.getAttr("{}.s".format(loc1))[0] self.assertListAlmostEqual(s, [1.0, 1.0, 1.0]) cmds.setAttr("{}.t".format(loc1), 5, 4, 6) s = cmds.getAttr("{}.s".format(loc1))[0] self.assertListAlmostEqual(s, [2.0, 1.0, 2.0]) cmds.setAttr("{}.t".format(loc1), -5, -6, -4) s = cmds.getAttr("{}.s".format(loc1))[0] self.assertListAlmostEqual(s, [0.5, 2.0, 3.0])
Example #4
Source File: test_cmt_rbf.py From cmt with MIT License | 6 votes |
def test_create_plot_demo(self): loc1 = cmds.spaceLocator()[0] node = rbf.RBF.create( inputs=["{}.t{}".format(loc1, x) for x in "xy"], outputs=["{}.tz".format(loc1)], add_neutral_sample=False, ) node.add_sample(input_values=[0, 0], output_values=[1]) node.add_sample(input_values=[2, 3], output_values=[0.5]) node.add_sample(input_values=[3, -1], output_values=[1.5]) node.add_sample(input_values=[-4, -2], output_values=[-1]) node.add_sample(input_values=[-2, 3], output_values=[2]) cmds.setAttr("{}.tx".format(loc1), 0) cmds.setAttr("{}.ty".format(loc1), 0) tz = cmds.getAttr("{}.tz".format(loc1)) self.assertAlmostEqual(tz, 1.0)
Example #5
Source File: test_cmt_rbf.py From cmt with MIT License | 6 votes |
def test_input_rotation(self): loc1 = cmds.spaceLocator()[0] loc2 = cmds.spaceLocator()[0] node = rbf.RBF.create( input_transforms=[loc1], outputs=["{}.s{}".format(loc2, x) for x in "xyz"] ) input_transforms = node.input_transforms() self.assertEqual(input_transforms, [loc1]) outputs = node.outputs() self.assertEqual(outputs, ["{}.scale{}".format(loc2, x) for x in "XYZ"]) node.add_sample(input_rotations=[[90, 45, 0]], output_values=[2, 1, 2]) node.add_sample(input_rotations=[[-90, -60, 0]], output_values=[0.5, 2, 3]) cmds.setAttr("{}.rx".format(loc1), 90) cmds.setAttr("{}.ry".format(loc1), 45) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [2.0, 1.0, 2.0]) cmds.setAttr("{}.rx".format(loc1), -90) cmds.setAttr("{}.ry".format(loc1), -60) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [0.5, 2.0, 3.0]) cmds.setAttr("{}.rx".format(loc1), 0) cmds.setAttr("{}.ry".format(loc1), 0) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [1.0, 1.0, 1.0])
Example #6
Source File: test_rig_common.py From cmt with MIT License | 6 votes |
def test_opm_point_constraint(self): loc1 = cmds.spaceLocator()[0] loc2 = cmds.spaceLocator()[0] cmds.setAttr("{}.t".format(loc1), 1, 2, 3) cmds.setAttr("{}.t".format(loc2), 2, 2, 4) common.opm_point_constraint(loc2, loc1) m1 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) m2 = cmds.getAttr("{}.worldMatrix[0]".format(loc2)) self.assertListAlmostEqual(m1, m2) cmds.setAttr("{}.tx".format(loc2), 5) m1 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) m2 = cmds.getAttr("{}.worldMatrix[0]".format(loc2)) self.assertListAlmostEqual(m1, m2) cmds.setAttr("{}.rx".format(loc2), 30) m1 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) self.assertListAlmostEqual(m1, m2)
Example #7
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_unary(self): loc = cmds.spaceLocator()[0] result = dge("-x", x="{}.tx".format(loc)) cmds.connectAttr(result, "{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, -5)
Example #8
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_pow_precendence(self): loc = cmds.spaceLocator()[0] result = dge("x^(2*2)", x="{}.tx".format(loc)) cmds.connectAttr(result, "{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 625)
Example #9
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_ternary(self): loc = cmds.spaceLocator()[0] result = dge("x < 1 ? x : 4", x="{}.tx".format(loc)) cmds.connectAttr(result, "{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 4) cmds.setAttr("{}.tx".format(loc), 0) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 0)
Example #10
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_ternary_is_equal(self): loc = cmds.spaceLocator()[0] result = dge("x == 1 ? x : 4", x="{}.tx".format(loc)) cmds.connectAttr(result, "{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 4) cmds.setAttr("{}.tx".format(loc), 1) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 1)
Example #11
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_ternary_with_function(self): loc = cmds.spaceLocator()[0] result = dge("x < 1 ? x : exp(x)", x="{}.tx".format(loc)) cmds.connectAttr(result, "{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, math.exp(5), places=3) cmds.setAttr("{}.tx".format(loc), 0) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 0)
Example #12
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_reuse_nodes(self): loc = cmds.spaceLocator()[0] result = dge( "y=(1-x)*(1-x)+(1-x)", x="{}.tx".format(loc), y="{}.ty".format(loc) ) cmds.setAttr("{}.tx".format(loc), 5) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 12) pma = cmds.ls(type="plusMinusAverage") self.assertEqual(len(pma), 2)
Example #13
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_lerp(self): loc = cmds.spaceLocator()[0] dge("y=lerp(4, 8, x)", x="{}.tx".format(loc), y="{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 1) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 8) cmds.setAttr("{}.tx".format(loc), 0) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 4) cmds.setAttr("{}.tx".format(loc), 0.25) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 5)
Example #14
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_min(self): loc = cmds.spaceLocator()[0] dge("y=min(x, 2)", x="{}.tx".format(loc), y="{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 1) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 1) cmds.setAttr("{}.tx".format(loc), 4) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 2)
Example #15
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_max(self): loc = cmds.spaceLocator()[0] dge("y=max(x, 2)", x="{}.tx".format(loc), y="{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 1) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 2) cmds.setAttr("{}.tx".format(loc), 4) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, 4)
Example #16
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_sqrt(self): loc = cmds.spaceLocator()[0] dge("y=sqrt(x)", x="{}.tx".format(loc), y="{}.ty".format(loc)) cmds.setAttr("{}.tx".format(loc), 10.2) y = cmds.getAttr("{}.ty".format(loc)) self.assertAlmostEquals(y, math.sqrt(10.2), places=5)
Example #17
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_sin(self): loc = cmds.spaceLocator(name="sin")[0] loc2 = cmds.spaceLocator()[0] dge("y=sin(x)", x="{}.tx".format(loc), y="{}.ty".format(loc2)) for i in range(100): v = -math.pi * 0.5 + 0.1 * i cmds.setAttr("{}.tx".format(loc), v) y = cmds.getAttr("{}.ty".format(loc2)) self.assertAlmostEquals(y, math.sin(v), places=5)
Example #18
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_tan(self): loc = cmds.spaceLocator(name="tan")[0] loc2 = cmds.spaceLocator()[0] dge("y=tan(x)", x="{}.tx".format(loc), y="{}.ty".format(loc2)) v = -math.pi * 0.5 + 0.02 while v < math.pi * 0.5: v += 0.02 cmds.setAttr("{}.tx".format(loc), v) y = cmds.getAttr("{}.ty".format(loc2)) self.assertAlmostEquals(y, math.tan(v), places=1)
Example #19
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_acos(self): loc = cmds.spaceLocator(name="acos")[0] loc2 = cmds.spaceLocator()[0] dge("y=acos(x)", x="{}.tx".format(loc), y="{}.ty".format(loc2)) for i in range(101): v = -1.0 + 0.02 * i cmds.setAttr("{}.tx".format(loc), v) y = cmds.getAttr("{}.ty".format(loc2)) self.assertAlmostEquals(y, math.degrees(math.acos(v)), places=4)
Example #20
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_asin(self): loc = cmds.spaceLocator(name="asin")[0] loc2 = cmds.spaceLocator()[0] dge("y=asin(x)", x="{}.tx".format(loc), y="{}.ty".format(loc2)) for i in range(101): v = -1.0 + 0.02 * i cmds.setAttr("{}.tx".format(loc), v) y = cmds.getAttr("{}.ty".format(loc2)) self.assertAlmostEquals(y, math.degrees(math.asin(v)), places=4)
Example #21
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_atan(self): loc = cmds.spaceLocator(name="atan")[0] loc2 = cmds.spaceLocator()[0] dge("y=atan(x)", x="{}.tx".format(loc), y="{}.ty".format(loc2)) for i in range(100): v = -5.0 + 0.1 * i cmds.setAttr("{}.tx".format(loc), v) y = cmds.getAttr("{}.ty".format(loc2)) self.assertAlmostEquals(y, math.degrees(math.atan(v)), places=5)
Example #22
Source File: test_cmt_dge.py From cmt with MIT License | 5 votes |
def test_distance(self): loc = cmds.spaceLocator()[0] loc2 = cmds.spaceLocator()[0] cmds.setAttr("{}.tx".format(loc), 2.5) result = dge("distance(i, j)", container="mydistance", i=loc, j=loc2) d = cmds.getAttr(result) self.assertAlmostEquals(d, 2.5)
Example #23
Source File: createdNodesContext.py From AdvancedPythonForMaya with GNU General Public License v3.0 | 5 votes |
def test(): cmds.file(new=True, force=True) with CreatedNodesContext() as cnc: cubes = cmds.polyCube() cmds.polySphere() cmds.spaceLocator() cmds.delete(cubes) print "Created the following nodes:\n\t%s" % ('\n\t'.join(cnc.nodes()))
Example #24
Source File: ml_puppet.py From ml_tools with MIT License | 5 votes |
def matchPoleVectorControl(jointChain, pv=None, doSnap=True): ''' Position a pole vector based on a 3-joint chain ''' def distanceBetween(a,b): difference = [x-y for x,y in zip(a,b)] return math.sqrt(sum([x**2 for x in difference])) p1 = mc.xform(jointChain[0], query=True, rotatePivot=True, worldSpace=True) p2 = mc.xform(jointChain[1], query=True, rotatePivot=True, worldSpace=True) p3 = mc.xform(jointChain[2], query=True, rotatePivot=True, worldSpace=True) mag1 = distanceBetween(p2,p1) mag2 = distanceBetween(p3,p2) #these are all temporary nodes loc = mc.spaceLocator(name='TEMP#')[0] mc.pointConstraint(jointChain[0], loc, weight=mag2) mc.pointConstraint(jointChain[2], loc, weight=mag1) mc.aimConstraint(jointChain[1], loc, aimVector=(1,0,0), upVector=(0,1,0), worldUpType='object', worldUpObject=jointChain[0]) pCenter = mc.xform(loc, query=True, rotatePivot=True, worldSpace=True) pPV = mc.xform(pv, query=True, rotatePivot=True, worldSpace=True) pvDist = distanceBetween(pPV,pCenter) loc2 = mc.spaceLocator(name='TEMP#')[0] loc2 = mc.parent(loc2, loc)[0] mc.setAttr(loc2+'.translate', (pvDist),0,0) if doSnap: snap(pv, loc2) mc.delete(loc) else: #for matching a range return loc, loc2
Example #25
Source File: common.py From SIWeightEditor with MIT License | 5 votes |
def main(self, objects=None, dummyParent=None, srtDummyParent=None, mode='cut', preSelection=None): self.objects = objects self.dummyParent = dummyParent self.srtDummyParent = srtDummyParent self.preSelection = preSelection # リストタイプじゃなかったらリストに変換する if not isinstance(self.objects, list): temp = self.objects self.objects = [] self.objects.append(temp) for self.node in self.objects: if mode == 'create': self.dummyParent = cmds.spaceLocator(name='dummyLocatorForParent') return self.dummyParent elif mode == 'delete': cmds.delete(self.dummyParent) return elif mode == 'cut': self.cutChildNode() return elif mode == 'custom_cut': self.customCutChildNode() return elif mode == 'parent': self.reparentNode() return
Example #26
Source File: test_rig_common.py From cmt with MIT License | 5 votes |
def test_opm_parent_constraint(self): loc1 = cmds.spaceLocator()[0] loc2 = cmds.spaceLocator()[0] cmds.setAttr("{}.t".format(loc1), 1, 2, 3) cmds.setAttr("{}.t".format(loc2), 2, 2, 4) m1 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) common.opm_parent_constraint(loc2, loc1, maintain_offset=True) m2 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) self.assertListAlmostEqual(m1, m2) cmds.setAttr("{}.rx".format(loc2), 30) m2 = cmds.getAttr("{}.worldMatrix[0]".format(loc1)) expected = [ 1.0, 0.0, 0.0, 0.0, 0.0, 0.8660254037844387, 0.49999999999999994, 0.0, 0.0, -0.49999999999999994, 0.8660254037844387, 0.0, 1.0, 2.5, 3.133974596215561, 1.0, ] self.assertListAlmostEqual(expected, m2)
Example #27
Source File: common.py From SISideBar with MIT License | 5 votes |
def main(self, objects=None, dummyParent=None, srtDummyParent=None, mode='cut', preSelection=None): self.objects = objects self.dummyParent = dummyParent self.srtDummyParent = srtDummyParent self.preSelection = preSelection # リストタイプじゃなかったらリストに変換する if not isinstance(self.objects, list): temp = self.objects self.objects = [] self.objects.append(temp) for self.node in self.objects: if mode == 'create': self.dummyParent = cmds.spaceLocator(name='dummyLocatorForParent') return self.dummyParent elif mode == 'delete': cmds.delete(self.dummyParent) return elif mode == 'cut': self.cutChildNode() return elif mode == 'custom_cut': self.customCutChildNode() return elif mode == 'parent': self.reparentNode() return
Example #28
Source File: Create.py From rush with MIT License | 5 votes |
def locator(): cmds.spaceLocator(p=[0, 0, 0]) # Measure Tools
Example #29
Source File: skeleton.py From video2mocap with MIT License | 5 votes |
def create_skeleton(): """ Create a skeleton hierarchy using the variables provided in the path module. :return: Skeleton data :rtype: dict """ # variable joints = {} # clear selection cmds.select(clear=True) # create body for body in BODY_HIERARCHY: joint = cmds.joint(name="{}_jnt".format(body)) joints[body] = joint # create limbs for side in ["l", "r"]: cmds.select(joints["hip"]) for leg in LEG_HIERARCHY: joint = cmds.joint(name="{}_{}_jnt".format(side, leg)) joints["{}_{}".format(side, leg)] = joint cmds.select(joints["spine"]) for arm in ARM_HIERARCHY: joint = cmds.joint(name="{}_{}_jnt".format(side, arm)) joints["{}_{}".format(side, arm)] = joint # reference reference_name = "reference" reference = cmds.spaceLocator(name=reference_name)[0] joints["reference"] = reference # parent hip to reference cmds.parent(joints["hip"], reference) return joints
Example #30
Source File: test_cmt_rbf.py From cmt with MIT License | 5 votes |
def test_input_rotation_swing(self): loc1 = cmds.spaceLocator()[0] loc2 = cmds.spaceLocator()[0] node = rbf.RBF.create( input_transforms=[loc1], outputs=["{}.s{}".format(loc2, x) for x in "xyz"] ) node.add_sample( input_rotations=[[0, 0, 90]], output_values=[2, 1, 2], rotation_type=rbf.RBF.swing, ) node.add_sample( input_rotations=[[0, 0, -90]], output_values=[0.5, 2, 3], rotation_type=rbf.RBF.swing, ) cmds.setAttr("{}.rx".format(loc1), 90) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [1.0, 1.0, 1.0]) cmds.setAttr("{}.rx".format(loc1), 0) cmds.setAttr("{}.rz".format(loc1), 90) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [2, 1, 2]) cmds.setAttr("{}.rx".format(loc1), 90) s = cmds.getAttr("{}.s".format(loc2))[0] self.assertListAlmostEqual(s, [2, 1, 2])