[英]Changing namespace separator from colon(:) to underscore (_) in Maya
I have imported a file "test_v001.mb" with the namespace "hello". 我导入了一个名为“hello”的文件“test_v001.mb”。 Is there a way where I can remove colon and replace it with underscore in the outliner? 有没有办法我可以删除冒号并用大纲中的下划线替换它?
import maya.cmds as cmds
test_file = "D:/test/test_v001.mb"
cmds.file(test_file, i=True, typ='mayaBinary', ra=True, mnc=False, op="v=0;", ns="hello", pr=True, lrd="all")
In the screenshot below I have done manually for the third one. 在下面的屏幕截图中,我已经手动完成了第三个。 I have to do this for a big file so trying to automate it. 我必须为一个大文件这样做,所以试图自动化它。
When I don't give any namespace in the file command then the column is replaced by underscore in the outliner which is exactly what I need like below. 当我没有在文件命令中给出任何命名空间时,该列被大纲中的下划线替换,这正是我在下面需要的。 But instead of the filename as a default prefix I want "hello" in the outliner. 但是,不是文件名作为默认前缀,我想在大纲中“hello”。 Is this easier to achieve? 这更容易实现吗?
Also if I give namespace as ":" then I don't even get any namespace and column. 此外,如果我将命名空间命名为“:”,那么我甚至没有获得任何命名空间和列。 So adding prefix is another option but that's only available in MEl. 因此添加前缀是另一种选择,但这仅在MEl中可用。
Maya uses :
as namespace and doesn't seem to be flexible about it. Maya使用:
作为命名空间和不似乎是灵活了。
The colon (':') character is the separator used to separate the names of namespaces and nodes instead of the slash ('/') or backslash ('\\') character. 冒号(':')字符是用于分隔命名空间和节点名称的分隔符,而不是斜杠('/')或反斜杠('\\')字符。
The code below might be helpful in replacing hello:
with hello_
: 下面的代码可能有助于替换hello:
with hello_
:
import pymel.core as pc
pc.namespace(set = ":") # just in case if there is any preset namespace
for obj in pc.ls(rn=False): # Referenced objects cannot be renamed
if "hello:" in obj:
pc.rename(obj, obj.replace(":", "_"))
Namespaces sure can be removed . 命名空间肯定可以删除 。
The renamingPrefix can be used while importing file to resolve nodes with prefixes instead of namespace. 导入文件时可以使用renamingPrefix来解析具有前缀而不是名称空间的节点。 In your case cmd.file(,,rpr = "hello",,,)
could be used. 在你的情况下cmd.file(,,rpr = "hello",,,)
可以使用cmd.file(,,rpr = "hello",,,)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.