Installing Scripts

Script File Locations

Lua scripting is ready to use right out of the box in Strata Design 3D CX. Scripts can even be set to run automatically during application startup. Add-ons may be supplied by Strata or third parties in the form of scripts, either via an installer that automatically installs all dependencies or as a package of files that you need to manually copy to the right places.

There are several locations where script files can be placed depending on whether you want to share them with all users on a machine or just use them with your own login. These locations differ based on which operating system you're running.

    • Mac OS X
      • Per-user Scripts
        • A folder named "Scripts" within the "Strata Design 3D CX 60" folder in the "Application Support" folder within the "Library" folder of the user home folder. ( /Users/<user>/Library/Application Support/Strata Design 3D CX 60/Scripts )
      • Shared Scripts
        • A folder named "Scripts" within the "Strata Design 3D CX 60" folder in the "Application Support" folder within the "Library" folder of the system drive. ( /Library/Application Support/Strata Design 3D CX 60/Scripts )
    • Windows XP
      • Per-user Scripts
        • A folder named "Scripts" within the "Strata Design 3D CX 60" folder in the "Application Data" folder within the "Library" folder of the user home folder. ( C:\Documents and Settings\<user>\Application Data\Strata Design 3D CX 60\Scripts )
      • Shared Scripts
        • A folder named "Scripts" within the "Strata Design 3D CX 60" folder in the "Application Data" folder within the "Library" folder of the "All Users" folder. ( C:\Documents and Settings\All Users\Application Data\Strata Design 3D CX 60\Scripts )
    • Windows Vista
      • Per-user Scripts
      • Shared Scripts

Scripts added to any of the "Scripts" folder locations can be loaded using the Lua require function. More complex add-ons can be packaged in a subfolder with additional files. For example an add-on named "Stuff" might be packaged as a folder named "Stuff" containing at least one Lua script file named "Stuff.lua". Using the Lua command:

require 'Stuff'

would find find and load the script from within the subfolder of the same name.

Automatic Scripts

Normal scripts should be left in the "Scripts" folder, but scripts designed to run automatically at program startup should be placed in a subfolder named "Autoload" within one of the "Scripts" folder locations. Avoid placing anything other than the auto loading script itself in that folder.

A Lua add-on could be designed as a self-contained module within a subfolder installed in the Scripts folder.

A script designed for the automatic folder is loaded and run early during program initialization. To be a good citizen and to ensure that everything is initialized before the script modifies any interface elements, such as adding to the scripting menu, it's common practice to register a callback function for execution after the program is fully initialized.

An Example Auto-loaded Script

local function DoThisLater (printFunction)

-- This print will happen much later after the program is fully initialized,

-- and since the console is initialized by then you'll see the result there.

printFunction( "I'm initializing now." )

--

-- Do all of your real work right here.

--

end

-- This print statement will execute right away at load time,

-- but you won't see the output in the scripting console because

-- that isn't initialized until after all the autoload scripts

-- have had a chance to execute. On the Macintosh this first

-- print statement will appear in the system console instead.

-- On Windows the output will just be lost.

print( "I'm loading now." )

-- Take note of the very subtle use of curly braces in the following function call.

-- We're calling this function with a single table argument as allowed by Lua.

RegisterAutoloadFinalizer { DoThisLater, print }

The RegisterAutoloadFinalizer function is only defined within the environment of this auto-loaded script. You shouldn't call it again in any callback functions or after the initial load and execution of your script. The use of a single table argument to this function is an anachronism held over from earlier versions of the program, but it's here to stay. If you don't like the call syntax using just the table braces you're free to add extra parenthesis as well.