Script27_ColorMeshWithAnalysisResults.lua
-- Lua example for Autodesk Netfabb 2021.0
-- Performs wall thickness test and feature detection on mesh parts and generates duplicates colored based on results.
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
function colorMeshBasedOnArray(mesh, array, threshold, colortype)
for j = 0, array.length - 1 do
if tonumber(array:get(j)) < threshold then
if colortype == "red" then
mesh:colortriangle(j, 0, 0, 255, 255) -- index, B, G, R, A
end
if colortype == "blue" then
mesh:colortriangle(j, 255, 0, 0, 255)
end
end
end
end
-- Get root meshgroup from tray
root = tray.root
-- Collect meshes in the tray
meshes = {}
insertMeshesIntoTable(root, meshes)
-- Iterate over meshes in tray
for i, traymesh in pairs(meshes) do
local luamesh = traymesh.mesh
newMesh:applymatrix(traymesh.matrix)
local array = system:createarray()
-- required array type for wall thickness test; a plain Lua from array = {} is not enough
-- Prepare mesh with semi-transparent gray for all its triangles
newMesh:colortriangles(128, 128, 128, 128) -- B, G, R, A
newMesh:wallthicknesstestwithoutput(0.51, 10, false, true, array)
-- distance, surface fraction threshold for pass/fail, use coloring, use multicore, array to write to
colorMeshBasedOnArray(newMesh, array, 0.51, "red")
newMesh:featuredetection(0.51, 10, false, true, array)
-- distance, surface fraction threshold for pass/fail, use coloring, use multicore, array to write to
colorMeshBasedOnArray(newMesh, array, 0.51, "blue")
newtraymesh = root:addmesh(newMesh, "0.51 mm threshold")
end