Share

Script35_MeshFaceSelector.lua

-- Lua example for Autodesk Netfabb 2021.1

-- Demonstrates the use of the MeshFaceSelector class and its methods
-- and visualizes the results on a part copy

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
            mesh:colortriangle(j, 0, 0, 255, 254)
        end
    end
end

-- Get root meshgroup from tray
root = tray.root
faceselector = system:createmeshfaceselector()
-- 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
    luamesh:applymatrix(traymesh.matrix)
    local array = system:createarray()
    newMesh:colortriangles(128, 128, 128, 128)

    --faceselector:selectnegativeshells(newMesh, array);
    faceselector:selecttrianglesperarea(newMesh, array, 0.0, 50)
    --faceselector:selectshellspervolume(newMesh, array, 0.0,6000);

    colorMeshBasedOnArray(newMesh, array, 0.5, "red")

    newtraymesh = root:addmesh(newMesh, traymesh.name .. "_SelectedTriangles", tonumber(traymesh.color, 16))
end

Was this information helpful?