query shading group assigned to instanced geomerty shape node?

1,718 views
Skip to first unread message

Ling

unread,
Jul 2, 2010, 3:56:43 PM7/2/10
to python_inside_maya
Hi guys:

Normally when dealing with a non-instanced shape node, it's easy to
get its shading group assighnment like:

shadingGroup = cmds.listConnections(shapeNode + '.instObjGroups[0]')
[0]



but when it comes to instanced the shapde nodes, one shape node
might have several shader assignments.

if I do a list connection to the instanced shape node, all the
shading groups assigned to it will be listed, and don't know which one
is assigned to a particular transform node's children shape node.

so how can I query which shader is assign to a given transform node?


many thanks


-ling

johnvdz

unread,
Jul 2, 2010, 7:56:32 PM7/2/10
to python_in...@googlegroups.com
Hi all just a quick Question i want to get a MvectorArray and Average
all the Values together without having to iterate over the values.

what i the best way to do this. in python API? is there a solution for
this?

any ideas would be much appreciated


john

John Creson

unread,
Jul 3, 2010, 2:00:57 AM7/3/10
to python_in...@googlegroups.com
If you pass in the full name to the shape node from the instance you
are wishing to find the shading group of, you will get the correct
shader returned.

import maya.cmds as cmds

shapeNode = 'pSphere2|pSphereShape1'
shadingGroup = cmds.listConnections(shapeNode + '.instObjGroups')[0]
print shadingGroup

> --
> http://groups.google.com/group/python_inside_maya

Judah Baron

unread,
Jul 3, 2010, 2:17:52 AM7/3/10
to python_in...@googlegroups.com
This question is slightly off topic, but still related.

When a shape from a referenced file is instanced a bunch of groupid nodes are created relating to the shading network, and it is possible to assign new materials to this instance. I am wondering if there is a way to prevent the creation of these groupid nodes and all of the related edits. We have a usage case wherein we know that we will never need or want to modify the materials of one of these "library" shapes.  We have some cleanup code that removes all of these edits, but I would much rather find a more elegant solution. 

 thanks,
-Judah


John Creson

unread,
Jul 3, 2010, 5:00:02 AM7/3/10
to python_in...@googlegroups.com
I'm not sure I recommend this, but maybe it can help out...

Particle instancing is simpler and doesn't cause these nodes and edits
to come into existence.

Assuming your object is at 0 0 0 when reffed in,
You can create a single particle at 0 0 0
Select your referenced in object, select you particle and choose
Particles > Instancer(replacement)

This creates a instancer node (and a single instance for each particle
- in this case 1).
The instancer node needs the particle and the transform input from
your reffed object.
The instancer can be transformed like a normal transform node, plus
there are some other attributes available.

You can do this as many times as you'd like with the same particle object.

> --
> http://groups.google.com/group/python_inside_maya

owen burgess

unread,
Jul 5, 2010, 5:18:02 AM7/5/10
to python_in...@googlegroups.com
Hi Judah,

re: instancing referenced shape nodes...

Here is a short explanation of what's happening, and a couple of workarounds:

. if you instance a referenced mesh that has per face material assignments, the instance will lose these material assigments when you reload the reference IF the referenced object is in a Group, ie: not parented to World.
. you've already noticed that when you instance your mesh, Maya creates a whole bunch of reference edits. On the face of it, these reference edits are disconnecting the per-face material assignments to the mesh shape node (yes, Autodesk is aware of the issue).
. what's actually happening is that the reference edits are disconnecting the groupID nodes that must be connected to both a shape node and a shading group for an assignment to happen....the upshot is that your scene fills up with 'dangling' groupID nodes.
. you can re-assign the material to the instance but you're just creating more reference edits, and not really addressing the problem.

As I mentioned earlier, the issue has to do with the way you organise the DAG. If your referenced mesh is in World space when you instance it, then you won't get the problem. However, if your mesh is Grouped when you instance it then Maya will break the connections to the groupID nodes and you'll lose your material assignments.

So you can either:
. leave your meshes in world space, or
. instance the mesh's parent node rather than the mesh object itself. So if you had your mesh parented to a Group node, you would instance the Group node.
. add your meshes to a Container (without Transform) - using Containers means you can organise your meshes in a hierarchical structure - similar to grouping them - yet allows Maya to instance each mesh without all the cr*p.

Hope that helps,

Owen




Judah Baron

unread,
Jul 6, 2010, 6:44:27 PM7/6/10
to python_in...@googlegroups.com
@Owen,
Thanks for the detail. We were pretty disappointed to see all of those reference edits show up. One of the main reasons we decided to do this was to reduce reference edits! Ugggghh. We had been running a cleanup callback that is rather nasty with large files. We have since turned it off and manage the references ourselves, meaning we track all references of a certain type, then kill them all at scene load and recreate. It's not our favorite solution, but it keeps the files from running wild with wrong/illegal edits.

I suppose we could move to instantiating the transform parent of the shape that we are interested in, but initially it seemed more efficient to stick to the shape node. Obviously we had assumed too much:)

@John
First off, I love the way you started that reply: "I'm not sure I recommend this," LOL.
Second, I had actually considered using an instancer. We still may do that. I'll have to run more tests when I can.

Thanks,
-Judah



johnvdz

unread,
Jul 8, 2010, 6:24:58 PM7/8/10
to python_in...@googlegroups.com
Hi all,

I'm trying to get a Icon in my model view in a standard QListview

I am running the PumpThread in maya2008 on ubuntu linux but I'm now
testing this in Python Standalone and i still get the same error.

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::setCompositionMode: Painter not active
QPainter::end: Painter not active, aborted

The UI runs but i get no icon showing, althroughi get the above error
when i select the item in the listview

As far as i know i'm know i'm doing everything correctly. I only have
one collum and the item is just text with a check box 'setCheckable' and
i just want an icon image in the same collum as part of the same item.

I have tried different formats gif, xpm and jpg and also standard images
etc but the same error occurs.

does anyone have sample code that is simple and works fine with pixmaps?
or if you can see anything in my code let me know

cheers

john


to run the below code just make a .ui file mainwindow with a single
listView named 'GroupList' and replace the UI_FILE Path name to point to it.

note...some lines are commented out for testing standard images and some
standard maya ones

## beginning Code##

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import uic
import os
import sys

win = None

UI_FILE = 'PATHTOMYUIFILE.ui'

#icon='/usr/autodesk/maya2008-x64/icons/out_mesh.xpm'

cacheGroups=['Shirt_dyn', 'Shirt_hi', 'shirt_dyn', 'shirt_hi']

class MainWindow(QMainWindow):

def __init__(self, *p):
QMainWindow.__init__(self, *p)
uic.loadUi(UI_FILE, self)
self.model = QStandardItemModel()

#pixmap = QPixmap(icon)
icon = QIcon ( self.style().standardPixmap(QStyle.SP_FileIcon) )

cacheGroups.sort()
for i in cacheGroups:
itm = QStandardItem(i)
#itm.setIcon(QIcon(pixmap))
itm.setIcon(icon)
itm.setCheckable(True) #adds checkbox

self.model.appendRow(itm)

self.GroupList.setModel(self.model)

def run():

app = qApp
win = MainWindow()
win.show()


if __name__ == '__main__': # runs them Main window
app = QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
print '%s done' % __file__

run()

Reply all
Reply to author
Forward
0 new messages