Share

Lua in Netfabb

Supported Lua functionality

Netfabb generally supports version 5.1 of the Lua language definition, see http://www.lua.org/manual/5.1/.

From the Lua 5.1 standard Netfabb supports the core language specification and a selection of libraries.

Lua library Supported Comment
Base Yes, with exceptions Some exceptions:

dofile: no, use system:executescriptfile()

print: no, use system:log()
Coroutine manipulation Yes
Modules No Use system:executescriptfile()
String manipulation Yes
Table manipulation Yes
Mathematical functions Yes
Input and output facilities No
Operating System facilities No
Debug library No [Desktop Automation] provides a debugger window.

Back to top

General Lua syntax

Netfabb's functions are included through Lua's basic object interface. While not delivering some of the more sophisticated techniques like creating inheritances of classes, there is enough functionality to create a good interface for 3D-mesh handling. As a rule, all properties of object instances can be used like generic variables in the code. A simple access through object.property is sufficient. Object methods are handled slightly differently, they are characterized by a colon, making the general syntax be:

result = object:method (param1, param2, param3) -- a generic method call

Back to top

API scopes

Netfabb's Lua capabilities are split into scopes. In the documentation, the different scopes are indicated with these tags where necessary:

[Desktop Automation][Slices]

Important: Scopes cannot be crossed over. Although objects and their methods and functions may appear in more than one scope, they are independent and cannot interact. For example, while geometry on a 3D platform cannot be sliced and have its result added back to the project tree (to the Slicing section), it is possible to slice geometry from the current 3D platform, process the results, and save them to slice files, and it is also possible to run a script in Slicing that loads 3D geometry, slices it, and adds the results to the project tree.

Back to top

[Desktop Automation]

Scripts are accessed through the Lua script library, located at Prepare > Run script > Run Lua script, where they are loaded, saved, edited, and run. A syntax checker and a debugger is available. Scripts are not required to work on content currently loaded in Netfabb and may even load, manipulate, and save an arbitrary FABBPROJECT file that is entirely independent from what is currently loaded for work by the user. Typically, however, a script targets content already loaded.

The Netfabb executable provides two Lua-related command-line options:

/startluascript="path\to\script.lua"

This executes the referenced script immediately after startup of Netfabb. The path is expected in relation to the location of the Netfabb executable, so, typically something like C:\Program Files\Autodesk\Netfabb 2026\.

/terminateafterlua

This option only works in conjunction with the option above and shuts down Netfabb after the referenced script has terminated. The option also causes Netfabb to bypass possible startup or warning-before-closing dialogs, like for savefile recovery or for saving before closing.

Note that this does not constitute a truly headless operation. Sufficient graphics display capabilities are still required even if all scripted loading, processing, and saving happens in memory.

Back to top

[Slices]

In the Slices project tree section, Lua automation effectively works as a freely programmable command. For example, instead of using the single Offset command to generate a single new slice stack, applying a Lua script may facilitate almost arbitrary complexity of processing for the selected stack. Select a slice stack (or multiple) and choose Prepare > Run Lua script, also available from a slice stack's context menu in the project tree or the main view.

The default slice object corresponds to the selected slice stack. When multiple stacks are selected, the script is executed on each stack independently. Any changes must be returned to the project tree with a new slice using system:addslicetotree(), otherwise it just remains in memory until script termination. The script SliceCommanderLUAScript_example1_Offset demonstrates this.

To reiterate: The [Slicing] Lua automation scope only applies to operations on and in the Slicing section in the project tree. Slicing-related functions as such are not limited to this scope and can be used in scripts that provide other sources and/or targets for slice objects, such as through loading from and saving to the file system.

Back to top

Example scripts

Some scripts are already loaded into the Lua script library. The majority of example scripts, however, reside in the Examples folder in Netfabb's installation folder. To run these, choose to create a new script in the library and then browse for the script file in the file system ([Desktop Automation]). The [Slicing] script examples do not use the library and are always loaded newly from disk for execution on selected slice stacks.

Back to top

Was this information helpful?