Using the edit flag in Python
 
 
 

When you perform an action on an object in the Maya user interface, you’re using Maya commands to change the attributes of selected objects. You can use the same Maya commands explicitly to edit the attributes of objects in the scene.

Some Maya commands take an edit flag that allows you to make changes to the attributes of an object. The edit flag is used in conjunction with other flags to specify which attributes to change.

To edit the attributes of an existing object

  1. Create a NURBS torus by typing the following:
    testVarName=cmds.torus(r=1, axis=(0,1,0) )

    The axis flag specifies the initial orientation of the torus. Geometry creation commands return the name of the created object, so you can easily refer to the object by storing the name of the object as a variable.

    NoteMost creation commands return the name of the created object as a return value. This value can be stored as a variable to refer to the object at a later time. This is especially useful when referring to controls within a user interface.
  2. Deselect the torus using a Python command.
    cmds.select(deselect=True)
  3. Edit the height ratio of the named torus by typing the following:
    cmds.torus(testVarName,edit=True, hr=0.4)

    When the edit flag is set to True, the command is put in edit mode. When in edit mode, all flags within the brackets of the command now change the attributes of the specified object.

    NoteThe edit flag does not need to be the first flag in a command. It is a named argument and can be positioned anywhere within the command after the positional arguments.