Assigning parts to instance variables
Scripts that frequently reference one or more parts by name are also good candidates for performance improvement.
When you paste a get or set selector, you reference a part by name. Typically, the code looks something like this:
(self subpartNamed: 'Apply Push Button')
enabled: <your expression here>.
If you reference a part frequently, you can improve performance by assigning the part to an instance variable.
First, create an instance variable in your part class, such as applyPushButton for the example above. Switch to the Script Editor, make sure no scripts are selected, and modify the class definition by adding applyPushButton (or whatever name you would like to use) to the list of instanceVariableNames. Select Save from the pop-up menu to save your change and recompile the class definition.
Second, select
, the Subpart Features Syntax tool.
Select the part you want to reference, Apply Push Button in this example, and select Assign to instance variable from the pop-up menu of the Subparts list.
Your window will look like this:
Next, a window is displayed that lists all of the instance variables for the class. Select the instance variable you want to use when you refer to the part, which is applyPushButton in this example. When you select OK, the part is assigned to the instance variable.
Now, when you paste get and set selectors for the part, the instance variable you assigned is used, and performance improves. In this example, the code now looks like this:
applyPushButton enabled: <your expression here>.
As you can see, you also get the added benefit of more readable code.
Last modified date: 06/11/2018