@ Justin
The script is for creating an eyelid rig which tracks the movement of
an eyeball (based on Stop Staring 3rd Ed.).
I'm not a professional coder but I like to write tools for my own use.
I've been using Python for about a year (its my favorite language to
date). This is the first time I'm using classes in my coding, so its a
learning experience.  I try to write the most efficient code and use
best coding practices.
The problem I encountered was how use a list to create nodes and
assign them to vars for further processing.  I asked around on a
couple of forums for how to accomplish this.  The reason I thought of
using vars is they are easy to read in the code.
I've already learned that 'vars()/globals()' is not the way to go for
a few reasons.  Others have also suggested using a dictionary, which
is what I ended up doing.
Here are the solutions that have worked:
----------------------- CODE --------------------------------------
EyeRig.py
class lidRig(object):

    def __init__(self):
        print 'lidRig - For instructions, run
EyeRig.ildRig().useage()'
        self.lidControls = dict()

    def useage(self):
        print lidRigUseage,'\n',UDAttrRemove

    def create (self, lidRigPrefix, uprLidJoint, lwrLidJoint,
eyeParent, faceControl, lidControls2Make):
        # lidControls2Make vars are ['uprLid', 'lwrLid','lwrLidTrack',
'lidControls['uprLidTrack']','uprLidRef','lidRig']
        controlNode = 'loc'
        # For each item in the 'lidControls2Make' list, create a group
or locator and add it to the list of controllers
        for control in lidControls2Make:

            # Create group/locator.  Use dictionary to store reference
based on name of control:
            if controlNode == 'group':
                self.lidControls[control] = cmds.group(em = 1, n= '%s_
%s' % (lidRigPrefix, control))
            else:
                self.lidControls[control] = cmds.spaceLocator(n= '%s_
%s' % (lidRigPrefix, control))[0]
            print 'Control:  %s. Object: %s' %(control,
self.lidControls[control])

        # uprLid controller will be parented under lwrLid controller w/
max rotation set to prevent passing thru lower lid
        # Set the max XRot of the uprLid to 0:
        cmds.transformLimits(self.lidControls['uprLid'],rx=(-45,
0),erx=(0, 1))# Need to set both limits, but erx unsets the min (first
value)

        # Setup Hierarchy of controllers
        cmds.parent
(self.lidControls['uprLid'],self.lidControls['lwrLid'])
        cmds.parent
(self.lidControls['lwrLid'],self.lidControls['lwrLidTrack'])
        ...
------------------------ END
-------------------------------------------

What I like about Chris' approach is that referencing the var is a bit
easier to write than the dictionary:
----------------------- CODE -------
for control in lidControls2Make:
        self.lidControls[control] = cmds.group(em = 1, n= '%s_%s' %
(lidRigPrefix, control))

# Setup Hierarchy of controllers
cmds.parent (lidRig.uprLid,lidRig.lwrLid)
cmds.parent (lidRig.lwrLid,lidRig.lwrLidTrack)
...
----------------------- END -------

I see in your suggestion that the dictionary can be created inside
'create()' and it won't require using 'self.' each time it's
referenced.
For readability, I found that I could assign the vars from the
dictionary and the vars would then be local to 'create()', (I realize
that is not totally necessary):
----------------------- CODE -------
...
lidControls = {}
for control in lidControls2Make:
        lidControls[control] = cmds.group(em = 1, n= '%s_%s' %
(lidRigPrefix, control))

# Create vars to make code easier to read:
uprLid = lidControls['uprLid']
lwrLid = lidControls['lwrLid']

# Setup Hierarchy of controllers
cmds.parent (uprLid,lwrLid)
cmds.parent (lwrLid,lwrLidTrack)
...
----------------------- END -------
Any further suggestions or insights are welcome.
Thanks.

-- 
view archives: http://groups.google.com/group/python_inside_maya
change your subscription settings: 
http://groups.google.com/group/python_inside_maya/subscribe

Reply via email to