On Sat, Jun 9, 2018 at 5:38 PM Adynsky <adien.den...@gmail.com> wrote:

> Hi guys,
>
> I'm new and starting learning python. I'm trying my self to create anim
> control using the curve and here I'm stuck to get item of function :
>
> def groupParent(groups, prefix, suffix):
>>
>>     grps = []
>>
>>     for i in range(len(groups)):
>>
>>         grps.append(mc.createNode('transform', n="%s%s%s_%s" % (prefix,
>>> suffix, groups[i], GROUP)))
>>
>>         if i > 0:
>>
>>             mc.parent(grps[i], grps[i - 1])
>>
>>
>
>> def matchPosition(objectOri, object):
>>
>>     mc.delete(mc.parentConstraint(objectOri, object, mo=False))
>>
>>
>
>> def createControl(suffix='ctrl',
>>
>>                   groups=['zro'],
>>
>>                   gimbal=None,
>>
>>                   gimbalSize=0.5,
>>
>>                   shape=SQUARE,
>>
>>                   connect=[]):
>>
>>     for obj in mc.ls(sl=1):
>>
>>         ctrl    = controller(shape)
>>
>>         renCtrl = mc.rename(ctrl, prefixName(obj))
>>
>>         grpPrnt = groupParent(groups, renCtrl, suffix.title())
>>
>>         mc.parent(renCtrl, grpPrnt)
>>
>>         finName = mc.rename(renCtrl, '%s_%s' % (prefixName(obj), suffix))
>>
>>
>>>         doMatch = matchPosition(obj, grpPrnt)
>>
>>
> I run it and have the error "Target list was empty or contained no valid
> targets." So, how do I do to get item the list on grps[0] in function
> groupParent and then assigned to grpPrnt variable?! Thanks in advance!
>


Hi. You are missing a return statement in your groupParent function. So you
end up having grpPrnt=None

def groupParent(groups, prefix, suffix):
    grps = []
    for i in range(len(groups)):
        grps.append(mc.createNode('transform', n="%s%s%s_%s" %
(prefix, suffix, groups[i], GROUP)))
        if i > 0:
            mc.parent(grps[i], grps[i - 1])
    return grps

​

Also, in the createControl function, be careful when passing default list
values for the function arguments. The groups param is currently being used
as read-only and the connect isn't being used. But if you ended up using
them to append, you might find surprising results when the default list
keeps growing on every call. Its better to use a lit:

def foo(myList=None):
    if myList is None:
        myList = ['default']

​


>
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/4129465e-02e4-4ef6-94fe-8abf14c225c6%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/4129465e-02e4-4ef6-94fe-8abf14c225c6%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1k5CRuC%2B4g9Y2uf3kfsNjqrVZVbgCYBL9ZNu30sos3UQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to