As a shot in the dark, if the origin of your namespaces is from importing a
scene, you have the option of merging names as opposed to storing it all
within a namespace. Namespaces are originally for dealing with name clashes.

>From the docs:

Namespaces are primarily used to resolve name-clash issues in Maya, where a
new object has the same name as an existing object (from importing a file,
for example). - Docs
<http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/CommandsPython/namespace.html>

​


On 4 September 2014 09:07, Marcus Ottosson <konstrukt...@gmail.com> wrote:

> Hello Marcus!
> Well, that only renames the node. So child nodes will still have the
> namespace intact.
>
> Yes it does. A namespace in Maya is actually nothing more than some
> additional character in its name. The cmds.namespace() is really just a
> fancy cmds.rename if all you’re using it for is renaming nodes. One of
> its benefits lie in the creation or removal of namespace objects, those you
> can see under Window -> General Editors -> Namespace Editor. But even
> those are mere conveniences for ultimately renaming nodes, as the “root”
> namespace really just means “no colons (:) in the name”
>
> With this in mind, the following snippet would look at your selection, and
> remove namespaces from all children below.
>
> def remove_namespaces(node):
>
>     try:
>         # Note rsplit instead of split
>
>         namespace, name = node.rsplit(":", 1)
>     except:
>         namespace, name = None, node
>
>     if namespace:
>         try:
>             cmds.rename(node, name)
>         except RuntimeError:
>             # Can't remove namespaces from read-only nodes
>             # E.g. namespaces embedded in references
>             pass
> def remove_namespaces_from_selection():
>     for node in cmds.ls(sl=1):
>         # Remove namespaces of all children first
>         for descendent in cmds.listRelatives(node, allDescendents=True):
>             remove_namespaces(descendent)
>
>         # Finally, remove namespace from current selection
>         remove_namespaces(node)
>
>
> remove_namespaces_from_selection()
>
> It wouldn’t look at shaders though, for that I’d recommend also listing
> connection to each node capable of having a shader.
>
> Does that help at all?
> ​
>
>
> On 3 September 2014 20:49, Stefan Andersson <sander...@gmail.com> wrote:
>
>> Hello Marcus!
>> Well, that only renames the node. So child nodes will still have the
>> namespace intact.
>>
>> So right now I have this which moves the namespace eventually into the
>> root
>>
>>
>> oSel = cmds.ls(sl=True)[0].split(":")
>> if len(oSel) >1:
>>     for i in range(len(oSel)-1):
>>         cmds.namespace(mv=(oSel[i], ":"), f=True)
>>
>> Still trying to find a clever way of removing a selected object/shader
>> (and their child nodes) into the root.
>>
>> regards
>> stefan
>>
>>
>>
>> On Wed, Sep 3, 2014 at 6:12 PM, Marcus Ottosson <konstrukt...@gmail.com>
>> wrote:
>>
>>> Hi Stefan,
>>>
>>> The namespace is in the name, so renaming a node to a name without
>>> namespace will effectively remove its namespace.
>>>
>>> cmds.rename('namespace:my_node', 'my_node')
>>>
>>> So if you’ve got many shaders you’d like to remove namespaces from,
>>> simply rename them all.
>>>
>>> for shader in cmds.ls(type='shadingDependNode'):
>>>     try:
>>>         # Note rsplit instead of split
>>>         namespace, name = shader.rsplit(":", 1)
>>>     except:
>>>         namespace, name = None, shader
>>>
>>>     if namespace:
>>>         try:
>>>             cmds.rename(shader, name)
>>>         except RuntimeError:
>>>             # Can't rename some shaders, like lambert1
>>>             pass
>>>
>>> Best,
>>> Marcus
>>> ​
>>>
>>>
>>> On 3 September 2014 17:53, Stefan Andersson <sander...@gmail.com> wrote:
>>>
>>>> Hi All,
>>>>
>>>> I'm having a brain lock down... I'm trying to removed namespaces (both
>>>> nested and not nested) from shaders. But can't for the world in me figure
>>>> out how to check the namespace of the selected object, or query a node to
>>>> return the namespaces....
>>>>
>>>> I need to get a string back of all the namespaces that a object or a
>>>> shader has.
>>>>
>>>> any help would be appreciated. or a RTFM to a specific page :)
>>>>
>>>> regards
>>>> stefan
>>>>
>>>>
>>>>
>>>> --
>>>> -- -- - [ *not morse code* ] -- - - -- -- - -- - -- -- - - - --- - --
>>>> - - - --- -
>>>> *stefan andersson | vfx superviso*r
>>>> Important Looking Pirates  | http://www.ilpvfx.com
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Python Programming for Autodesk Maya" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to python_inside_maya+unsubscr...@googlegroups.com.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/python_inside_maya/CAKW24e1X8N1As7CCePs_ijzMHj641rP7gCM_C3yNZ96QMqsdKA%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAKW24e1X8N1As7CCePs_ijzMHj641rP7gCM_C3yNZ96QMqsdKA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> --
>>> *Marcus Ottosson*
>>> konstrukt...@gmail.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Python Programming for Autodesk Maya" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to python_inside_maya+unsubscr...@googlegroups.com.
>>>  To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCYhOyigQ4Evvb4S%3D4EPOA3os-%3D06myX6d-zcKsfMRxFQ%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCYhOyigQ4Evvb4S%3D4EPOA3os-%3D06myX6d-zcKsfMRxFQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> --
>> -- -- - [ *not morse code* ] -- - - -- -- - -- - -- -- - - - --- - -- -
>> - - --- -
>> *stefan andersson | vfx superviso*r
>> Important Looking Pirates  | http://www.ilpvfx.com
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to python_inside_maya+unsubscr...@googlegroups.com.
>>  To view this discussion on the web visit
>> https://groups.google.com/d/msgid/python_inside_maya/CAKW24e0G6igN1y3BJ2m3DxL8tkYUYavysvTpmD9-Fm4zbN2xAg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/python_inside_maya/CAKW24e0G6igN1y3BJ2m3DxL8tkYUYavysvTpmD9-Fm4zbN2xAg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> *Marcus Ottosson*
> konstrukt...@gmail.com
>



-- 
*Marcus Ottosson*
konstrukt...@gmail.com

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAZCNyj_KbOpuNd9uRASvXUxEunPMJHZTJ08Me1igB40Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to