Python code doesn't work

Python code doesn't work

2368457978
Enthusiast Enthusiast
432 Views
3 Replies
Message 1 of 4

Python code doesn't work

2368457978
Enthusiast
Enthusiast

Hello, everyone, I want to control parameters through Python. Why is it useless? Is there a problem with my script?036676be27859111bdf7f7d405778c7.png

def yetivision():
    mod = cmds.ls(sl=True, dag=True)
    for each in mod:                
        vision=int(cmds.checkBox('yetiSubdivision', q=1, v=1))    
        cmds.setAttr(each + ".yetiSubdivision",vision)                                                             

 

def yetiset_name():
	name=str(cmds.textFieldGrp('yetiUVSetName', q=1, text=1))
	mod = cmds.ls(sl=True, dag=True)
	for each in mod:
		cmds.setAttr(each + ".yetiUVSetName",name)	
				
								
cmds.checkBox('yetiSubdivision',*args:SubdIter(), w=100, h=30, v=0, label="yetiSubdivision")

cmds.textFieldGrp('yetiUVSetName', w=300, h=30)
cmds.button("O K",w=60, bgc=(0.4, 0.2, 0.3), h=30, c="yetiset_name()")
															

 

0 Likes
Accepted solutions (1)
433 Views
3 Replies
Replies (3)
Message 2 of 4

jmreinhart
Advisor
Advisor
def yetivision():
    mod = cmds.ls(sl=True, dag=True)
    for each in mod:                
        vision=int(cmds.checkBox('yetiSubdivision', q=1, v=1))    
        cmds.setAttr(each + ".yetiSubdivision",vision)                                                             

def yetiset_name():
	name=str(cmds.textFieldGrp('yetiUVSetName', q=1, text=1))
	mod = cmds.ls(sl=True, dag=True)
	for each in mod:
		cmds.setAttr(each + ".yetiUVSetName",name)	
				
								
cmds.window( title='Gradient Control For OptionVar')
cmds.columnLayout()
cmds.checkBox('yetiSubdivision', w=100, h=30, v=0, label="yetiSubdivision")
cmds.textFieldGrp('yetiUVSetName', w=300, h=30)
cmds.button("O K",w=60, bgc=(0.4, 0.2, 0.3), h=30, c="yetiset_name()")
cmds.setParent( '..' )
cmds.showWindow()

I fixed the syntax error by deleting the "args" thing you had. Not sure what you were intending to do with that.

I also made an actual window for the tool so it doesnt get added to the current window.

def yetivision isn't getting called but I don't know how you wanted to connect it to the UI.

 

If you have other problems it would help if you were more specific, like say what the behavior you want that you aren't getting.

0 Likes
Message 3 of 4

2368457978
Enthusiast
Enthusiast

I hope to open and close yetiSubdivision by clicking checkBox, fill in the name of the set by textFieldGrpUI and click OK to update the properties under the shape of the property panel in real time.

This is an attribute execution command.

setAttr "pSphereShape1.yetiSubdivision" 1;
setAttr "pSphereShape1.yetiSubdivision" 0;

setAttr -type "string" pSphereShape1.yetiUVSetName "2";
setAttr -type "string" pSphereShape1.yetiUVSetName "aaa";

 

0 Likes
Message 4 of 4

jmreinhart
Advisor
Advisor
Accepted solution
def yetivision(vision):
    mod = cmds.ls(sl=True, dag=True)
    print mod
    for each in mod:      
        if cmds.objExists(each + ".yetiSubdivision"):              
            cmds.setAttr(each + ".yetiSubdivision",vision)                                                             

def yetiset_name():
	name=str(cmds.textFieldGrp('yetiUVSetName', q=1, text=1))
	mod = cmds.ls(sl=True, dag=True)
	for each in mod:
	   if cmds.objExists(each + ".yetiUVSetName"):    
		    cmds.setAttr(each + ".yetiUVSetName",name, type = 'string')	
				
								
cmds.window( title='Gradient Control For OptionVar')
cmds.columnLayout()
cmds.checkBox('yetiSubdivision', w=100, h=30, v=0, label="yetiSubdivision", changeCommand = yetivision)
cmds.textFieldGrp('yetiUVSetName', w=300, h=30)
cmds.button("O K",w=60, bgc=(0.4, 0.2, 0.3), h=30, c="yetiset_name()")
cmds.setParent( '..' )
cmds.showWindow()

This script does that. 

 

Most widgets in MEL have a changeCommand flag that let you link the widget to a command, make sure you're checking the doc page for the commands, because a lot of this stuff is written there.

0 Likes