Set the namespace for a nested assembly

Set the namespace for a nested assembly

Anonymous
Not applicable
1,756 Views
4 Replies
Message 1 of 5

Set the namespace for a nested assembly

Anonymous
Not applicable

Hey all,

 

I actually posted this a few days ago, but it seems the original post never appeared in the forum... So I apologize if this one end up being posted double.


I am in the process of creating some custom assembly nodes with our own representations. One of our custom representations loads in a json file with our setdress data. This representation will need to create new assemblynodes based on the data inside that json file. Essentially this will create a nested assembly.


Most of it is working already, but we have one very annoying issue. We can not set the namespace of that newly created node. It will always just get the default namespace and then when we try to set the namespace to a new value (from within the activate function of the parent assembly) it will give an error that you can not rename a namespace of a nested assembly node.

When using the MFnAssembly::ImportFile to load in a different maya scene containing the assemblynodes they do get the correct namespaces applied. So it should be possible somehow. How can we get that same functionality in our custom representation without writing a filetranslator?

I hope there will be someone able to help me.

Hans

0 Likes
Accepted solutions (1)
1,757 Views
4 Replies
Replies (4)
Message 2 of 5

john.paul.giancarlo
Autodesk
Autodesk

Scene Assembly workflow limitations

Scene does not fully support workflows that include:

  • Deformers:
    • Geometry with deformers can be added to an assembly definition as a Scene representation.
    • Deformers cannot be created on geometry after the object is part of a Scene representation.
  • HumanIK rigs
    • HumanIK rigs can be added to an assembly definition as a Scene representation. Animation can be added and edited by setting keyframes (on the base animation layer only) as assembly edits on an assembly reference node.
    • You cannot create a HumanIK rig from a skeleton that is contained by an assembly reference node or member.
    • You cannot add auxiliary effectors and pivots to HumanIK rigs that are contained by an assembly reference node or member.

Scene Assembly does not support workflows that include:

  • File referencing
  • Maya Dynamics, nDynamics, or Fluid Effects
  • Animation layers
  • Character sets
  • Set driven keys
  • Motion path animation, including flow path objects
  • Animation Snapshot
  • Render layers
Important: Do not use namespaces in representation files.
 
hopes this helps
0 Likes
Message 3 of 5

Anonymous
Not applicable

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

0 Likes
Message 4 of 5

cheng_xi_li
Autodesk Support
Autodesk Support

Hi,

 

I am confused about how your MPxRepresentation designes. It should call self._getAssembly() to get the assembly which owns this representation and modify the assembly object with MFnAssembly::updateRepNamespace I think.

 

Could you give us a working sample(including the script for creating your custom representation node)? The code snippet in your original post doesn't work and looks like not following the design of this class. 

 

BTW: MPxRepresentation should be used with MPxAssembly. If you have a sample please send to us also.

 

Yours,

Li

 

0 Likes
Message 5 of 5

Anonymous
Not applicable
Accepted solution

I stripped most of the code away to only show the relevant part.

I am not trying to change the representation namespace of the parent assembly, so I don't need the parent assembly. I am trying to set the representation namespace of a newly created assemblynode that gets created during the activate of another assemblynode.

Also, there is no MFnAssembly.updateRepNamespace(), only an MPxAssembly.updateRepNamespace() but that one is not something I can call myself, it gets called by maya when there is a namespace conflict to give you the ability to handle updating your internal way of keeping track of the namespace.

However, I did just find a "hacky" solution. Instead of trying to set the namespace attribute after creating the node I changed the implementation of getDefaultNamespace in the MPxAssembly class. So by default the representation namespace would be "nodename_NS" But I now changed it that if there is "___" in the nodename it will take the part of the name in front of those underscores to be the namespace. Then I can do the following inside my representation to create a new assemblynode:

node = cmds.assembly(type='customAssembly', name='custom_namespace____test')
dagpath = get_dag_from_node(node)  # returns an MDagPath
fndag = MFnDagNode(dagpath)
fndag.setName('test')

This would end up creating a new assembly node with the name test and the representation namespace correctly set to "custom_namespace". It seems a bit hacky, but at least it's working.

 

Cheers,

Hans

0 Likes