Yo,
Even though you are setting the current namespace, the other various
commands are still expecting fully qualified namespace paths to match. But
I think you would get what you want by using the relativeNames mode on the
namespace command. As per the docs, you have to be careful to turn it back
off after you have turned it on, since it changes the behavior of maya
cmds. Here is a quick snippet you can try that I have used before. It uses
a context manager to change the namespace, turn on relative mode, do
whatever commands you want, and then turn it back off and restore the
previous namespace:
from contextlib import contextmanager
@contextmanagerdef 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")
Does that do what you wanted?
Justin
On Mon, Mar 16, 2015 at 6:20 PM Panupat Chongstitwattana <[email protected]>
wrote:
> If I store my object names without namespace and then reference them into
> a new scene.
>
> For example if this is the string I stored.
> rig_grp|geo_grp|head_grp|left_eye_geo
>
> And I know for certain my namespace would be "ref_RN1"
>
> Currently I would manipulate the stored string so it turns into
> ref_RN1:rig_grp|ref_RN1:geo_grp|ref_RN1:head_grp|ref_RN1:left_eye_geo
> But I'm curious if there's a cleaner or more proper way to do this?
>
> Tried use namespace(set=':ref_extra_RN1') but that doesn't seem to do
> anything
>
> Best regard.
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/bb64548b-111e-483e-a609-e4d3015a8b15%40googlegroups.com
> <https://groups.google.com/d/msgid/python_inside_maya/bb64548b-111e-483e-a609-e4d3015a8b15%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA20P%2BRYpFjptkw6GmNy_gGd9FhVP91ahO19s8duEpeWKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.