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. On Wednesday, December 12, 2012, Daz wrote: > 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. > > On Tuesday, 11 December 2012 22:01:09 UTC, Justin Israel wrote: > > 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. > > > > > > > > On Tue, Dec 11, 2012 at 11:19 AM, Jesse Capper <jesse....@gmail.com> > wrote: > > > > 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) > > > > > > > > > > > > On Tuesday, December 11, 2012 9:05:46 AM UTC-8, Justin Israel wrote: > > > > > 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? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > On Dec 11, 2012, at 5:51 AM, Daz wrote: > > > > > > > > > > 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. > > > > > > > > > > -- > > > > > 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_maya+unsubscr...@googlegroups.com. > > > > > > > > -- > > > > 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_maya+unsubscr...@googlegroups.com. > > -- > 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_inside_maya@googlegroups.com. > To unsubscribe from this group, send email to -- 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_inside_maya@googlegroups.com. To unsubscribe from this group, send email to python_inside_maya+unsubscr...@googlegroups.com.