pymel.core.modeling.curve

curve(*args, **kwargs)

The curve command creates a new curve from a list of control vertices (CVs). A string is returned containing the pathname to the newly created curve. You can create a curve from points either in world space or object (local) space, either with weights or without. You can replace an existing curve by using the -r/replaceflag. You can append a point to an existing curve by using the -a/appendflag. To create a curve-on-surface, use the curveOnSurface command. To change the degree of a curve, use the rebuildCurve command. To change the of parameter range curve, use the rebuildCurve command.

Maya Bug Fix:
  • name parameter only applied to transform. now applies to shape as well

Flags:

Long Name / Short Name Argument Types Properties
append / a bool ../../../_images/create.gif
  Appends point(s) to the end of an existing curve. If you use this flag, you must specify the name of the curve to append to, at the end of the command. (See examples below.)
bezier / bez bool ../../../_images/create.gif
  The created curve will be a bezier curve.
degree / d float ../../../_images/create.gif
  The degree of the new curve. Default is 3. Note that you need (degree+1) curve points to create a visible curve span. eg. you must place 4 points for a degree 3 curve.
editPoint / ep float, float, float ../../../_images/create.gif
  The x, y, z position of an edit point. linearmeans that this flag can take values with units. This flag can not be used with the -point or the -pointWeight flags.
knot / k float ../../../_images/create.gif
  A knot value in a knot vector. One flag per knot value. There must be (numberOfPoints + degree - 1) knots and the knot vector must be non-decreasing.
name / n unicode ../../../_images/create.gif
  Name of the curve
objectSpace / os bool ../../../_images/create.gif
  Points are in object, or localspace. This is the default. You cannot specify both -osand -wsin the same command.
periodic / per bool ../../../_images/create.gif
  If on, creates a curve that is periodic. Default is off.
point / p float, float, float ../../../_images/create.gif
  The x, y, z position of a point. linearmeans that this flag can take values with units.
pointWeight / pw float, float, float, float ../../../_images/create.gif
  The x,y,z and w values of a point, where the w is a weight value. A rational curve will be created if this flag is used. linearmeans that this flag can take values with units.
replace / r bool ../../../_images/create.gif
  Replaces an entire existing curve. If you use this flag, you must specify the name of the curve to replace, at the end of the command. (See examples below.)
worldSpace / ws bool ../../../_images/create.gif
  Points are in world space. The default is -os. You cannot specify both -osand -wsin the same command. Flag can have multiple arguments, passed either as a tuple or a list.

Derived from mel command maya.cmds.curve

Example:

import pymel.core as pm

# These commands create curves with four control vertices.
# The first one is created without weights.  The third command
# shows how you can use units to specify position.
pm.curve( p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9)] )
# Result: nt.Transform(u'curve1') #
pm.curve( pw=[(0, 0, 0, 1), (3, 5, 6, 1), (5, 6, 7, 1), (9, 9, 9, 1)] )
# Result: nt.Transform(u'curve2') #
pm.curve( p=[('0cm', '0cm', '0cm'), ('3in', '5in', '6in'), ('5ft', '6ft', '7ft'), (9, 9, 9)] )
# Result: nt.Transform(u'curve3') #

# This command replaces an existing curve, curve1, with the given points.
# Do not use this flag on a curve that is a result of a construction
# history operation.
pm.curve( 'curve1', r=True, p=[(0, 0, 0), (3, 5, 6), (10, 12, 14), (9, 9, 9)] )
# Result: nt.Transform(u'curve1') #

# This command adds two CVs to an existing curve, curve1.
# The "-ws" flag can be used if the specified CVs are in world space.
# Do not use this flag on a curve that is a result of a construction
# history operation.
pm.curve( 'curve1', a=True, p=[(13, 13, 13), (13, 15, 16)] )
# Result: nt.Transform(u'curve1') #

# This command creates a curve with five control vertices,
# with a knot vector. Notice that there must be
# (number of CVs + degree - 1) knots and that the knot
# vector must be non-decreasing.
pm.curve( p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9), (12, 10, 2)], k=[0,0,0,1,2,2,2] )
# Result: nt.Transform(u'curve4') #

# This command creates a closed (or "periodic") curve with
# four distinct CVs. You must specify a knot vector when the
# "-per" flag is used. Notice that the first "degree" points
# are the same as the last "degree" points (ie. the first three
# points are the same as the last three points). Notice also
# that the knot spacing between the first "degree" knots must
# be the same as the spacing between the last "degree" knots
# (ie. the space between the 1st and 2nd knots is the same as
# the space between the 7th and 8th knots, and the space between
# the 2nd and 3rd knots is the same as the space between the
# 8th and 9th knots). There must be space between the first
# "degree" knots, unlike the previous example, where the first
# "degree" knots are the same.
pm.curve( per=True, p=[(0, 0, 0), (3, 5, 6), (5, 6, 7), (9, 9, 9), (0, 0, 0), (3, 5, 6), (5, 6, 7)], k=[-2,-1,0,1,2,3,4,5,6] )
# Result: nt.Transform(u'curve5') #

# How to query curve properties:

# This returns the degree of the curve.  Note that the
# number of CVs = degree + spans.
pm.getAttr( 'curve1.degree' )
# Result: 3 #

# This returns the number of spans in the curve.  Note that the
# number of CVs = degree + spans.
pm.getAttr( 'curve1.spans' )
# Result: 3 #

# This returns the curve form.
pm.getAttr( 'curve1.form' )
# Result: 0 #

# This returns the minimum parameter value on the curve.
pm.getAttr( 'curve1.minValue' )
# Result: 0.0 #

# This returns the maximum parameter value on the curve.
pm.getAttr( 'curve1.maxValue' )
# Result: 3.0 #

# This returns the local x,y,z of the 1st CV.  Use a curve info node if
# the curve is a result of a construction history operation.
pm.getAttr( 'curve1.cv[0]' )
# Result: dt.Vector([0.0, 0.0, 0.0]) #

# This returns the local x,y,z of the 1st three CVs.  Use a curve info
# node if the curve is a result of a construction history operation.
pm.getAttr( 'curve1.cv[*]' )
# Result: (0.0, 0.0, 0.0) #

# This returns the local x,y,z of all CVs.  Use a curve info node if
# the curve is a result of a construction history operation.
pm.getAttr( 'curve1.cv[0:2]' )
# Result: (0.0, 0.0, 0.0) #

# This returns the arc length of the curve.  Use "-ch" flag with
# the arclen command to get a curve info node that constantly updates
# to the current arc length.
pm.arclen( 'curve1' )
# Result: 27.33287667066844 #

# This sequence creates a curve info node, connects the info node to the
# curve and queries the knot vector of the curve using the curve info node.
# You can use the curve info node to query other attributes such as
# world space CV values and arc length.
pm.createNode( 'curveInfo' )
# Result: nt.CurveInfo(u'curveInfo1') #
pm.connectAttr( 'curveShape1.worldSpace', 'curveInfo1.inputCurve' )
pm.getAttr( 'curveInfo1.knots[*]' )