Hey,
Thanks for the answer, but I am not doing anything that is not allowed according to that document. Note: We are not referencing in a maya scene that contains namespaces. We are just creating an entirely new assembly node during the activate of another assembly node and trying to set it's representation namespace.
So just a bit more info:
We are creating our custom assemblynode in python using the maya.OpenMaya.MPxAssembly
We are using the exact same setup for namespaces as the "assemblyReference" node from the devkit, only of course we translated it to the equivalent python code.
Then in our custom representation we do something along the lines of the following: (Minimal example for the representation, in reality it would create assembly nodes based on a json file)
import maya.OpenMaya as om
def mobject_from_node(nodename):
selList = om.MSelectionList()
selList.add(nodename)
node = om.MObject()
selList.getDependNode(0, node)
return node
def create_assembly(name, namespace):
node = cmds.assembly(type='customAssembly', name=name)
onode = mobject_from_node(node)
afn = om.MFnAssembly(onode)
ns_plug = afn.findPlug('repNamespace')
ns_plug.setString(namespace)
return onode
class CustomRepresentation(Representation):
"""Representation which builds a set."""
def activate(self):
create_assembly('test', 'custom_namespace')
return True
This creates a new assembly node with the name "test". During initialization of this assembly node it will by default set it's representationNamespace to "test_NS". Then when setting the repNamespace plug to "custom_namespace" maya prints the error:
// Error: line 1: Cannot rename namespace associated with a nested assembly. //
The plug is set to "custom_namespace" but the actual namespace of the nodes that will be created under that new assembly node will still use the default "test_NS" namespace.
After that my activate method returns True which will cause the assembly system to call the postLoad on the newly created sub-assembly node. (which will then proceed to lock the namespace attribute as it should)
One would expect that nested assemblynodes should have the option of their namespaces being changed as long as the activate method of their parent has not yet completed, as this namespace attribute is part of the required setup.
Is this an oversight in the MPxAssembly API? Am I trying to do things that should not be done? Or is there actually a way to do this, that I have not found yet?
In another representation we use the MFnAssembly::importFile function pointing to a scene containing assembly nodes and when tracing through the code with a python debugger the calls that it makes during the initialization of the sub-assembly looks 100% the same, but there it DOES allow to change the representationNamespace of the sub-assembly. But as I can not see any of the actual code inside the MFnAssembly::importFile function there is no way for me to see what kind of magic things are being done to get that to work.
Does this make the issue more clear?
Cheers,
Hans