On Sat, Sep 30, 2017, 8:22 AM X Y <[email protected]> wrote:

> A question here, quickly, on storing 'the return value' of a for loop:
> let's say that in my case, if I run a for loop on a collection of objects
> how would I go about storing all the curves generated in a list for future
> access - what is the proper way of doing that?
>

If you follow Andres' suggestion of saving the return value from your Maya
commands, then it should be easy to append them to a list:

curves = []
for ... :
    a = mc.polyToCurve(form=0, degree=3)
    curves.append(a)

Now you will have a curves list that contains lists of [transform, shape]
Note that if you call rename() on the curves as you do in your example, you
should be storing the result of the rename and not the original curve.


> On Tuesday, September 26, 2017 at 10:08:02 PM UTC+3, Andres Weber wrote:
>>
>> Something that will help you immensely is not to rely on Maya's current
>> selection and the fact having your code only work with the current
>> selection.  That kind of information gets very hard to rely on as code gets
>> more complicated.  So what you need to do is actually store the return
>> value from these Maya functions you're running into variables.  You can
>> either read the help documentation entries for the commands you're running
>> and check what the return value is or if you want a more exploratory option
>> just store every function's return value in a variable.
>>
>> For example if you have a cube's edges selected and you run:
>>
>> a = mc.polyToCurve(form=0, degree=3)
>>
>> and then print a, you get the transform and the shape node that were
>> created in a list.  For example my result was:
>> [# Result: [u'polyToCurve1', u'polyEdgeToCurve1']
>>
>> With that knowledge you can actually now create the wire deformer from
>> the curve that was generated and run it on the selected object within the
>> same for loop.  The quicker you stop relying on Maya's selection and start
>> storing the results of functions to use later, the better your code will
>> get very quickly!
>>
>> On Monday, September 25, 2017 at 1:45:56 PM UTC-4, X Y wrote:
>>>
>>> Hey, hey!
>>>
>>> I'm having trouble with a little python script so maybe someone can help
>>> me get a grip with it.
>>>
>>> This is what I have so far:
>>>
>>> import maya.cmds as mc
>>>
>>> selection = mc.ls(orderedSelection=True)
>>>
>>> mc.select (cl=True)
>>>
>>> for i in selection:
>>>  Name = str(i)
>>>  print 'Object is: ' +Name
>>>  mc.select(i+'.e[124]', add=True)
>>>  mc.polySelectConstraint(propagate=4, m3a=20)
>>>  mc.polyExtrudeEdge(ch=0, ltz=-0.005)
>>>  mc.polyToCurve(form=0, degree=3)
>>>  mc.rename (Name)
>>>
>>> Now I would like for the second part of my script to take the generated
>>> curves and *match *each of them to the mesh they were generated from
>>> and create a wire deformer with the generated curve as a driver, and the
>>> respective mesh as driven. It's just that I don't know how I should
>>> approach *list / name matching* these two selections.
>>>
>>> Hopefully I'll hear from someone.
>>>
>>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA22ykfLioFgSWkOHz9A6J0cVe9mGjPNo8%2BQ7B_9NBS9Zg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to