7.4 Procedure modes

A procedure consists of a series of steps that collect input from the user. The following topics are covered in this section:


7.4.1 Procedure example

Steps in a procedure are posted using the following methods:

  • getFirstStep

  • getNextStep

  • getLoopStep

The following types of steps are available for use in procedures:
  • AFXDialogStep. This step provides an interface to a dialog box.

  • AFXPickStep. This step provides an interface to allow picking entities in the viewport.

The following example shows how to write a simple, one-step procedure mode that uses a dialog box step. Subsequent examples will extend this example to show how to use more steps.

from abaqusGui import *
from plateDB import PlateDB

class PlateProcedure(AFXProcedure):

    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def __init__(self, owner):
    
        AFXProcedure.__init__(self, owner)
        
        self.cmd = AFXGuiCommand(
            self, 'Plate', 'examples')
        self.nameKw = AFXStringKeyword(
            self.cmd, 'name', TRUE)
        self.widthKw = AFXFloatKeyword(
            self.cmd, 'width', TRUE)
        self.heightKw = AFXFloatKeyword(
            self.cmd, 'height', TRUE)
        
    #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    def getFirstStep(self):
    
        self.cmd.setKeywordValuesToDefaults()
        db = PlateDB(self)
        return AFXDialogStep(self, db)


7.4.2 Procedure constructor

You begin writing a procedure mode by deriving a new class from AFXProcedure. In the body of the AFXProcedure constructor you must call the base class constructor and pass in the owner, which is the module or toolset GUI to which this procedure belongs. Optionally, you can pass in a value for the type of procedure. The default value for the type is NORMAL. The type defines what happens when a new procedure is activated while another procedure is currently executing.

The type of a procedure can be either NORMAL or SUBPROCEDURE. When a normal procedure is activated, it cancels any procedure that is currently executing. When a subprocedure is activated, it suspends a normal procedure or cancels another subprocedure. If a procedure is suspended, it resumes upon the completion of the subprocedure.

View procedures (for example, pan, rotate, and zoom) are special types of procedures that cannot be suspended. View procedures are always cancelled when another procedure is activated, and they always suspend any currently executing procedure when they are activated.

After you have derived a new class from AFXProcedure, you define the commands and keywords needed for the mode. The keywords are stored as members of the mode so that they can be accessed by steps. If you set registerQuery=TRUE in the AFXGuiCommand constructor, the mode will query the kernel object specified by the command when it is activated and automatically set the values of the command's keywords. For more information, see Keeping the GUI and commands up-to-date, Section 6.5.3. If there is no kernel object associated with your command (for example, when creating a new object), you can set the keyword values by specifying a default value in their constructor.

If you have a default object that you want to use to reestablish default values for a dialog box, you can use the mode’s registerDefaultsObject method to register an object whose values will be queried when the user presses the Defaults button in the dialog box. For more information, see Defaults objects, Section 6.5.15.

By default, dialog boxes are posted as modeless. You can post a dialog box as modal by calling self.setModal(TRUE). In most cases you set the modality only once in the mode; however, you can change the modality as often as needed by calling the setModal method in the getFirstDialog or getNextDialog methods. For more information, see Modal versus modeless, Section 5.2.


7.4.3 getFirstStep

You must always write the getFirstStep method for your mode. The getFirstStep method should return the first step of the mode. In Procedure example, Section 7.4.1, a pointer to the procedure is passed into the dialog box constructor. The dialog box will use this pointer to access the mode's keywords.

If you want the same default values to appear every time you post the dialog box, you must call the setKeywordValuesToDefaults() method before returning the dialog box, as shown in Procedure example, Section 7.4.1.


7.4.4 getNextStep

If your mode contains more than one step, you must write the getNextStep method in addition to the getFirstStep method. The previous step is passed into the getNextStep method so that you can determine where the user is in the sequence of steps and act accordingly. The getNextStep method should return the next step in the sequence, or it should return None to indicate that it has finished collecting input from the user. The following example, which is a modified version of the example in Procedure example, Section 7.4.1, illustrates how inputs are collected from the user in a series of three steps rather than just one:

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getFirstStep(self):

    self.cmd.setKeywordValuesToDefaults()
    self.plateWidthDB = None
    self.plateHeightDB = None
    db = PlateNameDB(self)
    self.step1 = AFXDialogStep(self, db)
    return self.step1
   
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def getNextStep(self, previousStep):

    if previousStep == self.step1:
        if not self.plateWidthDB:
            self.plateWidthDB = PlateWidthDB(self)
        self.step2 = AFXDialogStep(self, self.plateWidthDB)
        return self.step2
    
    elif previousStep == self.step2:
        if not self.plateHeightDB:
            self.plateHeightDB = PlateHeightDB(self)
        self.step3 = AFXDialogStep(self, self.plateHeightDB)
        return self.step3
        
    else:
        return None


7.4.5 getLoopStep

If you want your procedure to loop, you must write the getLoopStep method. The getLoopStep method is defined in the base class to return None, indicating that the mode will be run through a single time. You can redefine the getLoopStep method and return a step to which the procedure should loop back. The following example shows how you can make the procedure shown in the previous section loop back to the first step after it has completed the last step:

def getLoopStep(self):    
    return self.step1


7.4.6 AFXDialogStep

The AFXDialogStep class allows you to post a dialog box during a procedure. To create a dialog step, you must supply the procedure, a dialog box, and, optionally, a prompt for the prompt line. If you do not suppy a prompt, ABAQUS uses a default prompt of Fill out the dialog box title dialog. The following is an example of a dialog step in a single step procedure:

def getFirstStep(self):
    
    db = PlateDB(self)
    prompt = 'Enter plate dimensions in the dialog box'
    return AFXDialogStep(self, db, prompt)

In most cases a procedure will have more than one step. Since a procedure has the ability to back up to previous steps, you must write procedures that do not construct dialog boxes more than once during the procedure. You can prevent a procedure from constructing dialog boxes more than once by initializing procedure members and then checking the members during getNextStep, as shown in the following example:

def getFirstStep(self):
    
    self.plateWidthDB = None
    self.plateHeightDB = None
    db = PlateNameDB(self)
    self.step1 = AFXDialogStep(self, db)
    return self.step1
       
def getNextStep(self, previousStep):
    
    if previousStep == self.step1:
        if not self.plateWidthDB:
            self.plateWidthDB = PlateWidthDB(self)
        self.step2 = AFXDialogStep(self, self.plateWidthDB)
        return self.step2
            
    elif previousStep == self.step2:
        if not self.plateHeightDB:
            self.plateHeightDB = PlateHeightDB(self)
        self.step3 = AFXDialogStep(self, self.plateHeightDB)
        return self.step3
            
    else:
        return None