list connection of specific channel?

4,168 views
Skip to first unread message

Panupat Chongstitwattana

unread,
Jun 1, 2012, 12:56:55 AM6/1/12
to python_in...@googlegroups.com
For example, if I want to get the input connection of blinn1.Color only, what would be the flag I need?

Thanks.

Judah Baron

unread,
Jun 1, 2012, 1:13:16 AM6/1/12
to python_in...@googlegroups.com
You don't need to use a flag to get what you are looking for. Just pass in the "node.attr" you are interested in querying, rather than just the "node".

Ex:
cmds.listConnections( "blinn1.color" )

You can use various command flags to filter the return.

On Thu, May 31, 2012 at 9:56 PM, Panupat Chongstitwattana <panu...@gmail.com> wrote:
For example, if I want to get the input connection of blinn1.Color only, what would be the flag I need?

Thanks.

Justin Israel

unread,
Jun 1, 2012, 1:36:48 AM6/1/12
to python_in...@googlegroups.com
http://download.autodesk.com/global/docs/maya2012/en_us/CommandsPython/index.html

default gives you both source and dest connection object names (without attr names)

Panupat Chongstitwattana

unread,
Jun 1, 2012, 2:19:29 AM6/1/12
to python_in...@googlegroups.com
Thanks Justin :)

Justin Israel

unread,
Jun 1, 2012, 11:02:08 AM6/1/12
to python_in...@googlegroups.com, python_in...@googlegroups.com
Ahh I always accidentally link to the main index when I paste maya doc links, because they freaking use frames. And then it looks like I'm just being snooty like "go read the docs". 

:-)

Daz

unread,
Dec 10, 2012, 11:33:46 AM12/10/12
to python_in...@googlegroups.com
Heya

If I may bump this topic instead of making a new one.

I'm trying to write a tool that will disconnect reflectivity/and other specific node connections for all selected materials.

But when I type for example..
cmds.listConnections('mia_material_x_passes1.reflectivity')
I get

# Result: [u'luminance1'] #

and I need luminance1.outValue so I can use cmds.disctonnectAttr....

How can I get the rest of the node details so I can use it ?

I went over the list connection docts but I failed :(

Thanks, bye.

Justin Israel

unread,
Dec 10, 2012, 1:48:43 PM12/10/12
to python_in...@googlegroups.com
listConnections
plugs(p)    boolean 
If true, return the connected attribute names; if false, return the connected object names only. Default false;

So just add the plugs flag:
cmds.listConnections('mia_material_x_passes1.reflectivity', p=True)



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To post to this group, send email to python_in...@googlegroups.com.
To unsubscribe from this group, send email to python_inside_m...@googlegroups.com.



Daz

unread,
Dec 11, 2012, 8:51:14 AM12/11/12
to python_in...@googlegroups.com
Heya

Right, that do gives me what I want thanks ! I had a feeling its one of settings I just failed to understand it properly...

Anyway since I'm writing here got 1 more question.

I have a list of materials and then a list of specific connections to those materials.

Is there a way to disconnect those connection from those materials?

My test fail somehow because(I think) every time I go through loop I end up trying to disconnect wrong nodes from wrong materials, since it goes one by one over list...

Not sure if I can match up list somehow or tell it to pick 1 mat, get its connections, break them, move to next node

Is there a way to do it ? Must be I guess I just didn't find out the proper command or how to name it...

Thanks, bye.

Justin Israel

unread,
Dec 11, 2012, 12:05:46 PM12/11/12
to python_in...@googlegroups.com
If you have a list of material attributes like this:
mats = ['material1.color', 'material2.color']

Then you can loop over it and disconnect like this:

for mat in mats:
    conns = cmds.listConnections(mat, p=True) or []
    for conn in conns:
        cmds.disconnectAttr(conn, mat)

If I missed your question, can you post an example of what you have so far so I can see what is not working?



Jesse Capper

unread,
Dec 11, 2012, 2:19:23 PM12/11/12
to python_in...@googlegroups.com
As a bit of an aside, I wish cmds.listConnections had an option to return connections in source/destination pairs or ordering like pymel does. Is there a better way to handle disconnecting attributes with an unknown direction than querying twice like so?

for attr in attrs:
src_conns = cmds.listConnections(attr, d=False, p=True) or []
for conn in src_conns:
cmds.disconnectAttr(conn, attr)
dst_conns = cmds.listConnections(attr, s=False, p=True) or []
for conn in dst_conns:
cmds.disconnectAttr(attr, conn)

Justin Israel

unread,
Dec 11, 2012, 5:01:09 PM12/11/12
to python_in...@googlegroups.com
pymel does it with two queries using cmds.listConnections as well, plus a bunch of other stuff wrapped around it to sort, split, convert, etc.

Daz

unread,
Dec 12, 2012, 5:41:51 AM12/12/12
to python_in...@googlegroups.com
Heya

Thanks Justin ! I got it to work at the end.

In the end I had to use Try command to filter over materials that did not have any connections and give me out errors... I still find it difficult to master a command that can check if there is connection and if so execute script so I gotta crack on that one day...

http://pastebin.com/FZsqhGVb

Thanks for help again, bye.

Justin Israel

unread,
Dec 12, 2012, 9:27:51 AM12/12/12
to python_in...@googlegroups.com
There is no need for a try..except here though. If all you want to do is disconnect any source connections driving that one specific attribute on those materials, you can simplify:

mats = cmds.ls(sl=1)
for mat in mats:
    matA = '%s.diffuse_weight' % mat
    conns = cmds.listConnections(matA, p=True, d=False, s=True) or []
    for conn in conns:
        cmds.disconnectAttr(conn, matA)

Just join the attribute once, use it specifically to look up connections instead of just the mat name, and only loop on source connections. This way you should not encounter exceptions because they really are connections if you get results. 

ctjanney

unread,
Apr 30, 2013, 10:50:30 PM4/30/13
to python_in...@googlegroups.com
On a similar note....how to get long names from listConnections?

I'm looking for all animCruves and setting their driven attr and node so I can write out anim curves, ala dkanim, but with more controls for our pipeline. Why long names? Modelers like to duplicate and not make sure sub nodes are uniquely named.

-ctj

Jesse Capper

unread,
May 1, 2013, 6:41:53 PM5/1/13
to python_in...@googlegroups.com
listConnections should return the shortest unique name for each node, so you should be able to work with the output of that no problem.

Otherwise you can pass the results to ls to get the long names.

longNames = cmds.ls(cmds.listConnections(attr), l=True)
Reply all
Reply to author
Forward
0 new messages