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
--
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_m...@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.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCYhOyigQ4Evvb4S%3D4EPOA3os-%3D06myX6d-zcKsfMRxFQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
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?
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e0G6igN1y3BJ2m3DxL8tkYUYavysvTpmD9-Fm4zbN2xAg%40mail.gmail.com.
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
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAZCNyj_KbOpuNd9uRASvXUxEunPMJHZTJ08Me1igB40Q%40mail.gmail.com.
any thoughts on shader publishing?
Actually, yes. Me and a few Pipeline TDs here and on GitHub have been working on exactly this for the past month; i.e. ensuring quality before sharing work, including shaders.
You are welcome to join; odds are we’d be able to create something better together than on our own. Have a look here:
https://github.com/abstractfactory/pyblish
GitHub is performing maintenance on their Wiki backend at the moment so links from the sidebar isn’t working as they should. Once they are finished, you can find more info here:
https://github.com/abstractfactory/pyblish/wiki
In a nutshell, the workflow is:
The end result is, nothing leaves Maya unless it follows your naming and namespace conventions, or whatever else you are looking to validate.
Feel free to add me on Hangouts and I’ll get you up and running with it, some of us are already using with it in production.
Best,
Marcus
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e2DnRK%3DVGPLZRc1Uy24iwbA%3DFNRDXkAMkgAJahhJaPeRQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e2DnRK%3DVGPLZRc1Uy24iwbA%3DFNRDXkAMkgAJahhJaPeRQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOB%2BcoUPSRd3m25V23id8TmxcrBU%2BZXf-kNRySk3xAYbKQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAMLeNpx_XR0WK0npYR-3xLOs%2BWKY8LaiDFVsK5ZvsfQp%2BqHshQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAKW24e3DE4nVSZwwN%3Dr818bWKrmRLKwm0Z9xPAmkcMbvjo8D7Q%40mail.gmail.com.
Marcus, that sounds an interesting project, I’ll take a look at that
Hey Mark, thanks for the kind words. It’d be my pleasure to have you with us. Let me know if you want any help getting set up.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAGQH2FGrQ%2BpYmmNTvdofZPUB3i-LhXsJCwNEotXObXHxFgu0Fg%40mail.gmail.com.