The querry problem

40 views
Skip to first unread message

sumant shenoy

unread,
Mar 18, 2018, 11:10:15 PM3/18/18
to Python Programming for Autodesk Maya
hey every 
i am trying to write a ui class and the trying to querry it from the instance that i created but i keep on getting error here is an example please let me know if what i am trying to do is possible 


save this in C:\Users\u-user\Documents\maya\2016\scripts

## -*-coding:UTF-8-*
##Test
import os
import maya.mel as mel
import maya.cmds as cmds 
UIElements={}
class VgsRigTools:
    def __init__(self,WndNme,fml,width,height):        
        self.WndNme=WndNme
        self.fml=fml
        self.wdh=width
        self.hgt=height
        if cmds.window(self.WndNme,exists=True):
            cmds.deleteUI(self.WndNme)       
        UIElements["windowName"]=cmds.window(self.WndNme,t=self.WndNme,mxb=False,mnb=False,sizeable=True,w=self.wdh,h=self.hgt)
        UIElements["Fma"]=cmds.formLayout(self.fml,w=self.wdh,h=self.hgt)
        cmds.showWindow(self.WndNme)
    def Button(self,btnName,width,height,top,left):
        self.btnName=btnName
        self.btnWdt=width
        self.btnHgt=height
        self.btnTop=top
        self.btnLft=left
        UIElements["btnA"]=cmds.button(l=self.btnName,w=self.btnWdt,h=self.btnHgt,p=self.fml) 
        cmds.formLayout(self.fml,e=True,af=[(UIElements["btnA"],"top",self.btnTop),(UIElements["btnA"],"left",self.btnLft)])
    def chkBox(self,chkName,chkTop,chkLft):
        self.chkName=chkName
        self.chkTop=chkTop
        self.chkLft=chkLft
        UIElements["ChkA"]=cmds.checkBox( label=self.chkName )
        cmds.formLayout(self.fml,e=True,af=[(UIElements["ChkA"],"top",self.chkTop),(UIElements["ChkA"],"left",self.chkLft)])
                
and then i tried the below script from maya  but i was not able to querry the check box


from ClassTest import VgsRigTools
vrt=VgsRigTools
vrt=VgsRigTools('RigTools','RigLayout',400,100)
vrt.Button('ButtonA',50,20,10,0)
chkBx=vrt.chkBox('chktst',30,300)
cmds.checkBox(chkBx,q=True,v=True)
vrt.Button('ButtonB',50,20,50,0)


this is the error i got 
# Error: RuntimeError: file <maya console> line 6: No object name specified.
i know why i am getting the error but i have no idea how to fix it any help would be deeply appreciated 

Thank you 
sumanth :D

Justin Israel

unread,
Mar 19, 2018, 12:23:04 AM3/19/18
to python_in...@googlegroups.com
I don't full understand the intent of the design, but I can tell you why it is failing and how to fix the specific error. Your chkBox() method does not return anything, but you are expecting it to return the name of the checkbox UI item, so that you can pass it to cmds.checkBox().

This would be the simplest fix for your code:

def chkBox(self,chkName,chkTop,chkLft):
    # ... the rest of the code
    return UIElements["ChkA"]

Now your chkBox() method returns the name of the checkbox.

I don't really understand the purpose of the global UIElements dictionary when you are already storing everything on the instance of your VgsRigTools class. The global is just an easy way to cause you problems down the line. If you were to do:

vrt1 = VgsRigTools('RigTools1','RigLayout1',400,100)
vrt2 = VgsRigTools('RigTools2','RigLayout2',400,100)

The second instance would overwrite the "windowName" and "Fma" keys in your global dictionary, but still create two windows.
 

Thank you 
sumanth :D

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/b3c698ac-8e6d-4468-b697-233be2cecb27%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Israel

unread,
Mar 19, 2018, 12:24:50 AM3/19/18
to python_in...@googlegroups.com
Yikes. My markdown plugin seems to have made strange formatting out of that code snippet:

sumant shenoy

unread,
Mar 19, 2018, 1:26:48 AM3/19/18
to Python Programming for Autodesk Maya
Hi justin 
Thank you for the reply worked perfectly .i am kinda new to classes and kinda understanding its importance now .the basic idea is create a master class for gui creation so that i can set the name and postions 
of the buttons,windows,layouts,etc easily so every time i dont have to write the same thing over an over just a personal project too see how far i can take it to make my work more faster :D.thanks for the global dictionary tip too will keep it in mind 
for the future  also

Warm Regards
sumanth :D
Reply all
Reply to author
Forward
0 new messages