This should be a pretty easy fix. In your constructor to the fileExporter
class, you accept 4 arguments, but you don't save any of them, so they are
lost:
#---------
class fileExporter():
def __init__(self, transform, startAnimation, endAnimation, cameraObj):
self.start = ""
self.end = ""
self.fileExport = []
self.exportWin()
#---------
But if you saved them, then your gui can still update some of them, and,
you will have saved the transform to reference later:
#---------
class fileExporter():
def __init__(self, transform, startAnimation, endAnimation, cameraObj):
self.transform = transform
self.start = startAnimation
self.end = endAnimation
self.cameraObj = cameraObj
self.fileExport = []
self.exportWin()
...
def test(self):
self.actualExp(self.transform, self.start, self.end, self.cameraObj)
#---------
Once you had fixed the transform, you would have seen the same error about
the cameraObj
On 21/10/2014 12:20 AM, "likage" <[email protected]> wrote:
> This may not be my best attempt but I would like to get some pointers if
> there are any.
> I tried to break up the exporting code, in hope that it may be easier, but
> I am getting errors in line 150 - *# NameError: global name 'transform'
> is not defined # *but if I am going to edit line 56 - *chanMe =
> fleExporter.actualExp(transform, minTime, maxTime, cameraObject)*, I will
> get this error -
> * // Error: line 0: unbound method actualExp() must be called with
> ChanFileExporter instance as first argument (got MFnTransform instance
> instead)*
>
> import math, sys, string, os
>
> import maya.OpenMaya as OpenMaya
> import maya.OpenMayaMPx as OpenMayaMPx
> import maya.OpenMayaAnim as OpenMayaAnim
>
> import maya.cmds as cmds
> import maya.mel as mel
>
> kPluginTranslatorTypeName = "chan Export/Import"
> kVersionNumber = "0.5a"
>
> class CustomNodeTranslator(OpenMayaMPx.MPxFileTranslator):
> def __init__(self):
> OpenMayaMPx.MPxFileTranslator.__init__(self)
> def haveWriteMethod(self):
> return True
> def haveReadMethod(self):
> return True
> def filter(self):
> return "*.chan"
> def defaultExtension(self):
> return "chan"
> def writer( self, fileObject, optionString, accessMode ):
> try:
>
> fullName = fileObject.fullName()
> fileHandle = open(fullName,"w")
>
> selectList = OpenMaya.MSelectionList()
>
> OpenMaya.MGlobal.getActiveSelectionList(selectList)
> node = OpenMaya.MObject()
> depFn = OpenMaya.MFnDependencyNode()
> path = OpenMaya.MDagPath()
> iterator = OpenMaya.MItSelectionList(selectList)
>
> animationTime = OpenMayaAnim.MAnimControl()
>
> maxTime = int(animationTime.maxTime().value())
> minTime = int(animationTime.minTime().value())
>
> while (iterator.isDone() == 0):
>
> iterator.getDependNode(node)
>
> depFn.setObject(node)
>
> iterator.getDagPath(path, node)
>
> cameraObject = OpenMaya.MFnCamera(path)
>
> transform = OpenMaya.MFnTransform(path)
>
> chanMe = fleExporter(transform, minTime, maxTime,
> cameraObject)
>
> for all in chanMe():
> fileHandle.write(all)
>
> iterator.next()
>
> fileHandle.close()
>
> except:
> sys.stderr.write( "Failed to write file information\n")
> raise
>
> def processLine( self, lineStr ):
>
> self.importTheChan.writeFrameData(lineStr)
>
>
> class fileExporter():
> def __init__(self, transform, startAnimation, endAnimation, cameraObj
> ):
> self.start = ""
> self.end = ""
> self.fileExport = []
> self.exportWin()
>
> def exportWin(self):
> print ">>> Running Exporting UI"
>
> self.expWindow = cmds.window(w=150, h=100, title = "Export
> Selection" )
> cmds.columnLayout( adjustableColumn=True )
> form = cmds.formLayout(numberOfDivisions=100)
> cmds.radioCollection()
> self.chk1 = cmds.radioButton( label='option1', onc = self.opt1On,
> ofc = self.opt1Off )
> self.chk2 = cmds.radioButton( label='option2', onc = self.opt2On,
> ofc = self.opt2Off )
> self.okayBtn = cmds.button(label='okay!', command=self.runSel,
> width=150, height=35)
>
> cmds.formLayout(form, edit=True, attachForm=[\
> (self.chk1, 'top', 15),\
> (self.chk1, 'left', 15),\
> (self.chk2, 'top', 30),\
> (self.chk2, 'left', 15),\
> (self.okayBtn, 'top', 50),\
> (self.okayBtn, 'left', 15)])
>
> cmds.showWindow( self.expWindow )
>
> def opt1On(self, *args):
> print "User checked option1"
> startAnimation = cmds.playbackOptions(query=True, minTime=True)
> endAnimation = cmds.playbackOptions(query=True, maxTime=True)
>
> self.start = startAnimation
> self.end = endAnimation
>
> def opt1Off(self, *args):
> print "User un-checked option1"
> cmds.radioButton(self.chk2, edit = True, enable = True)
> self.start = ""
> self.end = ""
>
> def opt2On(self, *args):
> print "User checked option2"
> startAnimation = cmds.findKeyframe(which='first')
> endAnimation = cmds.findKeyframe(which='last')
>
> self.start = startAnimation
> self.end = endAnimation
>
> def opt2Off(self, *args):
> print "User un-checked option2"
> self.start = ""
> self.end = ""
>
> def runSel(self, *args):
> chkVal1 = cmds.radioButton(self.chk1, query=True, sl=1)
> chkVal2 = cmds.radioButton(self.chk2, query=True, sl=1)
>
> if chkVal1 == 1:
> print "opt1 Pressed!"
> print self.start
> print self.end
> self.test()
>
> elif chkVal2 == 1:
> print "opt2 Pressed!"
> print self.start
> print self.end
> self.test()
>
> else:
> cmds.warning("Check an option")
>
>
> def test(self):
> # NameError: global name 'transform' is not defined #
> self.actualExp(transform, self.start, self.end, cameraObj)
>
>
> def actualExp(self, transform, startAnimation, endAnimation, cameraObj
> ):
> mayaGlobal = OpenMaya.MGlobal()
> mayaGlobal.viewFrame(OpenMaya.MTime(1))
>
> # Converts the float arguement into integer
> for i in range(int(startAnimation), int(endAnimation + 1)):
>
> focalLength = cameraObj.focalLength()
>
> vFilmApp = cameraObj.verticalFilmAperture()
>
> focalOut = 2* math.degrees(math.atan(vFilmApp * 25.4/ (2*
> focalLength)))
>
> myEuler = OpenMaya.MEulerRotation()
> spc = OpenMaya.MSpace.kWorld
>
> trans = transform.getTranslation(spc)
>
> rotation = transform.getRotation(myEuler)
> rotVector = OpenMaya.MVector(myEuler.asVector())
>
> self.fileExport.append((str(i) + '\t' + str(trans[0]) + "\t" +
> str(trans[1]) + "\t" + str(trans[2]) + "\t" + str(math.degrees(rotVector[0
> ])) + "\t" + str(math.degrees(rotVector[1])) + "\t" + str(math.degrees(
> rotVector[2])) + "\t" + str(focalOut) + "\n"))
>
> mayaGlobal.viewFrame(OpenMaya.MTime(i+1))
>
> def __call__(self):
> return self.fileExport
>
> def radianToDegree(self, radians):
> outDegrees = 0.0
> outDegrees = (float(radians) / (math.pi))*180
> return outDegrees
>
>
> # creator
> def translatorCreator():
> return OpenMayaMPx.asMPxPtr( CustomNodeTranslator() )
>
> # initialize the script plug-in
> def initializePlugin(mobject):
> mplugin = OpenMayaMPx.MFnPlugin(mobject)
>
> try:
> mplugin.registerFileTranslator(kPluginTranslatorTypeName, None,
> translatorCreator)
> except:
> sys.stderr.write( "Failed to register translator: %s" %
> kPluginTranslatorTypeName )
> raise
>
> # uninitialize the script plug-in
> def uninitializePlugin(mobject):
> mplugin = OpenMayaMPx.MFnPlugin(mobject)
> try:
> mplugin.deregisterFileTranslator( kPluginTranslatorTypeName )
> except:
> sys.stderr.write( "Failed to deregister translator: %s" %
> kPluginTranslatorTypeName )
> raise
>
>
>
> --
> 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/9c278912-ebec-427e-be9b-43741a99c7ef%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/9c278912-ebec-427e-be9b-43741a99c7ef%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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3cEs67A6kKwDGn_M1RB284VX3hq%2BqE9kCBASU4PqyPJA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.