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][3S][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. All the main Lua commands can be accessed within the script. The includes the general Lua commands, however excludes the special Lua commands for 3S. Scripts do not have to work on content currently loaded in Netfabb and may in fact load, manipulate, and save an arbitrary FABBPROJECT file entirely independent from what is currently loaded for work by the user. Typically, however, a script is targeted at content already loaded. For this purpose, the variable tray is predefined with the current platform (and its LUATray object) which provides access to all meshes in the buildroom. In addition, the global variable netfabbapplication facilitates access to the trays of the currently running Netfabb application.

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

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

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

/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 Slices, Lua automation is applied to slice stacks like any other command. 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. In addition to the functions of [Desktop Automation], the default slice object corresponds to the selected slice(s). The script is executed on each selected slice. 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.

Back to top

[3S]

3S Lua functions are exclusive to 3S; likewise, non-3S Lua functions cannot be used in 3S.

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?