Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Object Instancing with the Python 1.0 API

Object Instancing with the Python 1.0 API

aries2
Explorer Explorer
469 Views
2 Replies
Message 1 of 3

Object Instancing with the Python 1.0 API

aries2
Explorer
Explorer

Hello,

I am exploring the Maya API and testing code to instance an object by parenting a new transform node to the existing shape node:

 

 

 

import maya.OpenMaya as om
import maya.OpenMayaMPx as mpx

#explicitly get shape node
list = om.MSelectionList()
om.MGlobal.getSelectionListByName("pCubeShape1",list)
shape_node = om.MObject()
list.getDependNode(0,shape_node)

#create transform node
trans_node = om.MFnTransform().create()
dag_node = om.MFnDagNode(trans_node)

#parent shape node to transform node and instance with 'keepExistingParents' flag
dag_node.addChild(shape_node,keepExistingParents=True)

 

 

 

I'm getting the error: 'TypeError: MFnDagNode_addChild() takes no keyword arguments'.

Obviously it's supposed to take this keyword argument and I've seen several example python scripts which do pass this flag to the call.

 

Any Ideas?

Thanks!

0 Likes
Accepted solutions (1)
470 Views
2 Replies
Replies (2)
Message 2 of 3

brentmc
Autodesk
Autodesk
Accepted solution

Hi,

 

The Python 1.0 API is auto-generated from the C++ API so named arguments are not supported. (and one of the reasons the 2.0 API was developed)

So, in your example you just have to provide an index argument and then a boolean for keepExistingParents like this:

dag_node.addChild(shape_node, 0, True)



Brent McPherson
Principle Engineer
0 Likes
Message 3 of 3

aries2
Explorer
Explorer

Thanks a lot for your help @brentmc! This now works.

I guess the other examples I saw were based on the 2.0 API.

 

0 Likes