Announcement

Collapse
No announcement yet.

python - list connections, too many...

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • python - list connections, too many...

    Heya

    Bit sort of non/related question...

    I'm trying to list incoming connection to my shader but I get some extra nodes I'm not sure how to filter out
    I want to make a script to disconnect textures attached to nodes on multiple shaders. I got MR one working but Vray for some reason somehow is picky...
    Any hints?

    selected = cmds.ls(sl=1, mat=1)
    for materials in selected:
    connections = cmds.listConnections(c=1)
    newMatName = materials +'.diffuseColorAmount'
    for inNodes in connections:
    cmds.disconnectAttr(connections,newMatName)


    # Error: Invalid argument 1, '[u'VRayMtl1.message', u'materialInfo1', u'VRayMtl1.message', u'defaultShaderList1', u'VRayMtl1.outColor', u'VRayMtl1SG', u'VRayMtl1.diffuseColorAmount', u'VRayFlakesMtl1']'. Expected arguments of type ( , )
    # Traceback (most recent call last):
    # File "<maya console>", line 6, in <module>
    # TypeError: Invalid argument 1, '[u'VRayMtl1.message', u'materialInfo1', u'VRayMtl1.message', u'defaultShaderList1', u'VRayMtl1.outColor', u'VRayMtl1SG', u'VRayMtl1.diffuseColorAmount', u'VRayFlakesMtl1']'. Expected arguments of type ( , ) #

    Thanks, bye.
    CGI - Freelancer - Available for work

    www.dariuszmakowski.com - come and look

  • #2
    Instead of
    Code:
    for inNodes in connections:
        cmds.disconnectAttr(connections,newMatName)
    should it not be
    Code:
    for inNodes in connections:
        cmds.disconnectAttr([color=red]inNodes[/color],newMatName)
    Best regards,
    Vlado
    I only act like I know everything, Rogers.

    Comment


    • #3
      Heya Vlado

      Thanks for fast reply.

      Humh silly me that makes more sense than what I had. But atm for some reason it is still not working. The cmds.listConnections(c=1) still give me a lot more nodes that I need. I end up with error again.
      *
      Code:
      selected = cmds.ls(sl=1, mat=1)
      for materials in selected:
          connections = cmds.listConnections(c=1)
          newMatName = materials +'.diffuseColorAmount'
          for inNodes in connections:
              cmds.disconnectAttr(inNodes,newMatName)
      
      # Error: There is no connection from 'VRayMtl2.message' to 'VRayMtl2.diffuseColorAmount' to disconnect
      # Traceback (most recent call last):
      #   File "<maya console>", line 6, in <module>
      # RuntimeError: There is no connection from 'VRayMtl2.message' to 'VRayMtl2.diffuseColorAmount' to disconnect #
      *
      I know whats wrong with it I'm just not sure how to filter out the data I want

      This is my MR version of script which works last time I check...
      *
      Code:
      	mats = cmds.ls(sl=1)	
      	for mat in mats: # iterate
      	    conns = cmds.listConnections(mat, p=True) or [] # get connections
      	    cmds.editRenderLayerAdjustment('%s.%s'%(mat,'reflectivity'))
      	    cmds.editRenderLayerAdjustment('%s.%s'%(mat,'refl_color')) 
      	    for conn in conns: # iterate
      	    	try: #...
      	        	cmds.disconnectAttr(conn,'%s.%s'%(mat,'reflectivity')) # disconnect
      	        except: #...
      	        	pass  #...
      	        try:
      	        	cmds.disconnectAttr(conn,'%s.%s'%(mat,'refl_color')) # disconnect
      	        except:
      	        	pass
      *
      I know its not the prieatest one and TRY function hide a lot of issues but it does work (somehow)...

      I tried the same with vray and no luck
      Last edited by Dariusz Makowski (Dadal); 24-04-2013, 06:25 AM.
      CGI - Freelancer - Available for work

      www.dariuszmakowski.com - come and look

      Comment


      • #4
        What stops you from using the try/except code for the V-Ray code too??? You are probably getting errors with the MR code as well, but they are ignored because of the try/except.

        Best regards,
        Vlado
        I only act like I know everything, Rogers.

        Comment


        • #5
          Well that's the tricky weird think. When I tried try/pass it didnt work either.It execute the scripts, connection still stays and nothing happenz. I need to retest it another 10x see if I can come up with some "Creative" way of fixing it

          Thanks for help Vlado.
          CGI - Freelancer - Available for work

          www.dariuszmakowski.com - come and look

          Comment

          Working...
          X