我在获取引用对象的名称(重命名)时遇到麻烦,使用Python将大量对象导入Maya:
import maya.cmds as cmds
import os
myFolder = r"D:\temp\objs"
objFiles = cmds.getFileList(folder = myFolder, filespec = "*.%s" % "OBJ")
for item in objFiles:
fname = os.path.join(myFolder, item)
x = cmds.file(fname, i = True)
结果是x是对象的路径名,而不是大纲视图中显示的对象名称。
重新命名的正确参考是什么?
答案 0 :(得分:2)
您发布的代码仅用于导入。您是否要查找在循环的每个步骤中导入的对象?
隔离导入对象的简单方法是在导入时指定名称空间。然后,您可以使用新的命名空间来快速发现对象:
for eachfile in list_of_files:
# make a namespace. In production you might want to double
# check to make sure the same namespace does not already exist
import_ns = os.path.splitex(os.path.basename(eachfile))[0]
cmds.file(eachfile, i=True, ns = import_ns)
# this gets all of the imported stuff:
imported_objects = cmds.ls (import_ns + ":*")
# now you can loop over it and rename as needed.
通过添加第二个带有类型标志的ls调用,您可以从imported_objects
中仅选择某些类的对象,即
imported_shapes = cmds.ls(imported_objects, type='shape')