我需要从一个文件夹中将一组.obj文件导入到maya场景中,该文件夹还包含一个.csv文件及其名称,位置,wxyzrotation和scale。每行都匹配一个对象。
CSV样本行:
humanwings01.obj;-1.74366;9.68615;-0.017424690;0.9396926;0.0000;0.0000;-0.342020100;0.43248
我的问题是对象没有移动或缩放到位。 (尚未编写轮换脚本) 我认为出现问题是因为直到循环结束后才在场景中创建对象,但这只是一个猜测。
到目前为止,python脚本看起来像这样:
import maya.cmds as cmds
#CSV path: D:/environment/human/
#CSV format: ModelFile;PositionX;PositionY;PositionZ;RotationW;RotationX;RotationY;RotationZ;ScaleFactor
pathOfFiles = "D:/environment/human/" #folder with all the files
fh = open("D:/environment/human/objectdata.csv", "r") #open the csv file with all the data and save it
content = fh.readlines()[1:] #save all the lines of the file except the first one which contains the format for the csv
fh.close()
for line in content: #for every line
l = line.strip() #remove whispace at start and end
values = l.split(";") #save the values that were separated by ;
importedObj = cmds.file(pathOfFiles + values[0], i=True) #import each file by reading the first value of each line and save the name
cmds.move( values[1], values[2], values[3], importedObj, a=True ) #move the object that was just imported by reading the values from the csv
cmds.scale( float(values[8]), float(values[8]), float(values[8]), importedObj, a=True ) #scale the object that was just imported by reading the values from the csv.
答案 0 :(得分:1)
使用OpenMaya 2.0中的类(Student ID, Age, Gender, Family Income, Dropped Out
1, 15, M, 10000, Y
2, 16, F, 20000, N
3, 14, M, 13000, Y
..
10000, 15, M, 30000, N
,只要您使用的是Maya 2016+),看起来会变得容易一些。
maya.api.OpenMaya