LUA scripting : Issue with accessing slicetray data

LUA scripting : Issue with accessing slicetray data

quentin_schmidBRKQZ
Enthusiast Enthusiast
3,049 Views
18 Replies
Message 1 of 19

LUA scripting : Issue with accessing slicetray data

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Hi,

 

I am trying to access data for a slice stack from lua scripting in the slice mode. I can get the number of slice from slicetray.layercount as in the example script "SliceCommanderScript6_TimeCalculationAndVisualization.lua", but when I try to access the other properties described in

Help | Slice | Autodesk

 

I get the following error 

 

2025-03-03 10:37:12;LUA Runtime Error: [string "ExtractLayerWiseinformation.lua"]:9: invalid object method or property: name;General

 

How can I solve this ?

 

Thanks,

 

Quentin

0 Likes
Accepted solutions (2)
3,050 Views
18 Replies
Replies (18)
Message 2 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

Hello,

 

It's not clear what you're doing at that line. Without seeing actual code I can only guess that either the object has a name property and you're accidentally using a colon as if it was a method or that your code's syntax is technically correct but the object you're querying doesn't have a name property because it isn't the right one to query.

 

Kind regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 3 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast
The following code
 
''''
local PATH = "C:\\Users\\E129000\\OneDrive - RMIT University\\Documents\\NETFABB\\ScriptOutput\\"
local LayerThickness = 0.03;
 
system:setloggingtooglwindow(true);
 
Nl = slicetray.layercount;
NAME = slicetray.name;
 
system:log('Name of the mesh is'..NAME)
''''
 
yield the error

'''
2025-03-03 14:10:28;LUA Runtime Error: [string "ExtractLayerWiseinformation.lua"]:7: invalid object method or property: name;General
'''
 
Hope it helps
0 Likes
Message 4 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast
The following code

''''
local PATH = "C:\\Users\\E129000\\OneDrive - RMIT University\\Documents\\NETFABB\\ScriptOutput\\"
local LayerThickness = 0.03;

system:setloggingtooglwindow(true);

Nl = slicetray.layercount;
NAME = slicetray.name;

system:log('Name of the mesh is'..NAME)
''''

yield the error

'''
2025-03-03 14:10:28;LUA Runtime Error: [string "ExtractLayerWiseinformation.lua"]:7: invalid object method or property: name;General
'''

Hope it helps
0 Likes
Message 5 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

Hello,

 

The slicetray object does not have a name property.

 

The slicetray object represents the current generic platform's Slicing section, similar to how the tray object represents the current 3D platform. These objects are set up automatically by Netfabb under these names.

 

Its only property is layercount, its only method is createslicetimecalculation().

 

Kind regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 6 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Thanks for your feedback Steffen. But how can I access to the name of the .sli file ? (see attached file where it is "JEB_150-_0.sli").

I need as I want to export layer-wise information but I cannot find a way to access the name of the slice stack.

 

thanks,

 

Quentin

0 Likes
Message 7 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

Quentin,

 

That is a slice stack, a slice object, which does have a name property: https://help.autodesk.com/view/NETF/2025/ENU/?guid=NETF-LUA-SLICESTACK

 

Also, please note that this is no longer "a SLI file" but merely Netfabb's interpretation of whatever data it could import. Any data beyond that would be lost, or rather, not maintained. Likewise, exporting such a slice stack from Netfabb cannot be guaranteed to produce the same file as you started with because the exporter writes the file from maintained data from scratch.

 

Best regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 8 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Ok so it is basically not possible to access the name of the slice stack while running a script from the slice scope ?

0 Likes
Message 9 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

I'm not sure what would have caused you to believe so. Please by all means let me know so I can focus on that aspect in maintaining the documentation.

Getting the name of a slice stack is as simple as selecting the stack in the project tree and running a script with these contents through Prepare > Run Lua script:

 

system:messagedlg(slice.name)

 

slicename.png

What isn't possible, however, is iterating through multiple slice stacks already present in the tree within the same Lua script. In Slicing in the tree, even though multiselection is available, Lua scripts are always run for each selected stack freshly and separately.

To iterate through multiple slice stacks already present in the tree within the same Lua script, use the slicelist object. Netfabb sets one up (under the same name) from all stacks manually selected (or all of them if none are selected) in the project tree at script start. Just answer No to the confirmation whether to run the script on each slice stack separately.

separately.png

See <Netfabb installation>\Examples\Lua scripts\SliceCommanderScript2_OffsetWithSliceList.lua for a demonstration of that object.

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 10 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

I was thinking it was possible based on the script example 6 where I saw slicetray.layercount; that I mixed with slice.

Anyway the second part of your answer is actually what I wanted to do but you confirm it is not possible.

Is possible to to open a slice file (.sli or whatever) from a script, operate on it,close it and repeat ?

 

thanks,

 

Quentin

0 Likes
Message 11 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support
Accepted solution

Hello,

 

Yes and no.

 

Yes, as long as you do not need to invoke the project tree, you're free to use slicing functions on slice stacks imported from files, and do so in a script you call from the Lua script library as accessible while a 3D platform is active.

This would probably involve system methods getallfilesindirectory() and loadslice().

The example Demo Application (in the built-in Lua script library), calling specifically the function load_dir() from BaseRoutines.lua (in <Netfabb installation>\Examples\Lua scripts) demonstrates loading multiple files in a single script. You could go from there.

 

No, as Netfabb does not handle slice files natively, so, you cannot "open and save". Netfabb always imports and exports. Meaning, it takes what its importer is set up to understand, and writes what its exporter is set up to handle, with Netfabb's understanding of slice data in the middle, and all with expectable loss or discarding of information.

 

Best regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 12 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support
Accepted solution

Actually, what I wrote earlier is partly wrong. Netfabb does indeed have the ability to run through multiple stacks present in the same script. Use the slicelist object for that. Netfabb sets one up (under the same name) at the start of a script from the slice stacks present and, optionally, selected in the project tree.

So, yes, you could indeed run through multiple slice stacks batch-style in a single script. I have corrected my earlier posts where necessary.

Your workflow would then look something like this:

  1. Get slice stacks into Slicing, either by slicing 3D geometry or by importing slice files.
  2. Optional: Select stacks to process. (If none are selected, the automatically created slicelist object simply holds them all.)
  3. Run script. (Must include addslicetotree() method, otherwise the next steps will be rather pointless.)
  4. Optional: Select stacks to export.
  5. Manually perform the export.

Note that slicing 3D geometry is in fact supported inside a script run while Slicing is active: For this, the script must load the geometry to slice from the file system:

 

mymesh = system:load3mf("path\\to\\file.3mf")
myslice = system:slicemesh(mymesh, 1, 0, 100, true) -- 0, 100: arbitrary Z range for demo purposes
system:addslicetotree(myslice)

 

After all, the script isn't required to actually make use of slice or slicelist objects set up at script launch. The only requirement here is that there is already a (dummy) slice stack present, otherwise the command to run a Lua script is disabled.

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 13 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Hi Steffen, Many thanks for your advices this is really helpfull.  I will try to implement this

Message 14 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Hi Steffen,

 

Just a detail that I found out. It is not possible to run a script from the slice menu if you do not have a file already loaded. So far I was able to circumvent this by loading a dummy file, but I understand more what you mean by "you cannot cross scope with script". I will post here if I have more issue.

 

Thanks,

 

Quentin

0 Likes
Message 15 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Hi Steffen,

I managed to do what I wanted to do. Many thanks for your advices.

This being said, the distinction between the mesh that you load throught the get all files and the one you actually manipulate with the tray.

like you would do

 

MESH = system:loadstl(filename);
mesh = root:addmesh(MESH);

 

Interestingly, properties work on mesh whereas methods work on MESH. I find the documentation a bit confusing on this point.

 

Quentin

0 Likes
Message 16 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

Hi, Quentin,

 

There is a difference between a mesh object (LUAMesh) and a traymesh object (LUATrayMesh). Unfortunately, for historical reasons, they both have "mesh" in the name when the latter should really have been named "traypart", contributing to the confusion.

 

A LUAMesh is the triangle mesh itself, with properties like triangle counts, colors, and so on, but with no representation on the platform.

A LUATrayMesh is a part present on the platform and has properties like visibility, position on the platform, and indeed mesh, the triangle net information which LUAMesh has, or had originally before it was added to the tray.

 

In other words, it's not that properties only work on one and methods only work on the other, it's that they have different properties and methods, and you're either not using the right ones or your syntax isn't quite right. To get back at the triangle net information it's not enough to use, for example, mytraymesh itself but mytraymesh.mesh.

 

I'll see what I can do to update the documentation to be more clear, thanks for letting me know where it's lacking.

 

Best regards,

Steffen

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 17 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

The documentation claims that a mesh has a property area and volume, but I was only able to access it at LUAmesh level. It is in that sense that I say documentation is confusing.

This being said, many thanks for you support I was able to do more or less what I wanted to do in a few weeks

0 Likes
Message 18 of 19

steffen_anders_adsk
Autodesk Support
Autodesk Support

I can't reproduce what you report, or find anything not true in the documentation around area and volume.

 

If I launch Netfabb, spawn the default Helix from the part library, and then run this script:

 

system:setloggingtooglwindow(true)

traypartname = tray.root:getmesh(0).name
traypartarea = tray.root:getmesh(0).area
traypartvolume = tray.root:getmesh(0).volume
system:log(string.format("Part %s has %d mm² area and %d mm³ volume.", traypartname, traypartarea, traypartvolume))

mesharea = tray.root:getmesh(0).mesh.area
meshvolume = tray.root:getmesh(0).mesh.volume
system:log(string.format("Mesh of part %s has %d mm² area and %d mm³ volume.", traypartname, mesharea, meshvolume))

 

… I get this result:

 

Part Helix has 23575 mm² area and 108197 mm³ volume.
Mesh of part Helix has 23575 mm² area and 108197 mm³ volume.

 

(The reason behind both LUATrayMesh and LUAMesh having properties for area and volume each, and reason the values can be different between the two, is that a LUATrayMesh also contains a transformation matrix (accessible via traymesh.matrix) that applies and may have a scaling effect. This is intentional.)

 

So, please double-check your code.

Steffen Anders
Autodesk Netfabb team

Netfabb resources: Online help • System requirements • Knowledge base • Forums • Homepage • YouTube

How to get Netfabb Basic: Video • Help • Download

0 Likes
Message 19 of 19

quentin_schmidBRKQZ
Enthusiast
Enthusiast

Hi Steffen,

 

my bad the issue was that I was trying to directly get quantities like area and volume from

 

'''

MESH = system:loadstl(filename);

'''