from contextlib import contextmanager
@contextmanager
def namespaceContext(ns):
cur = cmds.namespaceInfo(currentNamespace=True)
on = cmds.namespace(q=True, relativeNames=True)
cmds.namespace(set=ns)
cmds.namespace(relativeNames=True)
yield
if on:
cmds.namespace(relativeNames=False)
cmds.namespace(set=cur)
# Test
cmds.namespace(set=":")
cmds.namespace(add="foo")
cmds.namespace(add="bar")
cmds.namespace(set=":foo")
cmds.sphere(name="mySphere")
cmds.namespace(set=":bar")
cmds.sphere(name="mySphere")
cmds.namespace(set=":")
cmds.ls("mySphere")
with namespaceContext(":"):
print cmds.ls("mySphere")
with namespaceContext(":foo"):
print cmds.ls("mySphere")
with namespaceContext(":bar"):
print cmds.ls("mySphere")
--
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/bb64548b-111e-483e-a609-e4d3015a8b15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
import maya.cmds as mc mc.select("ref_RN1:left_eye_geo",r=True)
--
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CABPXW4hj3sWVSJ_ABXdvHiuDgPa5eYC2OugrLs_gmK0o2nJP5A%40mail.gmail.com.
I would personally make it:
with namespace(":foo"):
print cmds.ls("mySphere")
Otherwise, that’s poetry you’ve got there, Justin. :)
You are too sweet Marcus! Hah
--
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+unsub...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOCGjGqK6OrLbuty6S69m_tSgEcRT%2B1rGEUo9m1dc7y76Q%40mail.gmail.com.