PDA

View Full Version : create nurbsCurve node... ...in PYTHON??


backwheelbates
12-12-2012, 02:02 AM
Just trying to build a nurbsCurve shape node with python.

Heres the MEL that works

createNode transform -name "curve1";
createNode nurbsCurve -name "curveShape1" -parent "curve1";
setAttr -keyable off ".visibility";
setAttr ".cached" -type "nurbsCurve"
1 1 0 no 3
2 0 1
2
0 0 0
10 10 10
;


And heres the Python code, that DOESNT work:

cmds.createNode( 'transform', n='curve1')
cmds.createNode( 'nurbsCurve',n='curveShape1', p='curve1' )
cmds.setAttr('curveShape1.cached', type='nurbsCurve', [1, 1, 0, 'no', 3, 2, 0, 1, 2, (0, 0, 0), (10, 10, 10)])


Thanks for any ideas on how to get this to work!!

zoharl
12-12-2012, 08:13 AM
Why don't you use the curve command instead of meddling with maya inner structure?

backwheelbates
12-12-2012, 05:04 PM
Thanks zoharl!

Yeah, Ive come to that conclusion myself. I wanted to create several shape nodes that are parented under a single transform node.

The "createNode" command is great because it lets you specify a parent transform node, but after that its difficult to work with.

In the end, I just made all the nurbsCurves as separate objects, used "parent -r -s" to reparent the shape nodes under the transform, and then deleted the leftover transform nodes.

Not very elegant, but it worked.

Cheers!!

zoharl
12-12-2012, 06:30 PM
Sounds like the standard way to do it, and I'm not sure why you found it not elegant. If you were using the API, you could have specified a parent when creating the curve, but I'm not sure why it bothers you. Also you could start the same way you did:

cmds.createNode( 'transform', n='curve1')
cmds.createNode( 'nurbsCurve',n='curveShape1', p='curve1' )

then add CVs with 'curve -a'; but why bother?!

I would find it disturbing to mess with the inner structure, which could change in the next version for example.

backwheelbates
12-13-2012, 04:14 AM
Hey Zohari,

Actually I tried that approach, but every time I tried to append a cv, I kept getting an error message. I'll have to dig that up, and also I couldn't see a way to set the number of degrees (3 is default, I wanted 1).

For the tool I was putting together, I was procedurally creating a few hundred nurbsCurves that all get parented under a single transform. I'm not really married to doing it one way or another, just seemed like setting the ".cached" attribute directly might be a valid approach.

Anyways, the standard method works just fine, so Ill stick with that for now. I'm still curious how to get the ".cached" method to work, in spite of it not being totally necessary.

Thanks!!

Eric

zoharl
12-13-2012, 05:19 AM
1. I can't make the cache work. I tried:

cmds.setAttr('curveShape1.cached', 1, 1, 0, 0, 3, 2, [[0]], (0, 0, 0), (10, 10, 10), type='nurbsCurve')
# Error: setAttr: Error reading data element number 7: [[0]]

But no matter what I put at the seventh data element it fails. I would have been better motivated if I could retrieve the data using getAttr. Since it's not possible to do that through mel, I would have considered using the API through python OpenMaya:

http://ewertb.soundlinker.com/api/api.028.php

Also you could use mel.eval in python to setAttr through mel.

2. How about:

cmds.createNode( 'transform', n='curve1')
cmds.createNode( 'nurbsCurve',n='curveShape1', p='curve1' )
cmds.curve(d=1, p=[(0, 0, 0), (10, 10, 10)], k=[0,1])


and then use the 'curve -a' if you need to add more CVs.

backwheelbates
12-13-2012, 05:35 AM
Hey Zohari,

I thought that might work as well, but when I run those three lines of code, I get two separate objects.

The big problem is that trying to append cvs to the shape node (that was created using the createNode command) seems to error out:


cmds.createNode( 'transform', n='curve1')
curveShape = cmds.createNode( 'nurbsCurve',n='curveShape1', p='curve1' )
cmds.curve( curveShape, a=True, p=[(13, 13, 13), (13, 15, 16)] )

zoharl
12-13-2012, 06:13 AM
Sorry, my bad. And you are right, something shitty is going here. Before the -a could work, we need first to set the cache attribute through the standard degree, knots, span... somehow.

CGTalk Moderation
12-13-2012, 06:13 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.