Speeding up a Mass Ranges Script

You may have a script which defines a lot of mass ranges and the colors and sizes for each atom type. One of the things that makes this script a little slow is that Apex will redraw the screen live with each change to the graphics state, even though that really isn’t useful until the whole script is over.

To make this script go faster, use the ‘updating atomtypes’ property of an Apex document — while this setting is false, Apex will avoid recalculating all the mass ranges, which saves a bit of time if you start to get a lot of them.

Additionally, you can turn off redraws in the window using the ‘doing redraw’ property of a window — while this is false, the window contents won’t be redrawn.

Be sure to turn these two properties back on when you are done with a script action. Here’s an example script using these two properties:

to setAtomtypeProps(typeIndex, typeColor, typeSize, typeName)
tell application “Apex”
set the color of atomtype typeIndex of document 1 to typeColor
set the size of atomtype typeIndex of document 1 to typeSize
set the name of atomtype typeIndex of document 1 to typeName
end tell
end setAtomtypeProps
tell application “Apex”
activate

set doing redraw of window 1 of document 1 to false
set updating atomtypes of document 1 to false

if ((count mass ranges of document 1) > 0) then
delete every mass range of document 1
end if
make new mass range with properties {name:”Al”, lower limit:13.38, upper limit:13.84, atomtype:4} in document 1
make new mass range with properties {name:”Fe”, lower limit:26.82, upper limit:27.34, atomtype:1} in document 1
make new mass range with properties {name:”Ni”, lower limit:28.88, upper limit:29.26, atomtype:2} in document 1
make new mass range with properties {name:”Ni”, lower limit:29.860001, upper limit:30.24, atomtype:2} in document 1
make new mass range with properties {name:”Ni”, lower limit:30.84, upper limit:31.26, atomtype:2} in document 1
make new mass range with properties {name:”Cu”, lower limit:31.379999, upper limit:32.32, atomtype:3} in document 1
make new mass range with properties {name:”Cu”, lower limit:32.400002, upper limit:33.139999, atomtype:3} in document 1
make new mass range with properties {name:”Cu”, lower limit:62.66, upper limit:64.5, atomtype:3} in document 1
make new mass range with properties {name:”Cu”, lower limit:64.660004, upper limit:66.5, atomtype:3} in document 1
set updating atomtypes of document 1 to true
end tell
setAtomtypeProps(1, {0, 0, 65535}, 0, “Fe”)
setAtomtypeProps(2, {0, 65535, 0}, 1, “Ni”)
setAtomtypeProps(3, {65535, 0, 0}, 1, “Cu”)
tell application “Apex”
set doing redraw of window 1 of document 1 to true
end tell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: