home     gallery   photography   contact   cv   videos  

How to – Maya – remove namespace after import tutorial

Ever find it annoying when you’re using Maya, you import some objects and it adds the name of the file you’re importing to the name of every object? The names of the objects in your scene can very quickly get a bit unwieldy if you’re working with lots of files. Use the following to clean things up a bit –

After your objects are imported paste the following line into the script editor –

namespace -mv "insert_namespace_here" ":" -force;

Replace insert_namespace_here with the namespace of your imported objects. ie for an object that is named part1:Cylinder02 use the following –

namespace -mv "part1" ":" -force;

Next you need to execute the MEL code and all objects with that namespace will have it removed. So part1:Cylinder02 will become Cylinder02.

[Hint – In order to keep the MEL in your script editor for another time, instead of it disappearing once the code is executed. Highlight the code and hit enter on the enter key beside the number keys on you keyboard.]

Share
Tags: , , , , , , , ,

21 Responses to “How to – Maya – remove namespace after import tutorial”

  1. Dikshant Says:

    Instead of removing namespaces you can go to import settings and disable use namespaces and resolve clashing nodes.
    This way seems to be better than again and again removing namespaces.

  2. Stephen Says:

    True, you can do this. But if you have multiple people working on a file, each with different import settings, this method can be very helpful.

  3. Stitched Says:

    I tried to use this method because I am having a problem with namespaces and working with References.

    I remove the reference but I get errors about nodes being locked, etc. When I replace the character (after removing the reference), it numbers the namespace “_002”. When I try to rename it in the reference loader, it says that “_001” already exists(!?!?!)

    So frustrating!

  4. Farfetch'd Says:

    @Stitched
    Yeah I get the same error when working with references… it keeps on raising the numbers after the namespace even after I removed the previous ones! I dunno how to resolve it. Does anyone know?

  5. Helper Says:

    @Farfetch’d & Stitched
    after running the above command or another namespace cleaner run
    namespace -rm “insert_namespace_here”
    That should remove the problematic database string that is holding onto namespace info causing it to increment in number. Also no “:” after the namespace name

  6. JO Says:

    Hi everyone many thanks for the tips, I have a little question for maya 2011 I got //Error: Syntax error// and I try many different scripts please help Thanks every one

  7. Jerome Says:

    You have to replace “ ” with the ” ” on your keyboard. Was stumped for awhile too. Have fun!

  8. Steve Says:

    Thank you. Namespaces were driving me batty!!!!!!!

  9. Ian Says:

    Thank you Jerome. It would be nice if the OP updated the article instead of leaving that hanging in the comments, but still it fixed the problem for me. (mac OSX user FWIW.)

  10. Stephen Says:

    Thanks for pointing this out. I’ve updated. WordPress was, annoyingly, changing the character on publishing the post.

  11. Harry_Gee Says:

    Hey I’ve been trying to figure all this out. Searched a couple websites. And the way i discovered on my own trying to add layers is adding your own naming convention “leg” which will then get entered as “asdas:Leg”

    If you just bring you curser to the front of the “:” sign you and backspace what maya inputs for you and hit enter. your outcome will be “leg”

    Quick and easy

  12. PMel Says:

    I tried all the suggestions above and it frustrated me that none of it worked.

    I found this better solution:
    Windows>General Editor>Namespace Editor
    choose the namespace and press delete option
    a dialog box will pop-up, choose “Merge with root” and the object is now part of the root/main group. Also check if the “root:” is with a green dot, that means you’re okay now.
    Much easier to me, i think.

  13. Stephen Says:

    I would agree that the namespace editor is a lot easier than using Mel. However, this tutorial was written before it existed in Maya so that’s why it is up. Not everyone has the latest version so worth keeping here.

  14. Niels Says:

    I found a simple way to remove any namespaces or prefixes, but it works.
    Example: when you imported a file named Character1, every item in your hierarchy will be named like Character1_Joint1 or Character1_Locator1.

    To simply remove all the “Character1” prefixes, go to Modify>Search and replace names.
    In the option window you type in Search for: Character1_
    and in Replace with: *hit spacebar once*

  15. Regan Music Says:

    but now we have:

    http://download.autodesk.com/global/docs/maya2013/en_us/index.html?url=files/GUID-084E707F-7C78-4F9F-B1C1-4876EB19D997.htm,topicNumber=d30e133054

  16. Andrew Says:

    Worked perfectly! Thank You.

  17. Factory 1 (Part 1) – The Girl Behind the Layer Mask Says:

    […] the problem and I found this link which offers a bit of MEL code to remove the namespace – but I think this code has to be […]

  18. myara Says:

    You could get all the NameSpaces and delete them automatically:

    //mel
    string $allNS[] = `namespaceInfo -listOnlyNamespaces`;
    for ($ns in $allNS){
    if ($ns != “UI” && $ns!=”shared”){
    namespace -mv $ns “:” -force;
    namespace -rm $ns;
    }
    }

    It may add a number to your object’s name if they have the same name as the nameSpace.

  19. myara Says:

    I just found that this code works better for me:

    string $allNS[] = `namespaceInfo -listOnlyNamespaces`;
    for ($ns in $allNS){
    if ($ns != “UI” && $ns!=”shared”){
    namespace -mergeNamespaceWithParent -removeNamespace $ns;
    }
    }

  20. tom Says:

    Harry_Gee solved it for me. Nothing else worked.

  21. Ralph Manis Says:

    This will work for Maya 2017…

    //MEL to remove namespaces

    string $allNS[] = `namespaceInfo -listOnlyNamespaces`;
    for ($ns in $allNS){
    if ($ns != “UI” && $ns!=”shared”){
    namespace -mergeNamespaceWithParent -removeNamespace $ns;
    }
    }

Leave a Comment