Share

Script15_GroupExample.lua

-- Lua example for Autodesk Netfabb 2019.0

-- Creates a named subgroup per part, copies the part into its allocated group, and deletes the original.
-- Only parts from the top level of the current tray are processed.

-- Get root meshgroup from tray
root = tray.root

-- Iterate parts ("meshes") in group
meshes = {}
for mesh_index = 0, root.meshcount - 1 do
    local traymesh = root:getmesh(mesh_index)
    table.insert(meshes, traymesh)
end

for i, traymesh in pairs(meshes) do
    local subgroup = root:addsubgroup(traymesh.name)
    local tempmesh = traymesh.mesh
    tempmesh:applymatrix(traymesh.matrix) -- fixates any transformation the part may "own"
    newmesh = subgroup:addmesh(tempmesh, traymesh.name, tonumber(traymesh.color,16))
end

for i, traymesh in pairs(meshes) do
    root:removemesh(traymesh)
end

Was this information helpful?