Script2_fabbproject.lua
-- Lua example for Autodesk Netfabb 2019.0
-- Loads and manipulates a fabbproject independently from the desktop application
-- Requires an existing FABBPROJECT file that cannot also be loaded already in Netfabb.
-- The project should contain a selection of parts to see the effects.
filename = 'd:\\demo\\test.fabbproject'
system:setloggingtooglwindow(true)
system:log(filename)
fabbproject = system:loadfabbproject(filename)
outputDir = 'd:\\demo\\output\\'
-- Iterate trays
for tray_index = 0, fabbproject.traycount - 1 do
local tray = fabbproject:gettray(tray_index)
-- Get root meshgroup from tray
local root = tray.root
-- Iterate through parts in group
for mesh_index = 0, root.meshcount - 1 do
local rotate = 0.5 * mesh_index
local translate = 15 * mesh_index
local scale = 1 / (mesh_index + 1)
local mesh = root:getmesh(mesh_index)
-- rotate mesh
mesh:rotate(1, 0, 0, rotate) --rotate around X in radians
-- translate mesh
mesh:translate(translate, 0, translate) -- translate in X and Z
-- scale mesh
mesh:scale(scale, scale, scale) --scale proportionally
if not system:directoryexists(outputDir) then
system:createdirectory(outputDir)
end
-- export source part mesh as STL with implicit application of any transformation
mesh.mesh:savetostl(outputDir .. mesh.name ..tostring(tray_index) .. '_source.stl')
-- export part as STL with transformation
mesh:savetostl (outputDir .. mesh.name ..tostring(tray_index).. '.stl')
end
end
-- save the modified fabbproject to a new FABBPROJECT file
system:log('Save \'copy.fabbproject\' ..')
fabbproject:savetofile(outputDir .. 'copy.fabbproject')
-- log all options that were not saved
if fabbproject.notsavedoptions ~= "" then
system:log('===== unsaved options =====')
system:log(fabbproject.notsavedoptions)
system:log('=============================')
end