【问题标题】:Name of object on import导入对象的名称
【发布时间】:2018-12-15 02:54:26
【问题描述】:

使用 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 是对象的路径名,而不是大纲中显示的对象名称。

为了重命名它的正确参考是什么?

【问题讨论】:

    标签: python import reference rename maya


    【解决方案1】:

    您发布的代码只是进行导入。您要查找在循环的每个步骤中导入的对象吗?

    隔离导入对象的简单方法是在导入时指定命名空间。然后,您可以使用新的命名空间来快速发现对象:

    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')
    

    【讨论】:

    • 最后一行不应该是imported_shapes = cmds.ls(imported_objects, type='shape') 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 2018-07-22
    • 2016-04-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多