简体   繁体   中英

Changing namespace separator from colon(:) to underscore (_) in Maya

I have imported a file "test_v001.mb" with the namespace "hello". 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. 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.

Maya uses : as namespace and doesn't seem to be flexible about it.

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_ :

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. In your case cmd.file(,,rpr = "hello",,,) could be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM