Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Excuse me, how to change the following code to loop processing?

4 REPLIES 4
Reply
Message 1 of 5
2368457978
333 Views, 4 Replies

Excuse me, how to change the following code to loop processing?

2368457978
Enthusiast
Enthusiast

def USVZ():
inputs = cmds.listConnections('.userVectorZ', source=True, destination=False, plugs=True)
if inputs:
input = inputs[0]
cmds.disconnectAttr(input,'.userVectorZ')


Now the code can only process a single object. I want to process all the objects I selected. How should I modify them?



0 Likes

Excuse me, how to change the following code to loop processing?

def USVZ():
inputs = cmds.listConnections('.userVectorZ', source=True, destination=False, plugs=True)
if inputs:
input = inputs[0]
cmds.disconnectAttr(input,'.userVectorZ')


Now the code can only process a single object. I want to process all the objects I selected. How should I modify them?



4 REPLIES 4
Message 2 of 5
Kahylan
in reply to: 2368457978

Kahylan
Advisor
Advisor

Hi!

 

This should do the trick:

def USVZ():
    inputs = cmds.listConnections('.userVectorZ', source=True, destination=False, plugs=True)
    if inputs:
        for input in inputs:
            cmds.disconnectAttr(input,'.userVectorZ')

 

I hope it helps!

0 Likes

Hi!

 

This should do the trick:

def USVZ():
    inputs = cmds.listConnections('.userVectorZ', source=True, destination=False, plugs=True)
    if inputs:
        for input in inputs:
            cmds.disconnectAttr(input,'.userVectorZ')

 

I hope it helps!

Message 3 of 5
2368457978
in reply to: Kahylan

2368457978
Enthusiast
Enthusiast
Unfortunately, he can't. My original code only changes the attributes of my last selected object, not all selected attributes. The function I want is similar to this one. I know less about Python, cmds.ls(sl=True,dag=True) should use this code, but I don't know how to embed it. def lwKet():
guidesSelection = cmds.ls(sl=True,dag=True)
for each in guidesSelection:
cmds.setKeyframe(each + ".lwgt")

Unfortunately, he can't. My original code only changes the attributes of my last selected object, not all selected attributes. The function I want is similar to this one. I know less about Python, cmds.ls(sl=True,dag=True) should use this code, but I don't know how to embed it. def lwKet():
guidesSelection = cmds.ls(sl=True,dag=True)
for each in guidesSelection:
cmds.setKeyframe(each + ".lwgt")
Message 4 of 5
Kahylan
in reply to: 2368457978

Kahylan
Advisor
Advisor

I guess this is what you want then:

 

def USVZ():
    objects = cmds.ls(sl = True, dag = True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorZ'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i,'{0}.userVectorZ'.format(o))

 

0 Likes

I guess this is what you want then:

 

def USVZ():
    objects = cmds.ls(sl = True, dag = True)
    for o in objects:
        inputs = cmds.listConnections('{0}.userVectorZ'.format(o), source=True, destination=False, plugs=True)
        if inputs:
            for i in inputs:
                cmds.disconnectAttr(i,'{0}.userVectorZ'.format(o))

 

Message 5 of 5
2368457978
in reply to: Kahylan

2368457978
Enthusiast
Enthusiast
He is effective. Thank you very much for solving my big trouble.

He is effective. Thank you very much for solving my big trouble.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report