Hi,
I come from a MEL background, and currently exploring the Python OOP world.
I'm trying to wrap my head around classes.
This seems like a very simple issue to resolve, but I can't seem to get the
proper syntax to work. As an example, I want to create a module with two
classes. I want the second class (Spring) to grab the variable information
from the first one (Connector) and use it to build a new set of locators
with additional functionality to be attached to them. I've tried a bunch of
syntax combinations, but can't seem to get the handle on it. The current
Spring class is mangled, and any help would be greatly appreciated.
At the moment, it creates two sets of locators and curves, and gives the
following error:
# Error: SetLoc() takes exactly 1 argument (2 given)
# Traceback (most recent call last):
# File "<maya console>", line 4, in <module>
# File
"C:/Users/.../Documents/maya/2014-x64/prefs/scripts\tgpMechanix.py", line
53, in __init__
# self.SetSpring(locs)
# File
"C:/Users/.../Documents/maya/2014-x64/prefs/scripts\tgpMechanix.py", line
59, in SetSpring
# self.basePos=mc.move(0,25,0, locs(self.baseLoc))
# TypeError: SetLoc() takes exactly 1 argument (2 given) #
Here's the current code:
import maya.cmds as mc
class Connector(object):
'''
This class will create a curve connector between two locators
'''
#initialize the class
def __init__(self):
self.SetLoc()
def SetLoc(self):
print "testing connector class"
#create locators
self.baseLoc=mc.spaceLocator(name="baseLoc", p=(0,0,0))[0]
self.topLoc=mc.spaceLocator(name="topLoc", p=(0,0,0))[0]
#create the connecting curve
self.conCurve=mc.curve(name="conCurve", d=1, p=[(0,0,0),(0,0,0)])
mc.setAttr(self.conCurve+".template",1) #template the curve
#create distanceNode
self.dNode=mc.createNode("distanceBetween")
#position the locators
self.basePos=mc.move(0,0,0, self.baseLoc)
self.topPos=mc.move(0,10,0,self.topLoc)
#connect the curve between the locators
mc.connectAttr(self.baseLoc+".t",self.conCurve+".cv[0]", force=True)
mc.connectAttr(self.topLoc+".t",self.conCurve+".cv[1]",force=True)
#attach the distanceNode between the locators
mc.connectAttr(self.topLoc+".worldMatrix[0]",self.dNode+".inMatrix1",force=True)
mc.connectAttr(self.baseLoc+".worldMatrix[0]",self.dNode+".inMatrix2",force=True)
#create new class to build spring using the locators from the Connector
class
class Spring(Connector):
def __init__(self, *args):
super(Spring,self).__init__(*args)
locs=Connector().SetLoc
self.SetSpring(locs)
def SetSpring(self,locs):
print "testing Spring class"
#position the locators
self.basePos=mc.move(0,25,0, locs(self.baseLoc))
self.topPos=mc.move(0,40,0,locs(self.topLoc))
--
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/88ccabda-2fff-4df6-a1bb-f538bb248b8d%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.