System and file functions
[Desktop Automation]
Methods
Name | Syntax | Description |
---|---|---|
calculatemd5 | Md5 = system:calculatemd5(filename:String); | Calculates MD5 hash sum of a file |
checklibrary | Result = system:checklibrary(libname:String); | Checks for the desired library |
cleargarbage | system:cleargarbage(); | Calls the garbage collector |
create3mfimporter | Importer = system: create3mfimporter(FileName:String; SplitMeshes: Boolean; Name:String; Tray: TLUATray); | Create an importer for 3MF files. SplitMeshes specifies whether to import all parts as shells into one part. See 3mfImporter for details. |
create3mfexporter | Exporter = system:create3mfexporter(); | Create a new 3MF exporter object. See 3mfExporter for details. |
createcollisiondetector | Detector = system:createcollisiondetector(gridsize: Number); | Create a Lua collision detector object. See CollisionDetector for details. |
createdirectory | Result = system:createdirectory(dirname:String); | Creates a directory |
createformatteduuid | UUID = system:createuuid(); | Returns a UUID, formatted |
creategraph | Graph = system:creategraph(graphs:integer) | Creates a Graph object. Graphs is the number of individual graphs to be painted. |
createhistogram | Histogram = system:createhistogram() | Creates a Histogram object |
creategraphdrawer | Graphdrawer = system:creategraphdrawer() | Creates a Graph drawer object |
createlatticegenerator | Latticegenerator =system:createlatticegenerator(); | Creates a Latticegenerator object |
createmeshfaceselector | Meshfaceselector =system:createmeshfaceselector(); | Creates a Mesh face selector object |
createprimitivelist | List = system:createprimitivelist() | Create a list-object that contains all available primitives. See primitive section. |
createhexbaseplate | BaseplateMesh = system: createhexbaseplate(HoleCountX:Number, HoleCountY:Number, Radius:Number; Height:Number; WallThickness:Number); | Creates a hex baseplate mesh with a given number of holes in directions X and Y and a specific hole radius. Height defines the baseplate's thickness; wall thickness defines the thickness of material between holes. |
createimageprocessing | Ip = system:createimageprocessing(); | Creates an image processing object. |
createrectbaseplate | BaseplateMesh = system: createrectbaseplate(HoleCountX:Number, HoleCountY:Number; CellSizeX:Number; CellSizeY:Number; Height:Number; WallThickness:Number); | Create a baseplate with rectangles. The first two parameters define the number of holes, the next two the size of the holes and the last two the height of the baseplate and the wall thickness |
createreportgenerator | Result = system: createreportgenerator(Snapshot: LUAsnapshotcreator); | Creates a LUAReportgenerator, function call must have a snapshotcreator as an argument [Desktop Automation] |
createrotationgenerator | result=system:createrotationgenerator | Create a LuaRotationGenerator, which generates rotationsvector, which rotates a mesh to different positions |
createscreenshot | system:createscreenshot(width:Number, height:Number, options:JsonObject) | Create a screenshot of the current camera position, returns an Image Object. For the Options object, see Screenshot options JSON. [Desktop Automation] |
createsettingsgroup | Luasetting = system: createsettingsgroup() | Creates a Lua settings object. This is independent of the the Netfabb settings. [Desktop Automation] |
createsnapshotcreator | Result = system:createsnapshotcreator(); | Creates a LUASnapshotcreator. This is used by other objects to create a snapshot. [Desktop Automation] |
createstamper | Result = system:createstamper(); | Create a LUAStamper, to label meshes [Desktop Automation] |
createstringmap | Map = system:createstringmap() | Create a string map for key/value pairs |
createuuid | UUID = system:createuuid(); | Returns a UUID |
createvector3 | vector = system:createvector3; | Creates a LuaVector3 object |
createvector4 | vector = system:createvector4; | Creates a LuaVector4 object |
createzip | zipobject = system:createzip(zipfile:String) | Creates a new ZipObject. When used without zipfile parameter, it creates the object in memory only. |
directoryexists | Boolean = system:directoryexists(dirname:String); | Returns true when directory exists |
downloadurl | Result:Boolean = System:downloadurl(URL:String, name:String); | Tries to download a file via HTTP GET from URL and saves it as name . Returns TRUE if successful. |
excludepathdelimiter | String = system:excludepathdelimiter(inputstring:String); | Returns string excluding the system-specific path delimiter (at the end) |
executeapplication | Boolean or String = system:executeapplication(app:String, options:String, wait:Boolean, readstdout:Boolean); | Starts app application and waits until application ends (blocking). options (optional) are separated by blank. wait (optional) sets whether Netfabb waits (true, default) for the external application to finish execution. Readstdout tells the command to read the stdout of the called application. If the call fails false is returned, otherwise true will be returned if the readstdout flag is set to false (default), otherwise the output of the called application is returned as a string |
executescript | system:executescript(script:String, scriptname :String ); | Execute a string as a lua script. scriptname is the name to be associated with the script (needed for the Lua debugger). |
executescriptfile | system:executescriptfile(scriptname:String); | Executes another Lua script. Scriptname is the name of the Lua script on the filesystem. |
extractfileext | Filenameext = system:extractfilenameext(inputstring:String); | Returns the file name extension from a string |
extractfilename | Filename = system:extractfilename(inputstring:String); | Returns the filename only from a string |
extractfilepath | String = system:extractfilepath(inputstring:String; trailingpathdelimiter:bool) | Returns a string with the file path. If trailingpathdelimiter is true, the trailing path delimiter are included, otherwise they are omitted. |
fileexists | Boolean = system:fileexists(filename:String); | Returns TRUE when file exists |
formatarea | Result:String = system:formatarea(numval:number, digits:integer); | Returns numval , formatted with number of digits (optional) and trailing currently set area unit [Desktop Automation] |
formatlength | Result:String = system:formatlength(numval:number, digits:integer); | Returns numval , formatted with number of digits (optional) and trailing currently set length unit [Desktop Automation] |
formattraffic | Result:String = system:formatraffic(numval:number); | Returns numval as formatted byte string, e.g.: 3.4 kB [Desktop Automation] |
formatvolume | Result:String = system:formatarea(numval:number, digits:integer); | Returns numval , formatted with number of digits (optional) and trailing currently set volume unit [Desktop Automation] |
getallfilesindirectory | xmlfilelist = system:getallfilesindirectory (dirname:String, includesubdirectories:Boolean); | Returns an XML file with all files in a directory. includesubdirectories is an optional flag (true by default) to define whether to search subdirectories as well [Desktop Automation] |
getdatestring | date = system:getdatestring(); | Returns current date as a string |
getfileage | fileage = system:getfileage(filename:String); | Returns the Unix timestamp of a file's creation date |
getfilesize | Size = system:getfilesize(filename:String); | Returns the size of a file |
getrepeatscript | Value = system:getrepeatscript() | Returns the variable repeatscript. If the value is true, the script is executed again in the desktop Lua environment after the script ends. |
gettimestring | time = system:gettimestring(); | Returns current time as a string |
hideprogressdlg | System: hideprogressdlg(); | Hides the progress dialog created by system:showprogressdlg [Desktop Automation] |
hideprogressdlgcancancel | system:hideprogressdlgcancancel(); | Hides the progress dialog created by system:showprogressdlgcancancel, see also showprogressdlgcancancel, setprogresscancancel, progresscancelled [Desktop Automation] |
includepathdelimiter | String = system:includepathdelimiter(inputstring:String); | Returns string with system-specific path delimiter (at the end) |
inputdlg | system:inputdlg(Title:String, Label:String, Defaultvalue:String); | Creates a generic dialog for input of one (text) field as well as an OK and a Cancel button. OK returns whatever is currently written in the field (including the default value), Cancel always returns the default value. All fields are mandatory but can be empty. [Desktop Automation] |
log | system:log(logsting:String); | Logs logstring to current log output channel. See also: setloggingtooglwindow |
logtofile | system:logtofile(filename:String; timestamp: Boolean = true); | Log Standard Output to file. If timestamp is false to time information is printed. The default value is true. |
messagedlg | system:messagedlg(message:String); | Show a message dialog [Desktop Automation] |
openurl | system:openurl(url:String) | Open a URL in the default browser [Desktop Automation] |
openzip | system:openzip(file:String; password:String) | Open an existing ZIP file for reading. Returns an instance of ZipObject. The password parameter is optional and is used to decrypt password protected archives. [Desktop Automation] |
passworddlg | system:passworddlg(Label:String, password:String); | Creates a dialog for inputting a password, hiding the input [Desktop Automation] |
progresscancelled | system:progresscancelled(); | Returns "true" if a progress dialog shown with "system:showprogressdlgcancancel" is cancelled. It's up to the LUA developer to cancel whatever operation the dialog is shown for, See also: hideprogressdlgcancancel, setprogresscancancel, showprogressdlgcancancel [Desktop Automation] |
registerextension | system:registerextension(Extension:String, LocalizationId:String, Filter:String, DescriptionLocalizationId:String) | Register a new extension to Netfabb. extension is the extension without the period ("stl"). LocalizationId is the translated string describing the filter ("STL File"). filter is the filter to apply ("*.stl").[Desktop Automation] |
safealphanumeric | Result = system:safealphanumeric(inputstring:String, withpunctuationsigns:Boolean); | Checks and returns a string for standard alphanumeric signs. withpunctuationsigns set to true also allows also punctuation (.,- ) |
setcameraorientation | system:setcameraorientation(new_orientation) | Sets the camera orientation like the viewcube in the UI. new_orientation can be one of the camera globals (see Constants ) |
setloggingtooglwindow | system:setloggingtooglwindow(yesno:Boolean); | Pipes all logging output to the OGL warning window. [Desktop Automation] |
setprogress | system:setprogress(percent:Number, message:String, translate:Boolean); | Set the progress dialog with a progress value and a message. translate is optional, selects whether the message should be translated (true if omitted) [Desktop Automation] |
setprogresscancancel | system:setprogresscancancel(percent: Number; message: String); | Set the progress value and a message for the progress dialog which can be cancelled, see also: showprogressdlgcancancel, hideprogressdlgcancancel, progresscancelled [Desktop Automation] |
setrepeatscript | system:getrepeatscript(value: Boolean) | Sets the variable repeatscript. If the value is true, the script is executed again in the desktop Lua environment after the end of the script. |
shellexecute | system:shellexecute(cmd:String, param:String, doWait:Boolean, Show:Boolean, directory:String) | Executes the shell command in cmd with the parameters in param .doWait : When true , waits until the command has finishedshow (default false ): set to true for the launched application to be visible. directory : Change to this directory for command executionExample/note for windows: system:shellexecute("cmd", "/c copy cube.stl test.stl", true, true); Note: Requires full path to the executable, otherwise Netfabb looks for it in its own installation folder. Variable resolution is not supported. |
showdirectoryselectdialog | Directorystring = system: showdirectoryselectdialog(allowcreate:Boolean, performCreate:Boolean, prompt:Boolean) | Opens a directory selection dialog.Allowcreate : An edit box to type in the name of a directory that does not exist. This option does not create a directory automatically.performCreate : Used only in combination with allowCreate . Creates the directory if it doesn't exist.prompt : Used only in combination with allowCreate . Displays a message box to informs when the entered directory does not exist and asks whether the directory should be created. Choosing OK creates the directory if performCreate is present; otherwise, the directory is not automatically created.Returns string with directory name or empty if nothing was selected. [Desktop Automation] |
showopendialog | Filename = system:showopendialog(extension:String) | Shows a file open dialog. Only one extension can be passed. If the extension is unknown to Netfabb it can be registered using system:registerextension . If a file was selected its name is returned, otherwise an empty string is returned. [Desktop Automation] |
showprogressdlg | system:showprogressdlg(defaultcallback: Boolean); | Shows the progress dialog [Desktop Automation] |
showprogressdlgcancancel | system:showprogressdlgcancancel(showCancel: Boolean); | Shows a progress dialog with an optional Cancel button. This dialog is used to notify the user of the progress of operations programmed in LUA also giving the option to stop these operations. See also: hideprogressdlgcancancel, setprogresscancancel, progresscancelled [Desktop Automation] |
showsavedialog | filename_to_save = system:showsavedialog(ext:String, [ext2:String]); | Open file save dialog with parameter for the file extension, returns filename. The second, optional parameter defines the possible extensions for the save file, the first the default ending. [Desktop Automation] |
showsavedialogex | filename_to_save = system:showsavedialogex(ext:String, ext2:String, name:String); | Open file save dialog with parameter for the file extension, returns filename. ext2 defines the possible extensions of the filename, the 1st the default. name suggests a filename for saving. [Desktop Automation] |
sleep | system:sleep(milliseconds:integer); | Stops the application for milliseconds . |
tonumber_safe | system:tonumber_save(value:String, name:String); | Registers name as global variable and stores value as float in it. [Desktop Automation] |
urlencode | encoded = system:urlencode(input:String); | Encodes a string following RFC 3986 (https://tools.ietf.org/html/rfc3986) |
urldecode | decoded = system:urlencode(encoded:String); | Decodes a string following RFC 3986 (https://tools.ietf.org/html/rfc3986) |
yesnodlg | Result = system:yesnodlg(message:String, [withCancel:Boolean]); | Displays a "Yes/No" dialog with message as text. withCancel (optional) enables a "Cancel" button.Result: 1 for Yes, 0 for No, -1 for other. [Desktop Automation] |
zoomto | system:zoomto(target:number) | Sets the camera to a target specified by built-in constant or literal value |
Examples
Name | Example | Return value |
---|---|---|
log | system:log("Hello World"); | - |
logtofile | system:logtofile("my_file.log"); | - |
getparam | filename_to_process = system:getparam(0); | string:String containing the desired parameter |
shellexecute | system:shellexecute("mail", -s subject "hello@mail.com") | - |
checklibrary | system:checklibrary("mysql"); | - |
showsavedialog | local filename = system:showsavedialog ("wrl"); | String: with the file name, or empty string |
createscreenshot | shotJson="{"show_verticalruler":true, "show_labels":true, "show_colors":true, "show_viewcube":true, "show_platform":true, "show_coordsystem":true, "show_horizontalruler":true, "show_textures":true, "camera":{"zoom":1, "eye":[0,1,0], "center":[0,0,0], "up":[0,0,1]}}" local shot=system:createscreenshot(400, 300, shotJson) |
Image object |
inputdlg | local userinput = system:inputdlg("Rename the part", "New name:", ""); | string |
Screenshot options JSON
The system:createscreenshot
method expects a JSON object as third parameter. This object controls the appearance of the screenshot. Using any of the keys is optional. If ommitted, keys and their values are derived from the 3D view's current settings. Keys and values set here only apply to the createscreenshot() method; they do not affect any current visual settings of the 3D view.
Name | Type | Description |
---|---|---|
![]() |
Boolean | Include or suppress bounding box shadows of visible parts |
show_colors | Boolean | Include the colors of the meshes |
show_coordsystem | Boolean | Include the coordinate system |
show_gizmo | Boolean | Include the Gizmo (i.e. the move and rotate controller) |
show_horizontalruler | Boolean | Include the horizontal ruler |
show_labels | Boolean | Include labels |
show_logo | Boolean | Include the Autodesk Netfabb Logo |
show_platform | Boolean | Include the platform (also toggles visibility of the arrows in position (0, 0, 0)) |
show_textures | Boolean | Include the model textures |
show_verticalruler | Boolean | Include the vertical ruler |
show_viewcube | Boolean | Include the viewcube |
An optional camera
JSON key controls the camera for the screenshot. If no camera
JSON key is present the current camera settings are used. Most of the entities of this camera
key are arrays with 3 floating point values that represent a 3D vector. The zoom
key controls the zoom factor of the camera where 1
is the default value, lower values zoom in, and higher values zoom out. The outbox
key is an array with 6 elements that define the bounding box to look at. The center
and zoom
keys are ignored if the outbox
key is present.
Name | Type | Description |
---|---|---|
center | 3 item float array | An array with 3 float items defining the camera center position in (X, Y, Z). This value is ignored when an outbox array is present. |
eye | 3 item float array | An array with 3 float items defining the camera position in (X, Y, Z) |
outbox | 6 item float array | An array with 6 float items defining the bounding box to look at. The first 3 entries define the minimum position (X, Y, Z) whereas the latter 3 values define the maximum position (X, Y, Z). Use either center or outbox . |
up | 3 item float array | An array with 3 float items defining the camera up-vector in (X, Y, Z). This vector is reduced to its effective component as permitted by the constraints of center or outbox and eye . It is not necessary to provide calculated, geometrically correct values for all of its three components. |
Zoom | float | Zoom value where 1 is default zoom, lower values zoom in, higher values zoom out. This value is ignored when an outbox array is present. |
Example
{
"show_horizontalruler": false,
"show_coordsystem": false,
"show_verticalruler": false,
"show_labels": false,
"show_viewcube": false,
"show_platform": false,
"show_logo": false,
"camera": {
"eye": [ 10, 0, 2.5 ],
"center": [ 0, 0, 0 ],
"up": [ 0, 0, 1 ],
"zoom": 0.5
}
}