Share

Script9_PackMultiTray.lua

-- Lua example for Autodesk Netfabb 2019.0

-- Packs parts from the first tray evenly into a second and third tray

system:setloggingtooglwindow(true)

function packtray(Actualtray)
    local pa_id = Actualtray.packingid_montecarlo
    local packer = Actualtray:createpacker(pa_id)

    if pa_id == Actualtray.packingid_montecarlo then
        system:log("Setting options in the Monte Carlo packer.")
        packer.packing_quality = -1
        packer.z_limit = 0.0 -- If z_limit is set to zero, the default value, MachineSizeZ is used
        packer.start_from_current_positions = false
    end

    packer:pack()
    Actualtray:updatetodesktop()
end

system:log("Get things started")
trayArray = {}
system:log("Tray is here")
if (netfabbtrayhandler.traycount == 1) then
    netfabbtrayhandler:addtray("tray2", 400, 400, 400)
    netfabbtrayhandler:addtray("tray3", 400, 400, 400)
end
if (netfabbtrayhandler.traycount > 2) then
    for idx = 0, netfabbtrayhandler.traycount - 1 do
        trayArray[idx] = netfabbtrayhandler:gettray(idx)
    end
    root = trayArray[0].root
    root2 = trayArray[1].root
    root3 = trayArray[2].root

    for mesh_index = 0, root.meshcount - 1 do
        local traymesh = root:getmesh(mesh_index)
        local luamesh = traymesh.mesh
        if (mesh_index - math.floor(mesh_index / 2) * 2) == 0 then
            root2:addmesh(luamesh, traymesh.name, tonumber(traymesh.color,16))
        else
            root3:addmesh(luamesh, traymesh.name, tonumber(traymesh.color,16))
        end
    end
    packtray(trayArray[1])
    packtray(trayArray[2])
end

Was this information helpful?