Python Maya question


#1

Hi
I am a complete beginner in python so this might be something basic but so far it just seems really weird to me…

anyway this is my script so far. I am trying to copy the global reflection and refraction node trees over to selected shaders while also renaming them removing the global part and adding the name of the shader I am copying it to.

The weird part is that if I run through everything except the connections it works but if I run through the whole script the renaming only renames the first node. So it is like something is up with my loop but only when I also try to run with the following parts. Any tips are appreaciated:)

import maya.cmds as mc

shaders= mc.ls(sl=1)

for each in shaders:
    #duplicate refl/rough networks
    duplicateReflShd = mc.duplicate ('remapValue_Srf_Refl_global', 'remapValue_Srf_Rough_global', un=True) 
    
    #rename reflshaders
    for x in duplicateReflShd:
        name = x.split("_")
        name.remove(name[-1])
        name="_".join(name)
        newname = name + "_" + each
        mc.rename(x, newname)
        #print newname     
    
        # connect refl shader to surface shader
	mc.connectAttr ("remapValue_Srf_Refl_" + each + ".outValue", each + ".refl_weight", force=True)
	mc.connectAttr ("remapValue_Srf_Rough_" + each + ".outValue", each + ".refl_roughness", force=True)

#2

Hi buddy, just try looping from 5-8 line and you are all good to go. Hope this helps :slight_smile:

Regards,
SixTad


#3

Hi buddy, a quick update, did it work?

Regards,
SixTad


#4

Hello,

I really appreciate your work

You can try connecting from 5 to 8 lines and you are all suitable to go.

Regards,
Softpulse Infotech


#5

Really a problem with those lines


#6

I have been looking for this since a very long time.


#7

Keep sharing such Informative posts.


#8

i will keep my eye on this,