Share

LUAPacker

[Desktop Automation]

An instance of this object is returned by the createpacker function of the LUATray (see LUATray) object. It is used to pack the content of trays. When packers are created, they take a snapshot of the tray which they work on. Any meshes added or removed after the packer instance is created do not factor into its packing results.

Properties

Some or all of these properties apply to the packing method of choice.

Property Access Type Default Range Description
borderspacingxy read/write Number 0 (mm) The desired minimal distance from the border of the tray.
borderspacingz read/write Number 0 (mm) The desired minimal distance from the build platform ceiling of the tray.
defaultpartrotation read/write Integer 0 0-2 Permits or restricts rotation for finding better fits. The values can be 0 (Arbitrary), 1 (z-axis), 2 (no rotation), default value is 0. This property may be overridden per part by adjusting its individual packing property.
minimaldistance read/write Number 1 (mm) The desired minimal distance between the parts in the tray.
optInteger read Number 0 0 Constant for parameter type Integer
optFloat read Number 1 1 Constant for parameter type Float
optBoolean read Number 2 2 Constant for parameter type Boolean
parametercount read Number Number of parameters of the packing method
[additional parameter name] read/write Packer-specific parameter. Refer to the documentation of the packer implementations for details.

Back to top

Methods

Name Syntax Description
getoutbox Result = Packer:getoutbox() Returns the dimensions of the current tray as a TLUAOutbox object with its minx, miny, maxy, maxz coordinates.
getparametername Result = packer:getparametername(Index: Number) Returns the name of the parameter with the given index. See tray.parametercount for the number of parameters available.
getparametertype Result = packer:getparametertype(Index: Number) Returns the type of the parameter with the given index as string (integer, float, Boolean). See tray.parametercount for the number of parameters available.
getparametertypeid Result = packer: getparametertypeid(Index: Number) Returns the name of the parameter with the given index as constant (see LUAPacker.optInteger, LUAPacker.optFloat, LUAPacker.optBoolean). See tray.parametercount for the number of parameters available.
getparametervalue Result = packer: getparametervalue(Index: Number) Returns the value of the parameter with the given index. Note that the type of the returned value differs depending on the type of the parameter. See tray.parametercount for the number of parameters available.
pack Result = packer:pack() Pack the tray with the desired algorithm. Returns a packer-specific error code (general: 0 = no error)
setoutbox Packer:setoutbox(boundingBox:TLUAOutbox) Sets the dimension of the tray to be packed. This can be used to pack only a fraction of the tray.

Example

List packing properties and values

system:setloggingtooglwindow(true)

for i = 0, 6 do -- adjust 6 if/when new packing algorithm becomes available
    system:log("Packer " .. i)
    local packer = tray:createpacker(i)
    for j = 0, packer.parametercount - 1 do
        system:log(string.format(
            "id %d - name %s - type %s - typeid %s - value %s",
            j,
            packer:getparametername(j),
            packer:getparametertypeid(j) == 3 and "unknown" or packer:getparametertype(j),
                -- if typeid is 3 then requesting the type would throw an error as the associated return value is currently not available due to a bug
            packer:getparametertypeid(j),
            packer:getparametertypeid(j) == 3 and "unknown" or tostring(packer:getparametervalue(j))
                -- as above
        ))
    end
    packer:release()
end

Back to top

Was this information helpful?