I did have a clue that variable length items might be passed as lists, or at
least I hoped they might.
The clue for me that got me going was in his error:

# RuntimeError: Error reading data element number 7: 0

That told me that some of the data elements were reading without errors
based on the nurbsCurve type.
I tried any reference I could think of, but the one that wins in the end is
the good old node description for nurbsCurve, I just didn't know it as it
stared me in the face.

But I tried passing both the knots and the cvs as lists, lists of tuples....

The funky part started in when I started getting the next dataType correct,
and then it would skip a data element and complain about the following one.
I still didn't clue in for some time.  At one point I thought the cv list of
tuples might not be defined by the number preceding, as I would add another
tuple and it seemed to ask for more.  So I doubled up the list of cvs with a
copy paste and it went through.  After that I noticed that the cvs that were
created were every other one, and then I looked back at the description in
the node docs to try and understand it.

It is good to remember that Python can't just drop arguments it doesn't need
at the moment the way MEL can.  The Python version of this dataType must
account for the full description of the dataType (the un-needed W values in
this instance) so Python will parse the arg list correctly.  It can properly
ignore those elements it doesn't use, but it needs everything it needs in
its expected place in the arg list.

- JohnCreson



On Fri, May 15, 2009 at 8:25 PM, Paul Molodowitch <elron...@gmail.com>wrote:

>
> Awesome, thanks!
>
> Out of curiosity - how did you figure that out? Is there some
> reference I'm unaware of? Or some awesome python introspection
> ability? Or just some good intuition? (In retrospect, it makes sense
> to have the variable-length items passed as lists...)
>
> - Paul
>
> On Fri, May 15, 2009 at 3:15 PM, John Creson <johncre...@gmail.com> wrote:
> > ###########################
> > import maya.cmds as cmds
> > cmds.createNode('nurbsCurve',n="myNurbsCurveShape")
> > cmds.setAttr('myNurbsCurveShape.cc',3,1,0,
> >        False,3,
> >        (0,0,0,1,1,1),6,
> >     4,(-2,3,0),(),(2,1,0),(),(2,-3,0),(),(-2,-1,0),(),
> >         type='nurbsCurve')
> >
> >
> > #############################
> >
> > In the above example the 6 could also be () and the curve still seems to
> > build as expected.
> > I think the list knows how long it is...
> > I think the () after every CV may be a place holder for possible W values
> > when making rational curves.
> > (CV positions in x,y,z (and w if rational) )
> >
> > On Wed, May 13, 2009 at 1:59 PM, barnabas79 <elron...@gmail.com> wrote:
> >>
> >> Hey - I was wondering if anyone here has tried to set a 'nurbsCurve'
> >> attribute using setAttr (or, really, any of the shape attribute types
> >> - I assume the syntax will be similar between them).
> >>
> >> Ie, the docs have this example for mel:
> >>
> >> createNode nurbsCurve -n "myNurbsCurveShape";
> >> setAttr myNurbsCurveShape.cc -type nurbsCurve 3 1 0 no 3
> >> 6 0 0 0 1 1 1
> >> 4 -2 3 0 -2 1 0 -2 -1 0 -2 -3 0;
> >>
> >> I would think that the python conversion would be:
> >>
> >> import maya.cmds as cmds
> >> cmds.createNode('nurbsCurve',n="myNurbsCurveShape")
> >> cmds.setAttr('myNurbsCurveShape.cc',3,1,0,
> >>        False,
> >>        3,6,0,0,0,1,1,
> >>        1,4,-2,3,0,-2,1,0,-2,-1,0,-2,-3,0,
> >>        type='nurbsCurve')
> >>
> >> but this results in:
> >>
> >> # RuntimeError: Error reading data element number 7: 0
> >>
> >> These don't work either:
> >>
> >> import maya.cmds as cmds
> >> cmds.createNode('nurbsCurve',n="myNurbsCurveShape")
> >> cmds.setAttr('myNurbsCurveShape.cc', """3 1 0 no 3
> >> 6 0 0 0 1 1 1
> >> 4 -2 3 0 -2 1 0 -2 -1 0 -2 -3 0""",
> >>        type='nurbsCurve')
> >>
> >>
> >> import maya.cmds as cmds
> >> cmds.createNode('nurbsCurve',n="myNurbsCurveShape")
> >> cmds.setAttr('myNurbsCurveShape.cc', (3,1,0,
> >>        False,
> >>        3,6,0,0,0,1,1,
> >>        1,4,-2,3,0,-2,1,0,-2,-1,0,-2,-3,0),
> >>        type='nurbsCurve')
> >>
> >>
> >> import maya.cmds as cmds
> >> cmds.createNode('nurbsCurve',n="myNurbsCurveShape")
> >> cmds.setAttr('myNurbsCurveShape.cc', [3,1,0,
> >>        False,
> >>        3,6,0,0,0,1,1,
> >>        1,4,-2,3,0,-2,1,0,-2,-1,0,-2,-3,0],
> >>        type='nurbsCurve')
> >>
> >> ...any ideas on how to get this to work in python?
> >>
> >
> >
> > >
> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to