UI Creation class


#1

I’m trying to create a script to reset the pan camera values. The UI is being displayed in the window but when I click on the reset button I get the following error.

Error: global name ‘whichCam’ is not defined

Traceback (most recent call last):

File “C:/Users/Nikhil/AppData/Local/Temp/MayaCode.py”, line 10, in reSet

self.panelwf = mc.getPanel(withFocus=True)

NameError: global name ‘whichCam’ is not defined

teh code I’m trying to implement is:


class pointBlast:
    def __init__(self):
        #get Cameras in the scene
        self.panelwf = mc.getPanel(withFocus=True)
        print(self.panelwf)
        self.whichCam = mc.modelPanel(self.panelwf, query=True, camera=True)
        print(self.whichCam)
        self.whichCamShape = mc.ls(self.whichCam, dag=True, allPaths=True, shapes=True)

        self.cameras = mc.ls(cameras=True)

        #create a window
        self.winname = ("CPWin")
        if mc.window(self.winname, query=True, exists=True):
            mc.deleteUI(self.winname)
        self.changewindow = mc.window(self.winname, title="PanCam Tool", widthHeight=(350,250), resizeToFitChildren=True, sizeable=True)
        mc.columnLayout()
        mc.frameLayout(label="Zoom Options",width= 350)
        mc.columnLayout()
        self.camList = mc.optionMenuGrp(self.whichCam, label="Camera To Zoom",columnAlign= (1,'left'))
        print(self.camList)
        mc.menuItem(label=self.whichCamShape[0])
        for i in self.cameras:
            mc.menuItem(label = i)

        mc.setParent('..')
        self.x = mc.floatSliderGrp(label="X",field=True,step=0.000001,minValue=-1.0,maxValue=1.0)

        self.y = mc.floatSliderGrp(label="Y",field=True,step=0.000001,minValue=-1.0,maxValue=1.0)

        self.z = mc.floatSliderGrp(label="Z",field=True,step=0.000001,minValue=-1.0,maxValue=1.0)

        self.pointBlastOption = mc.checkBox(label="camPan On/Off", value=0 )
        mc.columnLayout()
        mc.button(label="Reset",width= 100,height = 20,command=reSet)

        mc.showWindow(self.changewindow)


    def reSet(self, *args):
        # This proc resets the values back to 0, and 1 for the zoom
        self.resetCam = mc.optionMenuGrp(self.whichCam, query=True, value=True)
        print(self.resetCam)
        mc.setAttr(self.resetCam + ".panZoomEnabled", 0)
        mc.setAttr(self.resetCam + ".horizontalPan", 0)
        mc.setAttr(self.resetCam + ".verticalPan", 0)
        mc.setAttr(self.resetCam + ".zoom", 1)


        mc.floatSliderGrp(self.x,e=True,value=0)
        mc.floatSliderGrp(self.y,e=True,value=0)
        mc.floatSliderGrp(self.z,e=True,value=1)






pointBlast()




I have assigned the whichCam variable but still it is mentioning global name whichcam not defined.please guide me where I’m going wrong