Create Custom Module with Avizo Scripting Interface¶
Note
Reference: In <Avizo-installation-path>/doc/ directory there is a AvizoCodeBook.pdf. The title is “How to use Avizo efficiently and how to extend it”. This is your reference.
Avizo script object¶
Scripting of Avizo is done by writing text files in the Tcl language. The magic cookies capabilities of Avizo rely on a special header that has to be included in all script files:
# Amira-Script-Object V3.0
Once this line is added to a file Avizo will recognize it as a script object and after loading it it will be added to the object pool with a blue icon.
Create Custom Module¶
To create a custom module in Avizo, we need to write a script which can do our computation for us.
A typical .srco file look like this:
# Amira-Script-Object V3.0
$this proc constructor {} {
$this newPortConnection CastField HxCastField
$this newPortButtonList doit 1
$this doit setLabel 0 "DoIt"
}
$this proc compute {} {
if { ![$this doit wasHit 0] }
{
return
}
set inputData [$this data source]
if { $inputData == "" }
{
echo "Please connect to a data object"
return;
}
In order to make this script accessible in the Avizo interface we need to write a .rc file which goes together with the script. Usually the above script is saved with extension .srco in <Avizo-installation-path>/share/script-objects/ directory. Also the .rc file should be saved in this directory.
The .rc file will tell Avizo the name of our module, its input data type and the category where the script appears in the Avizo user interface after righ-mouse-click on our input data object.
A typical .rc file look like this:
module -name "YourModuleName" \
-package "hxscriptobj" \
-category "Compute" \
-proc {
set mod [[create HxScriptObject] setLabel YourModuleLabel]
$mod script setValue $AVIZO_ROOT/share/script-objects/yourscriptname.scro
$mod fire
$mod data connect $PRIMARY
}
-check { [$PRIMARY primType] == 3 } \
Here you set your module to be inside “Compute” category, and the data source accepts a type “3” datatype (0 = bytes, 1 = 16-bit signed integers, 2 = 32-bit signed integers, 3 = 32-bit floating point values, 4 = 64-bit floating point values, 7 = 16-bit unsigned integers.)
Use your module¶
After you create two files (.scro and .rc), and copied them to <Avizo-installation-path>/share/script-objects/ directory, restart Avizo, the new module will be loaded by Avizo automatically and ready for you to use.
Right click on any empty space, choose Compute->YourModuleLabel, your module will appear as a blue color-coded module. Connect an input data source, and click the “DoIt” button to execute the module.
Notice this module has a Restart button, followed by a script object path. This interface makes it easy to debug/edit your script object and re-load the script on-the-fly, no need to restart Avizo.
What to do next¶
Take a look at the Avizo Code Book, lots of cool stuff there! Create some modules!