Q:

Referencing results with Python in Maya

I've been working on a script in Maya that will allow me to work with the cameras without having to go into the Attribute Editor all the time. Currently I have a menu with a menu item and within that menu item I have the check box flag active as well. When the check box button is toggled it runs a command that prints out the result of the check box. What I would like to do is have an if statement that will toggled the dof attribute in any camera but does this by reading the result of the checkbox flag. I know how to properly work with if statements and also find the correct camera, but I don't know how to query the result. Some of the script is below and line four, the if statement, is where I am having issues. Thank you for your help!
#Window Functions go here

def dofToggle(self):
    print(cmds.menuItem("dof", q=1, cb=1))

    # query the result
    if (cmds.menuItem("dof") == 1):
        cmds.setAttr(camera1.dof=True)

    # window settings go here
    if (cmds.window("Camera Tools", exists=True)):
        cmds.deleteUI("Camera Tools")

    cmds.window(title="Camera Tools", nestedDockingEnabled=True, rtf=True, sizeable=False, menuBar=True, menuBarResize=True, menuBarVisible=True)

    cmds.menu(label="dof")

    cmds.menuItem("dof", label="on/off", checkBox=True, command=dofToggle)

A:

To get the DOF of the camera use this command:
import maya.cmds as cmds
print(cmds.camera('cameraShape1', q=True, dof=True))

To disable the DOF of the camera use this command:
cmds.camera('cameraShape1', e=True, dof=False)

So your if statement should look like this:
if(cmds.camera('cameraShape1', q=True, dof=True) == 1):
    cmds.camera('cameraShape1', e=True, dof=False)

