Share

Script16_CutMesh.lua

-- Lua example for Autodesk Netfabb 2019.1

-- Cuts the meshes in the tray.

system:setloggingtooglwindow(true)

local insertMeshesIntoTable
insertMeshesIntoTable = function(meshgroup, outtable)
    for mesh_index = 0, meshgroup.meshcount - 1 do
        local traymesh = meshgroup:getmesh(mesh_index)
        table.insert(outtable, traymesh)
    end
    for group_index = 0, meshgroup.groupcount - 1 do
        subgroup = meshgroup:getsubgroup(group_index)
        insertMeshesIntoTable(subgroup, outtable)
    end
end

local root = tray.root
-- Collect meshes in the tray
local meshes = {}
insertMeshesIntoTable(root, meshes)

-- Iterate meshes in group
for i, traymesh in pairs(meshes) do
    local luamesh = traymesh.mesh
    local matrix = traymesh.matrix
    newMesh = luamesh:dupe()
    newMesh:applymatrix(matrix)
    local cutmesh = newMesh:cut(2, 20) --First parameter: 0:y-z plane, 1: x-y plane, 2: x-y plane; second parameter: position of the plane in mm
    root:addmesh(cutmesh)
end

Was this information helpful?