Activating a mode

A mode is usually activated by sending it a message with its ID set to ID_ACTIVATE and a type of SEL_COMMAND. This message causes the activate method of the mode to be called. For more information, see Targets and messages.

If you need to do any processing before a mode begins to collect input from the user, you can redefine the activate method. For example, you can check that the current viewport contains a part before beginning a mode that requires the user to pick something on a part, as shown in the following method:

    def activate(self):

        if getDisplayedObjectType() == PART:
            AFXForm.activate(self)
        else:
            showAFXErrorDialog(getAFXApp().getAFXMainWindow(),
                 'A part must be displayed in the \
                  current viewport.')

If you write your own activate (or deactivate) method, you must call the base class version of that method if no error conditions are encountered. The base class methods perform additional processing necessary to make the mode function properly.