gpt4 book ai didi

python - API导出问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:07:27 25 4
gpt4 key购买 nike

我需要有人提供有关我的导出问题的专业知识。

工作原理:选择一个摄像机(是否有动画可选)>>文件>>导出选择>>文件类型:.chan(需要将此脚本作为插件加载)

这就是问题开始的地方。它能够创建一个 .text 文件,但是,它不会“导出”或将内容写入文本文件,并且文件大小为零字节。

我正在利用当前已编码的 API,修改代码以添加一些 Maya cmd

有人可以帮我吗?

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 = []
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 ):
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 processLine( self, lineStr ):

self.importTheChan.writeFrameData(lineStr)


class fileExporter():
""" module for exporting chan files from application. arguments: object, startFrame, endFrame """

def __init__(self, transform, startAnimation, endAnimation, cameraObj):
self.fileExport = []
self.transform = transform
self.cameraObj = cameraObj
self.start = startAnimation
self.end = endAnimation
self.exportWin()

def exportWin(self):
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

#self.start.append(int(startAnimation))
#self.end.append(int(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()
self.closeWindow()

elif chkVal2 == 1:
print "opt2 Pressed!"
print self.start
print self.end
self.test()
self.closeWindow()

else:
cmds.warning("Check an option")

def closeWindow(self):
cmds.deleteUI(self.expWindow, window=True)

def test(self):
self.actualExp(self.transform, self.start, self.end, self.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, args):
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

最佳答案

__call__ 方法应该提供文件的内容。它返回 self.fileExport,这是一个未填充的空列表。

关于python - API导出问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26585667/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com