Python maya.cmds.curve() Examples
The following are 30
code examples of maya.cmds.curve().
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 | 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 #2
Source File: ml_arcTracer.py From ml_tools with MIT License | 6 votes |
def applyBrush(curve, parent): ''' Simply applies the paint effects brush to the curve with the settings we want. ''' mc.AttachBrushToCurves(curve) stroke = mc.ls(sl=True)[0] stroke = mc.parent(stroke,parent)[0] mc.setAttr(stroke+'.displayPercent',92) mc.setAttr(stroke+'.sampleDensity',0.5) mc.setAttr(stroke+'.inheritsTransform',0) mc.setAttr(stroke+'.translate',0,0,0) mc.setAttr(stroke+'.rotate',0,0,0) return stroke
Example #3
Source File: orientjoints.py From cmt with MIT License | 6 votes |
def create_arrow(jointName): curve = cmds.curve( name="%s_ForwardDirection" % jointName, degree=1, point=[ (-1, 0, 0), (-1, 2, 0), (-2, 2, 0), (0, 4, 0), (2, 2, 0), (1, 2, 0), (1, 0, 0), (-1, 0, 0), ], ) group = cmds.group() cmds.xform(objectSpace=True, pivots=(0, 0, 0)) jointScale = cmds.jointDisplayScale(query=True) jointRadius = cmds.getAttr("%s.radius" % jointName) jointScale *= jointRadius cmds.xform(scale=(jointScale, jointScale, jointScale)) return group
Example #4
Source File: test_cmt_control.py From cmt with MIT License | 6 votes |
def test_get_curve_object_with_history(self): curve = cmds.circle()[0] obj = control.CurveShape(curve) self.assertEqual(obj.degree, 3) self.assertEqual(obj.form, 2) self.assertListEqual(obj.knots, range(-2, 11)) expected_cvs = [ (0.7836116248912245, 0.7836116248912246, 0.0), (6.785732323110912e-17, 1.1081941875543877, 0.0), (-0.7836116248912245, 0.7836116248912244, 0.0), (-1.1081941875543881, 5.74489823752483e-17, 0.0), (-0.7836116248912245, -0.7836116248912245, 0.0), (-1.1100856969603225e-16, -1.1081941875543884, 0.0), (0.7836116248912245, -0.7836116248912244, 0.0), (1.1081941875543881, -1.511240500779959e-16, 0.0), ] self.cvs_are_equal(obj.cvs, expected_cvs) self.assertIsNone(obj.color)
Example #5
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def splitCurveToParametersByParameter(curve, num): """ Get a list of parameters evenly spaced along a curve, based on the division of its parameters. Ranges are normalizes to be between 0-1. :param str curve: :param int num: :return: parameters :rtype: list """ increment = 1.0 / (num - 1) parameters = [i * increment for i in range(num)] if cmds.getAttr("{0}.form".format(curve)) == 2: parameters.insert(0, parameters[-1]) parameters.pop(-1) return parameters # ----------------------------------------------------------------------------
Example #6
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def createCurveShape(name, points): """ Create a curve and rename the shapes to be unique. :param str name: Name of curve :param list points: List of points. """ # create curve curve = cmds.curve(p=points, d=1, n=name) # rename shapes shapes = [] for shape in cmds.listRelatives(curve, s=True, f=True) or []: shape = cmds.rename(shape, "{0}Shape".format(name)) shapes.append(shape) return curve, shapes
Example #7
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 6 votes |
def convertToBezierCurve(curve): """ Check if the parsed curve is a bezier curve, if this is not the case convert the curve to a bezier curve. :param str curve: Name of curve """ # get shape curveShape = cmds.listRelatives(curve, s=True)[0] # convert to bezier curve if cmds.nodeType(curveShape) == "bezierCurve": return cmds.select(curve) cmds.nurbsCurveToBezier() # ----------------------------------------------------------------------------
Example #8
Source File: control.py From cmt with MIT License | 5 votes |
def create(self, transform=None, as_controller=True): """Create a curve. :param transform: Name of the transform to create the curve shape under. If the transform does not exist, it will be created. :param as_controller: True to mark the curve transform as a controller. :return: The transform of the new curve shapes. """ transform = transform or self.transform if not cmds.objExists(transform): transform = cmds.createNode("transform", name=transform) periodic = self.form == 2 points = self._get_transformed_points() points = points + points[: self.degree] if periodic else points curve = cmds.curve(degree=self.degree, p=points, per=periodic, k=self.knots) shape = shortcuts.get_shape(curve) if self.color is not None: cmds.setAttr("{}.overrideEnabled".format(shape), True) if isinstance(self.color, int): cmds.setAttr("{}.overrideColor".format(shape), self.color) else: cmds.setAttr("{}.overrideRGBColors".format(shape), True) cmds.setAttr("{}.overrideColorRGB".format(shape), *self.color) cmds.parent(shape, transform, r=True, s=True) shape = cmds.rename(shape, "{}Shape".format(transform)) cmds.delete(curve) if as_controller: cmds.controller(transform) logger.info("Created curve {} for transform {}".format(shape, transform)) return transform
Example #9
Source File: test_cmt_control.py From cmt with MIT License | 5 votes |
def test_save_and_load_curves(self): file_path = self.get_temp_filename("test_curve.json") control.export_curves([self.curve], file_path) self.assertTrue(os.path.exists(file_path)) cmds.delete(self.curve) controls = control.import_curves(file_path) self.assertTrue(cmds.objExists(self.curve)) self.assertEqual(controls[0], self.curve) self.test_get_curve_object()
Example #10
Source File: test_cmt_control.py From cmt with MIT License | 5 votes |
def test_save_and_load_curve_on_other_transform(self): file_path = self.get_temp_filename("test_curve.json") control.export_curves([self.curve], file_path) other = cmds.createNode("transform", name="other") cmds.setAttr("{}.tx".format(other), 2) control.import_curves_on_selected(file_path) self.assertTrue(cmds.objExists("otherShape")) obj = control.CurveShape(other) self.assertEqual(obj.degree, 3) self.assertEqual(obj.form, 0) self.assertListEqual(obj.knots, self.knots) self.cvs_are_equal(obj.cvs, self.cvs) self.assertIsNone(obj.color)
Example #11
Source File: orientjoints.py From cmt with MIT License | 5 votes |
def create_orient_manipulator(joint, material): joint_scale = cmds.jointDisplayScale(query=True) joint_radius = cmds.getAttr("{0}.radius".format(joint)) radius = joint_scale * joint_radius children = cmds.listRelatives(joint, children=True, path=True) if children: p1 = cmds.xform(joint, q=True, ws=True, t=True) p1 = OpenMaya.MPoint(*p1) p2 = cmds.xform(children[0], q=True, ws=True, t=True) p2 = OpenMaya.MPoint(*p2) radius = p1.distanceTo(p2) arrow_cvs = [ [-1, 0, 0], [-1, 2, 0], [-2, 2, 0], [0, 4, 0], [2, 2, 0], [1, 2, 0], [1, 0, 0], [-1, 0, 0], ] arrow_cvs = [[x[0] * radius, x[1] * radius, x[2] * radius] for x in arrow_cvs] shape = cmds.curve(name="{0}_zForward".format(joint), degree=1, point=arrow_cvs) # shape = cmds.sphere(n='{0}_zForward'.format(joint), p=(0, 0, 0), ax=(0, 0, -1), ssw=0, esw=180, r=radius, d=3, ut=0, tol=0.01, s=8, nsp=4, ch=0)[0] # cmds.setAttr('{0}.sz'.format(shape), 0) # cmds.select(shape) # cmds.hyperShade(assign=material) group = cmds.createNode("transform", name="{0}_grp".format(shape)) cmds.parent(shape, group) cmds.makeIdentity(shape, apply=True) cmds.addAttr(shape, longName=MESSAGE_ATTRIBUTE, attributeType="message") cmds.connectAttr( "{0}.message".format(joint), "{0}.{1}".format(shape, MESSAGE_ATTRIBUTE) ) for attr in ["tx", "ty", "tz", "ry", "rz", "v"]: cmds.setAttr("{0}.{1}".format(shape, attr), lock=True, keyable=False) return group, shape
Example #12
Source File: control.py From cmt with MIT License | 5 votes |
def import_new_curves(file_path=None, tag_as_controller=False): """Imports control shapes from disk onto new transforms. :param file_path: Path to the control file. :param tag_as_controller: True to tag the curve transform as a controller :return: The new curve transforms """ controls = load_curves(file_path) transforms = [] for curve in controls: transform = _get_new_transform_name(curve.transform) transforms.append(curve.create(transform, tag_as_controller)) return transforms
Example #13
Source File: control.py From cmt with MIT License | 5 votes |
def import_curves(file_path=None, tag_as_controller=False): """Imports control shapes from disk onto their saved named transforms. :param file_path: Path to the control file. :param tag_as_controller: True to tag the curve transform as a controller :return: The new curve transforms """ controls = load_curves(file_path) transforms = [ curve.create(curve.transform, tag_as_controller) for curve in controls ] return transforms
Example #14
Source File: control.py From cmt with MIT License | 5 votes |
def import_curves_on_selected(file_path=None, tag_as_controller=False): """Imports a control shape from disk onto the selected transform. :param file_path: Path to the control file. :param tag_as_controller: True to tag the curve transform as a controller :return: The new curve transform """ controls = load_curves(file_path) selected_transforms = cmds.ls(sl=True) if not selected_transforms: return for transform in selected_transforms: for curve in controls: curve.create(transform, tag_as_controller) return selected_transforms
Example #15
Source File: test_cmt_control.py From cmt with MIT License | 5 votes |
def test_create_on_existing_transform(self): transform = cmds.createNode("transform", name="my_new_transform") obj = control.CurveShape(self.curve) transform2 = obj.create(transform) self.assertEqual(transform, transform2) self.assertTrue(cmds.objExists(transform)) obj = control.CurveShape(transform) self.assertEqual(obj.degree, 3) self.assertEqual(obj.form, 0) self.assertListEqual(obj.knots, self.knots) self.cvs_are_equal(obj.cvs, self.cvs) self.assertIsNone(obj.color)
Example #16
Source File: control.py From cmt with MIT License | 5 votes |
def translate_by(self, x, y, z, local=True): """Translate the curve cvs by the given values :param x: Translate X :param y: Translate Y :param z: Translate Z :param local: True for local space, False for world """ space = OpenMaya.MSpace.kObject if local else OpenMaya.MSpace.kWorld self.transform_matrix.translateBy(OpenMaya.MVector(x, y, z), space)
Example #17
Source File: control.py From cmt with MIT License | 5 votes |
def set_translation(self, x, y, z, local=True): """Set the absolute translation of the curve shape. :param x: Translate X :param y: Translate Y :param z: Translate Z :param local: True for local space, False for world """ space = OpenMaya.MSpace.kObject if local else OpenMaya.MSpace.kWorld self.transform_matrix.setTranslation(OpenMaya.MVector(x, y, z), space)
Example #18
Source File: control.py From cmt with MIT License | 5 votes |
def rotate_by(self, x, y, z, local=True): """Rotate the curve cvs by the given euler rotation values :param x: Rotate X :param y: Rotate Y :param z: Rotate Z :param local: True for local space, False for world """ x, y, z = [v * 0.0174533 for v in [x, y, z]] space = OpenMaya.MSpace.kObject if local else OpenMaya.MSpace.kWorld self.transform_matrix.rotateBy(OpenMaya.MEulerRotation(x, y, z), space)
Example #19
Source File: control.py From cmt with MIT License | 5 votes |
def set_rotation(self, x, y, z): """Set the absolute rotation of the curve shape in euler rotations. :param x: Rotate X :param y: Rotate Y :param z: Rotate Z """ x, y, z = [v * 0.0174533 for v in [x, y, z]] self.transform_matrix.setRotation(OpenMaya.MEulerRotation(x, y, z))
Example #20
Source File: control.py From cmt with MIT License | 5 votes |
def set_scale(self, x, y, z, local=True): """Set the absolute scale of the curve shape. :param x: Scale X :param y: Scale Y :param z: Scale Z :param local: True for local space, False for world """ space = OpenMaya.MSpace.kObject if local else OpenMaya.MSpace.kWorld self.transform_matrix.setScale([x, y, z], space)
Example #21
Source File: control.py From cmt with MIT License | 5 votes |
def mirror_curve(source, destination): """Mirrors the curve on source across the YZ plane to destination. The cvs will be mirrored in world space no matter the transform of destination. :param source: Source transform :param destination: Destination transform :return: The mirrored CurveShape object """ source_curve = CurveShape(source) path_source = shortcuts.get_dag_path2(source) matrix = path_source.inclusiveMatrix() path_destination = shortcuts.get_dag_path2(destination) inverse_matrix = path_destination.inclusiveMatrixInverse() world_cvs = [OpenMaya.MPoint(*x) * matrix for x in source_curve.cvs] for cv in world_cvs: cv.x *= -1 local_cvs = [p * inverse_matrix for p in world_cvs] source_curve.cvs = [(p.x, p.y, p.z) for p in local_cvs] is_controller = cmds.controller(source, q=True, isController=True) source_curve.transform = destination source_curve.create(destination, as_controller=is_controller) return source_curve
Example #22
Source File: control.py From cmt with MIT License | 5 votes |
def get_knots(curve): """Gets the list of knots of a curve so it can be recreated. :param curve: Curve to query. :return: A list of knot values that can be passed into the curve creation command. """ curve = shortcuts.get_shape(curve) info = cmds.createNode("curveInfo") cmds.connectAttr("{0}.worldSpace".format(curve), "{0}.inputCurve".format(info)) knots = cmds.getAttr("{0}.knots[*]".format(info)) knots = [int(x) for x in knots] cmds.delete(info) return knots
Example #23
Source File: plotBendHV.py From maya_rotationDriver with MIT License | 5 votes |
def _createCurve(name, angle, cvs, parent): node = cmds.curve(d=1, p=cvs) cmds.parent(node, parent) name += '_n%03d' if angle < 0. else '_p%03d' cmds.rename(node, name % abs(round(angle))) return node
Example #24
Source File: curve.py From maya-spline-ik with GNU General Public License v3.0 | 5 votes |
def numCVs(curve): """ Get the number of CVs of a curve. :param curve: :return: number of cvs :rtype: int """ return cmds.getAttr("{0}.cp".format(curve), s=1) # ----------------------------------------------------------------------------
Example #25
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def createCurve(self, cvName, cvDegree, cvPointList, cvKnot, cvPeriodic, dpGuide, *args): """ Create and return a simple curve using given parameters. """ cvCurve = cmds.curve(name=cvName, point=cvPointList, degree=cvDegree, knot=cvKnot, periodic=cvPeriodic) self.addControlInfo(cvCurve, dpGuide=dpGuide) self.ctrls.renameShape([cvCurve]) return cvCurve
Example #26
Source File: dpBaseControlClass.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def cvCreate(self, useUI, cvID, cvName='Control_Ctrl', cvSize=1.0, cvDegree=1, cvDirection='+Y', cvRot=(0, 0, 0), cvAction=1, dpGuide=False, combine=False, *args): """ Check if we need to get parameters from UI. Create a respective curve shape. Return the transform curve or a list of selected destination items. """ # getting current selection: destinationList = cmds.ls(selection=True, type="transform") # check if the given name is good or add a sequencial number on it: self.cvName = utils.validateName(cvName, self.suffix) self.cvID = cvID self.cvSize = cvSize self.cvDegree = cvDegree self.cvDirection = cvDirection self.cvRot = cvRot self.cvAction = cvAction # getting UI info: if useUI: self.getControlUIValues(self.cvName) # combine or create curve using the parameters: if combine: self.cvCurve = self.generateCombineCurves(useUI, self.cvID, self.cvName, self.cvSize, self.cvDegree, self.cvDirection) else: # getting curve info to be created based on choose degree: if self.cvDegree == 1: #linear self.getLinearPoints() else: #cubic self.getCubicPoints() self.cvCurve = self.createCurve(self.cvName, self.cvDegree, self.cvPointList, self.cvKnotList, self.cvPeriodic, dpGuide) # set control direction for the control curve: self.setControlDirection(self.cvCurve, self.cvDirection) # working about action to do, like new control, add shape or replace shapes: self.doControlAction(destinationList) # select the result node and return it if self.cvAction == 1: #new control cmds.select(self.cvCurve) return self.cvCurve elif destinationList: cmds.select(destinationList) return destinationList
Example #27
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def cvJointLoc(self, ctrlName, r=0.3, d=1, rot=(0, 0, 0), guide=True, *args): """Create and return a cvJointLocator curve to be usually used in the guideSystem and the clusterHandle to shapeSize. """ # create locator curve: cvLoc = self.cvLocator(ctrlName+"_CvLoc", r, d) # create arrow curves: cvArrow1 = cmds.curve(n=ctrlName+"_CvArrow1", d=3, p=[(-0.1*r, 0.9*r, 0.2*r), (-0.1*r, 0.9*r, 0.23*r), (-0.1*r, 0.9*r, 0.27*r), (-0.1*r, 0.9*r, 0.29*r), (-0.1*r, 0.9*r, 0.3*r), (-0.372*r, 0.9*r, 0.24*r), (-0.45*r, 0.9*r, -0.13*r), (-0.18*r, 0.9*r, -0.345*r), (-0.17*r, 0.9*r, -0.31*r), (-0.26*r, 0.9*r, -0.41*r), (-0.21*r, 0.9*r, -0.41*r), (-0.05*r, 0.9*r, -0.4*r), (0, 0.9*r, -0.4*r), (-0.029*r, 0.9*r, -0.33*r), (-0.048*r, 0.9*r, -0.22*r), (-0.055*r, 0.9*r, -0.16*r), (-0.15*r, 0.9*r, -0.272*r), (-0.12*r, 0.9*r, -0.27*r), (-0.35*r, 0.9*r, -0.1*r), (-0.29*r, 0.9*r, 0.15*r), (-0.16*r, 0.9*r, 0.21*r), (-0.1*r, 0.9*r, 0.2*r)] ) cvArrow2 = cmds.curve(n=ctrlName+"_CvArrow2", d=3, p=[(0.1*r, 0.9*r, -0.2*r), (0.1*r, 0.9*r, -0.23*r), (0.1*r, 0.9*r, -0.27*r), (0.1*r, 0.9*r, -0.29*r), (0.1*r, 0.9*r, -0.3*r), (0.372*r, 0.9*r, -0.24*r), (0.45*r, 0.9*r, 0.13*r), (0.18*r, 0.9*r, 0.345*r), (0.17*r, 0.9*r, 0.31*r), (0.26*r, 0.9*r, 0.41*r), (0.21*r, 0.9*r, 0.41*r), (0.05*r, 0.9*r, 0.4*r), (0, 0.9*r, 0.4*r), (0.029*r, 0.9*r, 0.33*r), (0.048*r, 0.9*r, 0.22*r), (0.055*r, 0.9*r, 0.16*r), (0.15*r, 0.9*r, 0.272*r), (0.12*r, 0.9*r, 0.27*r), (0.35*r, 0.9*r, 0.1*r), (0.29*r, 0.9*r, -0.15*r), (0.16*r, 0.9*r, -0.21*r), (0.1*r, 0.9*r, -0.2*r)] ) cvArrow3 = cmds.curve(n=ctrlName+"_CvArrow3", d=3, p=[(-0.1*r, -0.9*r, 0.2*r), (-0.1*r, -0.9*r, 0.23*r), (-0.1*r, -0.9*r, 0.27*r), (-0.1*r, -0.9*r, 0.29*r), (-0.1*r, -0.9*r, 0.3*r), (-0.372*r, -0.9*r, 0.24*r), (-0.45*r, -0.9*r, -0.13*r), (-0.18*r, -0.9*r, -0.345*r), (-0.17*r, -0.9*r, -0.31*r), (-0.26*r, -0.9*r, -0.41*r), (-0.21*r, -0.9*r, -0.41*r), (-0.05*r, -0.9*r, -0.4*r), (0, -0.9*r, -0.4*r), (-0.029*r, -0.9*r, -0.33*r), (-0.048*r, -0.9*r, -0.22*r), (-0.055*r, -0.9*r, -0.16*r), (-0.15*r, -0.9*r, -0.272*r), (-0.12*r, -0.9*r, -0.27*r), (-0.35*r, -0.9*r, -0.1*r), (-0.29*r, -0.9*r, 0.15*r), (-0.16*r, -0.9*r, 0.21*r), (-0.1*r, -0.9*r, 0.2*r)] ) cvArrow4 = cmds.curve(n=ctrlName+"_CvArrow4", d=3, p=[(0.1*r, -0.9*r, -0.2*r), (0.1*r, -0.9*r, -0.23*r), (0.1*r, -0.9*r, -0.27*r), (0.1*r, -0.9*r, -0.29*r), (0.1*r, -0.9*r, -0.3*r), (0.372*r, -0.9*r, -0.24*r), (0.45*r, -0.9*r, 0.13*r), (0.18*r, -0.9*r, 0.345*r), (0.17*r, -0.9*r, 0.31*r), (0.26*r, -0.9*r, 0.41*r), (0.21*r, -0.9*r, 0.41*r), (0.05*r, -0.9*r, 0.4*r), (0, -0.9*r, 0.4*r), (0.029*r, -0.9*r, 0.33*r), (0.048*r, -0.9*r, 0.22*r), (0.055*r, -0.9*r, 0.16*r), (0.15*r, -0.9*r, 0.272*r), (0.12*r, -0.9*r, 0.27*r), (0.35*r, -0.9*r, 0.1*r), (0.29*r, -0.9*r, -0.15*r), (0.16*r, -0.9*r, -0.21*r), (0.1*r, -0.9*r, -0.2*r)] ) cvArrow5 = cmds.curve(n=ctrlName+"_CvArrow5", d=1, p=[(0, 0, 1.2*r), (0.09*r, 0, 1*r), (-0.09*r, 0, 1*r), (0, 0, 1.2*r)] ) cvArrow6 = cmds.curve(n=ctrlName+"_CvArrow6", d=1, p=[(0, 0, 1.2*r), (0, 0.09*r, 1*r), (0, -0.09*r, 1*r), (0, 0, 1.2*r)] ) # rename curveShape: locArrowList = [cvLoc, cvArrow1, cvArrow2, cvArrow3, cvArrow4, cvArrow5, cvArrow6] self.renameShape(locArrowList) # create ball curve: cvTemplateBall = self.cvControl("Ball", ctrlName+"_CvBall", r=0.7*r, d=3) # parent shapes to transform: locCtrl = cmds.group(name=ctrlName, empty=True) ballChildrenList = cmds.listRelatives(cvTemplateBall, shapes=True, children=True) for ballChildren in ballChildrenList: cmds.setAttr(ballChildren+".template", 1) self.transferShape(True, False, cvTemplateBall, [locCtrl]) for transform in locArrowList: self.transferShape(True, False, transform, [locCtrl]) # set rotation direction: cmds.setAttr(locCtrl+".rotateX", rot[0]) cmds.setAttr(locCtrl+".rotateY", rot[1]) cmds.setAttr(locCtrl+".rotateZ", rot[2]) cmds.makeIdentity(locCtrl, rotate=True, apply=True) # create an attribute to be used as guide by module: cmds.addAttr(locCtrl, longName="nJoint", attributeType='long') cmds.setAttr(locCtrl+".nJoint", 1) # colorize curveShapes: self.colorShape([locCtrl], 'blue') # shapeSize setup: shapeSizeCluster = self.shapeSizeSetup(locCtrl) cmds.select(clear=True) return [locCtrl, shapeSizeCluster]
Example #28
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def cvCharacter(self, ctrlType, ctrlName, r=1, d=1, dir="+Y", rot=(0, 0, 0), *args): """ Create and return a curve to be used as a control. """ # get radius by checking linear unit r = self.dpCheckLinearUnit(r) curve = self.cvControl(ctrlType, ctrlName, r, d, dir, rot) # edit a minime curve: cmds.addAttr(curve, longName="rigScale", attributeType='float', defaultValue=1, keyable=True) cmds.addAttr(curve, longName="rigScaleMultiplier", attributeType='float', defaultValue=1, keyable=False) # create Option_Ctrl Text: try: optCtrlTxt = cmds.group(name="Option_Ctrl_Txt", empty=True) try: cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Source Sans Pro", text="Option Ctrl", constructionHistory=False)[0] except: cvText = cmds.textCurves(name="Option_Ctrl_Txt_TEMP_Grp", font="Arial", text="Option Ctrl", constructionHistory=False)[0] txtShapeList = cmds.listRelatives(cvText, allDescendents=True, type='nurbsCurve') if txtShapeList: for s, shape in enumerate(txtShapeList): # store CV world position curveCVList = cmds.getAttr(shape+'.cp', multiIndices=True) vtxWorldPosition = [] for i in curveCVList : cvPointPosition = cmds.xform(shape+'.cp['+str(i)+']', query=True, translation=True, worldSpace=True) vtxWorldPosition.append(cvPointPosition) # parent the shapeNode : cmds.parent(shape, optCtrlTxt, r=True, s=True) # restore the shape world position for i in curveCVList: cmds.xform(shape+'.cp['+str(i)+']', a=True, worldSpace=True, t=vtxWorldPosition[i]) cmds.rename(shape, optCtrlTxt+"Shape"+str(s)) cmds.delete(cvText) cmds.parent(optCtrlTxt, curve) cmds.setAttr(optCtrlTxt+".template", 1) cmds.setAttr(optCtrlTxt+".tx", -0.72*r) cmds.setAttr(optCtrlTxt+".ty", 1.1*r) except: # it will pass if we don't able to find the font to create the text pass return curve
Example #29
Source File: dpControls.py From dpAutoRigSystem with GNU General Public License v2.0 | 5 votes |
def resetCurve(self, changeDegree=False, transformList=False, *args): """ Read the current curve degree of selected curve controls and change it to another one. 1 to 3 or 3 to 1. """ if not transformList: transformList = cmds.ls(selection=True, type="transform") if transformList: for item in transformList: if cmds.objExists(item+".dpControl") and cmds.getAttr(item+".dpControl") == 1: # getting current control values from stored attributes: curType = cmds.getAttr(item+".className") curSize = cmds.getAttr(item+".size") curDegree = cmds.getAttr(item+".degree") curDir = cmds.getAttr(item+".direction") curRotX = cmds.getAttr(item+".cvRotX") curRotY = cmds.getAttr(item+".cvRotY") curRotZ = cmds.getAttr(item+".cvRotZ") if changeDegree: # changing current curve degree: if curDegree == 1: #linear curDegree = 3 #cubic else: #cubic curDegree = 1 #linear cmds.setAttr(item+".degree", curDegree) curve = self.cvControl(curType, "Temp_Ctrl", curSize, curDegree, curDir, (curRotX, curRotY, curRotZ), 1) self.transferShape(deleteSource=True, clearDestinationShapes=True, sourceItem=curve, destinationList=[item], applyColor=True) cmds.select(transformList)
Example #30
Source File: test_cmt_control.py From cmt with MIT License | 5 votes |
def test_get_control_data(self): controls = control.get_curve_data([self.curve]) expected = [ { "transform": self.curve, "cvs": self.cvs, "degree": 3, "form": 0, "knots": self.knots, "color": None, } ] expected = json.dumps(expected, sort_keys=True) actual = json.dumps(controls, sort_keys=True, cls=control.CurveShapeEncoder) self.assertEqual(expected, actual)