导入对象的名称
Name of object on import
使用 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 是对象的路径名,而不是大纲中显示的对象名称。
重命名的正确参考是什么?
您发布的代码只是进行导入。您要查找在循环的每个步骤中导入的对象吗?
隔离导入对象的简单方法是在导入时指定命名空间。然后您可以使用新的命名空间来快速发现对象:
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.
您可以从 imported_objects
中仅选择一些 类 对象,方法是使用类型标志添加对 ls 的第二次调用,即
imported_shapes = cmds.ls(imported_objects, type='shape')
使用 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 是对象的路径名,而不是大纲中显示的对象名称。
重命名的正确参考是什么?
您发布的代码只是进行导入。您要查找在循环的每个步骤中导入的对象吗?
隔离导入对象的简单方法是在导入时指定命名空间。然后您可以使用新的命名空间来快速发现对象:
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.
您可以从 imported_objects
中仅选择一些 类 对象,方法是使用类型标志添加对 ls 的第二次调用,即
imported_shapes = cmds.ls(imported_objects, type='shape')