Share

Script20_PartOrientator.lua

-- Lua example for Autodesk Netfabb 2025.0

-- Finds new orientation based on least support volume

system:setloggingtooglwindow(true)

root = tray.root

-- Register parts present in the current tray
meshes = {}
for mesh_index = 0, root.meshcount - 1 do
    local traymesh = root:getmesh(mesh_index)
    table.insert(meshes, traymesh)
end

-- Iterate over parts in tray
for i, traymesh in pairs(meshes) do
    system:log("Orienting part: " .. traymesh.name)
    local luamesh = traymesh.mesh
    luamesh:applymatrix(traymesh.matrix)

    local orienter = luamesh:create_partorienter()
    orienter.cutoff_degree = 45
    orienter.smallest_distance_between_minima_degree = 30
    orienter.rotation_axis = "arbitrary"
    orienter.distance_from_platform = 10
    orienter.support_bottom_surface = true
    -- Optionally limit height
    -- orienter:limitbuildheight(250);
    orienter:search_orientation_with_progress()
    orientation = orienter:get_best_solution_for("support_volume")
    local matrix = orienter:get_matrix_from_solution(orientation)
    luamesh:applymatrix(matrix)
    newmesh = root:addmesh(luamesh, traymesh.name .. " (oriented)", tonumber(traymesh.color,16))
end

Was this information helpful?