Okay, I think I have switched it to the use of checkboxes, as it seems
slightly easier for me?
Pardon my lack of understanding, but I was wondering if you could further
elaborate second previous post -
* move your logic that is in your __init__ into another method. Your writer
plugin can then create an instance of the FileExplorer, and have it show
the UI. Then it can take the values from the UI and call another method
that actually does the work. Your constructor shouldn't be doing all the
work.*Apparently in my current code, the file gets exported before my UI*, *way
before I can choose between the options/functions I have set it in my
checkBox (and the okayBtn)
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"
camSel = []
start = []
end = []
win_name = "chan_window"
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 ):
self.exportWin()
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 = fileExporter(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 test1On(self, *args):
print "User checked option1"
cmds.checkBox(self.chk2, edit = True, enable = False)
startAnimation = cmds.playbackOptions(query=True, minTime=True)
endAnimation = cmds.playbackOptions(query=True, maxTime=True)
start.append(startAnimation)
end.append(endAnimation)
def test1Off(self, *args):
print "User un-checked option1"
cmds.checkBox(self.chk2, edit = True, enable = True)
del start[:]
del end[:]
def test2On(self, *args):
print "User checked option2"
cmds.checkBox(self.chk1, edit = True, enable = False)
startAnimation = cmds.findKeyframe(which='first')
endAnimation = cmds.findKeyframe(which='last')
start.append(startAnimation)
end.append(endAnimation)
def test2Off(self, *args):
print "User un-checked option2"
cmds.checkBox(self.chk1, edit = True, enable = True)
del start[:]
del end[:]
def test3(self, *args):
chkVal1 = cmds.checkBox(self.chk1, query=True, value=True)
chkVal2 = cmds.checkBox(self.chk2, query=True, value=True)
if chkVal1 == 1:
print "opt1 Pressed!"
print start
print end
elif chkVal2 == 1:
print "opt2 Pressed!"
print start
print end
else:
cmds.warning("Check an option")
def exportWin(self):
w = cmds.window(w=150, h=100, title = "Export Selection" )
cmds.columnLayout( adjustableColumn=True )
form = cmds.formLayout(numberOfDivisions=100)
self.chk1 = cmds.checkBox( label='option1', onc = self.test1On, ofc
= self.test1Off )
self.chk2 = cmds.checkBox( label='option2', onc = self.test2On, ofc
= self.test2Off )
self.okayBtn = cmds.button(label='okay!', command=self.test3, 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( w )
def processLine( self, lineStr ):
self.importTheChan.writeFrameData(lineStr)
def reader(self, fileObject, optionString, accessMode):
self.initialWindow()
try:
# Empty out any existing captured info in camSel list to have a
clean import
camSelClear = camSel
del camSelClear[:]
fullPath = fileObject.fullName()
self.fileHandle = open(fullPath,"r")
camHandle = self.fileHandle
camBaseName = os.path.basename(camHandle.name)
camName = os.path.splitext(camBaseName)[0]
# Imported camera will not have any animation unless Rotation
Order is selected
cameraName, cameraShape = cmds.camera(n=str(camName))
camSel.extend((cameraName, cameraShape))
cmds.scale(0.5, 0.5, 0.5)
except:
sys.stderr.write( "Failed to read file information\n")
raise
self.fileObject = fileObject
self.optionString = optionString
self.accessMode = accessMode
class fileExporter():
""" module for exporting chan files from application. arguments:
object, startFrame, endFrame """
def __init__(self, transform, startAnimation, endAnimation, cameraObj):
print ">>> Exporting..."
self.fileExport = []
mayaGlobal = OpenMaya.MGlobal()
mayaGlobal.viewFrame(OpenMaya.MTime(1))
# Capture the animation keyframes within the selection instead of
the range from time slider
#startAnimation = cmds.findKeyframe(which='first')
#endAnimation = cmds.findKeyframe(which='last')
# 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/7393136e-bd81-4d61-825c-043626ac060d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.