【发布时间】:2015-07-13 18:01:27
【问题描述】:
我正在编写脚本以在不使用/打开命名空间编辑器的情况下删除命名空间(嵌套或非嵌套),假设在其中没有内容的情况下满足条件。
这样做时,我遇到了无法使用 cmds.namespace(rm="<string of the namespace>") 删除嵌套命名空间的问题
我找到了一个更长的解决方法,但我被卡住了,因为输出是列表中的 unicode,我似乎无法将其转换为字符串。
nsLs = cmds.namespaceInfo( lon=True)
# nsLs Result: [u'UI', u'camera01', u'shared', u'v02', u'v03']
defaultNs = ["UI", "shared", "camera01"]
diffLs = [item for item in nsLs if item not in defaultNs]
# diffLs Result: [u'v02', u'v03']
for ns in diffLs:
nsNest = cmds.namespaceInfo(ns, lon=True)
# nsNest Result: [u'v02:new_run01']
# [u'v03:new_run01']
cmds.namespace(rm=str(nsNest))
因此,我使用的“删除”标志不起作用,因为遇到以下错误:
# Error: No namespace matches name: '[u'v02:new_run01']'.
# Traceback (most recent call last):
# File "<maya console>", line 13, in <module>
# RuntimeError: No namespace matches name: '[u'v02:new_run01']'. #
我输入的上述代码仅适用于嵌套命名空间,虽然它仍然不是'那里'来实现结果并且也不是很灵活(假设场景中只有1个嵌套级别),有没有有什么办法解决这个问题?
此外,如果有人有任何解决方案/方法来删除命名空间而不使用命名空间编辑器,当然......
【问题讨论】:
标签: python namespaces maya