API error connecting initialShadingGroup to a mesh

794 views
Skip to first unread message

Rudi Hammad

unread,
Nov 1, 2015, 8:56:34 AM11/1/15
to Python Programming for Autodesk Maya
hello
I am new to api and I am starting with something quite simple. Just making a cube.
Everything goes ok until I try to give it the default material. A problem with the connection between the 'polySurfaceShape1.instObjGroups' to 'initialShadingGroup.dagSetMembers'

here is the code:



import maya.OpenMaya as OpenMaya

"""------ NODOS SUELTOS -----"""
#--[DG NODES]--#
# polyCube
mFnDependencyNode_pCubeHistory
= OpenMaya.MFnDependencyNode()
objPolyCube
= mFnDependencyNode_pCubeHistory.create("polyCube", "myPolyCubeName") #el tipo de nodo existente, designado en ayuda por typeId
#--[DAG NODES]--#
# transform
mFnDagNode_pCubeTransform
= OpenMaya.MFnDagNode()
objPolyTrans
= mFnDagNode_pCubeTransform.create("transform")
# cube shape
mFnDagNode_pCubeShape
= OpenMaya.MFnDagNode()
objPolyShape
= mFnDagNode_pCubeShape.create("mesh", objPolyTrans)
#--[retrive initialShadingGroup]--#
mSelectionList
= OpenMaya.MSelectionList()
mSelectionList
.add("initialShadingGroup")
mObject_initShdGrp
= OpenMaya.MObject()
mSelectionList
.getDependNode(0,mObject_initShdGrp)
initShadingNode
= mObject_initShdGrp.apiTypeStr()
mFnDependencyNode_initialShadingGroup
= OpenMaya.MFnDependencyNode()
mFnDependencyNode_initialShadingGroup
.setObject(mObject_initShdGrp)
name
= mFnDependencyNode_initialShadingGroup.name() # Result: initialShadingGroup, so it ok so far



"""------ CONNECTIONS WITH MDGMODIFIER -----"""
mDgModifier
= OpenMaya.MDGModifier()
# polyCube-->shape connections
srcPlug
= mFnDependencyNode_pCubeHistory.findPlug("output")
destPlug
= mFnDagNode_pCubeShape.findPlug("inMesh")
mDgModifier
.connect(srcPlug, destPlug)
# shape-->shader connections
meshOutPutPlug
= mFnDagNode_pCubeShape.findPlug("instObjGroups")
initShadingGroupInPutPlug
= mFnDependencyNode_initialShadingGroup.findPlug("dagSetMembers")
mDgModifier
.connect(meshOutPutPlug, initShadingGroupInPutPlug)

mDgModifier
.doIt()




# Error: Connection not made: 'polySurfaceShape1.instObjGroups' -> 'initialShadingGroup.dagSetMembers'.  Source node will not allow the connection. #
# Error: RuntimeError: file S:\Maya_2016_DI\build\Release\runTime\Python\Lib\site-packages\maya\OpenMaya.py line 2889: (kFailure): Unexpected Internal Failure #

I don´t understand why the connection can´t be made
thanks

Justin Israel

unread,
Nov 1, 2015, 3:43:22 PM11/1/15
to python_in...@googlegroups.com
Could you try using some of the higher level API calls, instead of trying to do it more low level, by connecting up explicit plugs?
setFn = OpenMaya.MFnSet(mObject_initShdGrp)
setFn.addMember(objPolyShape)
This will end up doing the right thing. I think your probably was that the plugs are array types and they weren't being connected properly. But if you stick to the high level functions, it won't matter.


--
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/eea5784b-e6e8-4b35-bf8a-14e73687720d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Nov 1, 2015, 3:48:02 PM11/1/15
to python_in...@googlegroups.com

Justin Israel

unread,
Nov 1, 2015, 6:20:07 PM11/1/15
to python_in...@googlegroups.com

Rudi Hammad

unread,
Nov 1, 2015, 6:31:58 PM11/1/15
to Python Programming for Autodesk Maya
Thanks guys.
hey Marcus, of course I can use cmds.connectAttr() , but that is not my goal. I want to do it with API, but thanks
Justin, I didn´t know about a higher level in API. That definitetly is makes it easier. thank you. I still dont understand why it didn´t work, but that´s okey
cheers!
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

--
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.

Justin Israel

unread,
Nov 1, 2015, 6:45:03 PM11/1/15
to python_in...@googlegroups.com
On Mon, Nov 2, 2015 at 12:32 PM Rudi Hammad <rudih...@gmail.com> wrote:
Thanks guys.
hey Marcus, of course I can use cmds.connectAttr() , but that is not my goal. I want to do it with API, but thanks
Justin, I didn´t know about a higher level in API. That definitetly is makes it easier. thank you. I still dont understand why it didn´t work, but that´s okey

If you look at what's happening in the Script Editor output, when you add the shape to the shader group, you will see it is actually doing something like this:

instObjGroups[0] => dagSetMembers[0]

When you use the higher level API for adding the member, you don't have to worry about the array attributes. 
 
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

--
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.

--
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.

--
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/98b6daa9-cf57-4e5a-8422-124cc751f3bf%40googlegroups.com.

Roy Nieterau

unread,
Nov 2, 2015, 2:49:18 PM11/2/15
to Python Programming for Autodesk Maya
Not entirely related to the question but just giving a heads up to ensure you won't be pulling out your hairs as you go.

If you're using Maya 2016 and MFnSet in API to list the current members of a shadingEngine (shading group) it will also list something like "shaderBallGeomShape1" if you looked at the shader in the new Hypershade's material viewer in the current session. The "shaderBallGeomShape1" is no valid object in the scene. Only the API seems to have this bug and return it as an object (maya commands itself doesn't).

Cheers,
Roy
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.

--
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.

--
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.

--
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.
Reply all
Reply to author
Forward
0 new messages