60 from builtins
import next
62 import maya.OpenMaya
as OpenMaya
63 import maya.OpenMayaUI
as OpenMayaUI
64 import maya.OpenMayaMPx
as OpenMayaMPx
67 contextCmdName =
"spMoveManipCtxCmd"
68 nodeName =
"spMoveManip"
70 class moveManip(OpenMayaMPx.MPxManipContainer):
75 OpenMayaMPx.MPxManipContainer.__init__(self)
77 def createChildren(self):
78 self.fDistanceManip = self.addDistanceManip(
"distanceManip",
"distance")
82 distanceManipFn.setStartPoint(startPoint)
83 distanceManipFn.setDirection(direction)
84 self.fFreePointManip = self.addFreePointTriadManip(
"pointManip",
"freePoint")
86 def connectToDependNode(self, node):
90 syPlug = nodeFn.findPlug(
"scaleY")
91 tPlug = nodeFn.findPlug(
"translate")
93 distanceManipFn.connectToDistancePlug(syPlug)
95 freePointManipFn.connectToPointPlug(tPlug)
96 OpenMayaMPx.MPxManipContainer.finishAddingManips(self)
97 OpenMayaMPx.MPxManipContainer.connectToDependNode(self,node)
99 sys.stderr.write(
"Error finding and connecting plugs\n" )
102 def moveManipCreator():
103 return OpenMayaMPx.asMPxPtr( moveManip() )
105 def moveManipInitialize():
106 OpenMayaMPx.MPxManipContainer.initialize()
108 class moveManipContext(OpenMayaMPx.MPxSelectionContext):
110 OpenMayaMPx.MPxSelectionContext.__init__(self)
111 self.updateManipulatorsCallbackID =
None
113 def toolOnSetup(self,event):
114 updateManipulators(self)
117 def toolOffCleanup(self):
118 self.deleteManipulators()
120 if self.updateManipulatorsCallbackID !=
None:
123 sys.stderr.write(
"Cleanup called before setup.\n" )
124 super(moveManipContext, self).toolOffCleanup()
126 def updateManipulators(clientData):
127 clientData.deleteManipulators()
132 while not selectionIter.isDone():
134 selectionIter.getDependNode(dependNode)
135 if dependNode.isNull()
or not dependNode.hasFn(OpenMaya.MFn.kDependencyNode):
136 print(
"depend node is null")
140 rPlug = dependNodeFn.findPlug(
"translate",
False)
141 sPlug = dependNodeFn.findPlug(
"scaleY",
False)
142 if rPlug.isNull()
or sPlug.isNull():
143 print(
"translate and/or scale plugs are null")
148 manipulator = OpenMayaMPx.MPxManipContainer.newManipulator(nodeName, manipObject)
149 if manipulator
is not None:
150 clientData.addManipulator(manipObject)
151 manipulator.connectToDependNode(dependNode)
154 class moveManipCtxCmd(OpenMayaMPx.MPxContextCommand):
156 OpenMayaMPx.MPxContextCommand.__init__(self)
159 return OpenMayaMPx.asMPxPtr( moveManipContext() )
162 def contextCmdCreator():
163 return OpenMayaMPx.asMPxPtr( moveManipCtxCmd() )
167 def initializePlugin(mobject):
168 mplugin = OpenMayaMPx.MFnPlugin(mobject)
171 mplugin.registerContextCommand( contextCmdName, contextCmdCreator )
173 print(
"Failed to register context command: %s" % contextCmdName)
177 mplugin.registerNode(nodeName, moveManipId, moveManipCreator, moveManipInitialize, OpenMayaMPx.MPxNode.kManipContainer)
179 print(
"Failed to register node: %s" % nodeName)
183 def uninitializePlugin(mobject):
184 mplugin = OpenMayaMPx.MFnPlugin(mobject)
186 mplugin.deregisterContextCommand(contextCmdName)
188 print(
"Failed to deregister context command: %s" % contextCmdName)
192 mplugin.deregisterNode(moveManipId)
194 print(
"Failed to deregister node: %s" % nodeName)