[Maya-Python] Python API method of setAttr -type "nurbsCurve"

31 views
Skip to first unread message

Marcus Ottosson

unread,
Jul 13, 2018, 5:01:57 AM7/13/18
to python_in...@googlegroups.com

Hi all,

I’m trying to achieve this..

createNode transform -n "myCurve";
createNode nurbsCurve -n "myCurveShape" -p "myCurve";
setAttr "myCurveShape.cached" -type "nurbsCurve" 
    3 2 no no 3
    7 -2 -1 0 1 2 3 4
    5
    1.0 0.0 0.0
    1.0 0.0 1.0
    0.0 0.0 1.0
    -1.0 0.0 1.0
    -1.0 0.0 -1.0
    ;

..using API (any version, Maya 2015+)..

from maya.api import OpenMaya as om

mfn = om.MFnDagNode()
parent = mfn.create("transform", "myCurve")
shape = mfn.create("nurbsCurve", "myCurveShape", parent=parent)
attr = mfn.findPlug("cached", False)
attr.set...(?)

Does anyone know how to set this attribute?

Best,
Marcus

Serguei Kalentchouk

unread,
Jul 13, 2018, 10:19:16 AM7/13/18
to python_in...@googlegroups.com
Hi Marcus,

It would be something like this (pseudo code):

data = MFnNurbsSurfaceData()
obj = data.create()
surffn = MFnNurbsSurface(obj)
surffn.create(...)
plug.set(obj)



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOD_%2Bw7CEsc%2B2R7KQ%3D4%3D3Qt%2BzhyXiPo_atgDwqTCHa-HxA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Jul 13, 2018, 10:42:26 AM7/13/18
to python_in...@googlegroups.com

Genius!

from maya import OpenMaya as om1

def setNurbsCurve(shape, points, degree=1, form=om1.MFnNurbsCurve.kOpen):
    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()
    data = om1.MFnNurbsCurveData()
    mobj = data.create()

    for point in points:
        cvs.append(om1.MPoint(*point))

    curveFn.createWithEditPoints(cvs,
                                 degree,
                                 form,
                                 False,
                                 False,
                                 True,
                                 mobj)

    shapeFn = om1.MFnDagNode(shape)
    plug = shapeFn.findPlug("cached")
    plug.setMObject(mobj)

mfn = om1.MFnDagNode()
parent = mfn.create("transform")
shape = mfn.create("nurbsCurve", "shape", parent)
setNurbsCurve(shape, points=((0, 0, 0), (0, 1, 0), (0, 2, 0)))

Now it makes sense what those *Data members are for; previously, I’ve passed a transform as argument for parent for the createWithEditPoints command, which would create a new curve and automatically parent it to that transform. But one of the issues I was having was that I wasn’t able to give that shape a name. But with this approach, it makes sense as that function probably isn’t designed to actually both create the geometry and the node, in which case I can create the node elsewhere and set the attribute like this.

Thanks Serguei!


To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAPCVZ5O%2BuC3L%3D7N84U_nSy92P5qUE1%3DBB__ptvp9ZyzdAfj75A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages