Skip to main content

Nesting

Nesting lays copies of flat parts out on sheets of stock so that as little material as possible is wasted, ready for a laser, plasma, waterjet or router. CAD Cloud nests the parts' true shapes, curves and holes included: a small part can sit inside the hole of a larger one. It is one of the Pro algorithms that run only on CAD Cloud.

Nesting after the plates template: 142 plates on one 2000 x 1000 mm sheet, the small ones placed inside the holes of the large ones, with the sheet's use and every part's count beside it

The picture is the plates template from the input templates: thirteen plates, 142 copies in all, on one 2000 x 1000 mm sheet, the washers and small plates placed inside the rings and frames.

Download the plates that nest inside each other template, a compressed STEP file (294 KB) Download every nesting template, each with its request and the scripts that run it (309 KB)

What a part is​

You send STEP files (.step, .stp, or gzip-compressed .stpz), at most 50 and 200 MB together. A part is anything flat: a planar face, coplanar faces such as an unfolded sheet-metal part, a plate solid, or a drawing of closed wires.

The plates template's STEP file in 3D: one of each of the thirteen 3 mm plates, as they were modelled, before nesting

The plates template's file holds one of each of its thirteen plates, as they were modelled. Its request asks for 142 copies of them, and the nesting places them on the sheet.

Parts are read file after file, as each file's product structure gives them:

  • every placement of a part in an assembly is a part, and a file with no assembly is its one part;
  • within a part, every solid is a part of its own, in the order they sit, and whatever else it holds stays one part after them (an unfolded flat pattern with its bend lines, a drawing's outline with its holes);
  • a part with no edge is skipped.

A plate's thickness does not matter to the layout: its outline and its holes do. Lengths are millimetres. A file whose header names the wrong unit, as some exporters write a model drawn in metres under a millimetre header, is read right with fileUnit. The DXF and SVG cut files can be written in inches instead: see the cut files' unit.

In Studio​

  1. Open Nesting and drop your STEP files on it, or choose Start from a template and Plates that nest inside each other.
  2. The parts are read and nested at once, on a sheet sized for them.
  3. Set the stock and the gaps in the Sheet tab and each part's copies in the Parts tab, then choose Nest again.

Layout lists every sheet with the parts on it and how much of it they use. Export downloads the cut paths as DXF or SVG, and the other formats below. The unit of the DXF and the SVG is chosen beside it, under Cut files in, and applies from the next Nest again; the menu names the unit each cut file of the layout shown was written in.

The routes​

RouteWhat it does
POST /api/v1/cad/pro/nesting/nestNests the parts and writes the nested sheets
POST /api/v1/cad/pro/nesting/inspectReads the parts as nesting would, without nesting them: each part's file, kind, outline size, area and cut length, or why it cannot be nested

Both take the uploaded files as stepFileIds, start a task and answer with its taskId. They need an API key with the cad scope. Inspect first when a file comes from somewhere new: it shows how many parts the file gives and in what order, which is the order options.parts follows.

A request​

This is the request the small nesting template ships with: three plates, two, four and six copies of them. <your uploaded file> stands for the fileId the upload gave you.

{
"stepFileIds": ["<your uploaded file>"],
"options": {
"sheets": [{ "width": 1000, "height": 500 }],
"parts": [{ "quantity": 2 }, { "quantity": 4 }, { "quantity": 6 }],
"spacing": 5,
"margin": 10,
"seed": 1,
"evaluationBudget": 3000,
"timeBudgetSeconds": 60
},
"outputs": { "formats": ["dxf", "svg", "outlines"] }
}

Stock​

options.sheets lists what you nest onto, either:

  • sheets: up to 100 kinds of rectangle, each a width and a height, with a quantity when you have only so many and a cost per sheet. Without costs, the stock that wastes least is opened first;
  • or one strip: { "strip": true, "height": 1250 }, a roll or bar of that width whose length is open. The nesting makes the length as short as it can.

Each part​

options.parts[i] belongs to the i-th part over all files. An entry may be null, and parts past the end of the list take the defaults.

OptionWhat it doesDefault
quantityHow many copies to place; 0 leaves the part out1
rotationsHow the part may turn: { "mode": "fixed", "angles": [0, 180] } for a grain direction, { "mode": "step", "step": 45 } for steps that divide 360, or { "mode": "free" }steps of 90 degrees
allowFlipWhether the part may be turned over: a half turn about an axis in its plane, never a mirrorfalse
priorityParts of higher priority are placed first, so they are the last left off when stock runs out0
xDirectionThe direction in the part's plane that a turn of 0 lays along the sheet's x axisthe part as drawn

All copies together stay within 100,000, over at most 5,000 parts.

OptionWhat it doesDefault
spacingThe least distance between any two parts, measured on their true shapes0, where parts that tile exactly may touch
marginThe band along each sheet's edges that no part enters0
timeBudgetSecondsHow long the search may run; the best layout found by then is returned10, at most 120
evaluationBudgetStop after this many placements are tried; 0 means no limitno limit
seedThe seed of the search's random choices1
toleranceHow far the straight chords that stand in for curved edges may stray from them; the spacing still holds on the true curves0.1

Repeatable layouts. A search stopped by time depends on how fast the server ran, so two runs can differ. Give an evaluationBudget that the search reaches well inside its time budget, and the same seed gives the same layout every time. The report's run.reproducible says whether it did. Every template's request is set up this way.

Outputs​

FormatWhat you get
dxfAn AutoCAD 2000 drawing in millimetres, or in outputs.unit: the sheets' outlines on layer SHEETS, the parts' cut paths on layer PARTS, every arc, ellipse and spline exact
svgThe same drawing as an SVG file in the same unit, each layer a group
outlinesThe same cut paths as JSON, in millimetres, each copy in its sheet's frame and named by its placement, for drawing the layout yourself
step or stpzEach used sheet one part, holding its placed parts and its outline
gltfThe nested sheets as glTF, the default
decomposed-meshThe placed parts triangulated, as JSON

Give step or stpz, not both. A dxf or svg too large to write is left out while every other format is still written, and the task's metadata says why under outputsLeftOut.

The cut files' unit​

outputs.unit sets the unit the DXF and SVG cut files are written in: mm (the default), cm, m or in. For a shop whose cutting software works in inches:

"outputs": { "formats": ["dxf", "svg"], "unit": "in" }

The drawing is scaled into the unit and each file states it, so the software opens it at its true size: the DXF in its header ($INSUNITS), the SVG in its width and height. A part 254 mm wide is 10 units wide in an inch DXF. SVG has no metre, so an SVG in metres gives its width and height in centimetres.

The unit changes those two files only:

  • step and stpz stay in millimetres. A STEP file states its unit in its header, and CAD programs convert it on import.
  • gltf and decomposed-mesh are written as without it.
  • The outlines JSON, the report and every length in the request stay in millimetres.

The nesting report​

The task's metadata result is the report:

  • sheets: every used sheet, its stock, how many parts it holds and how much of it they fill (utilization);
  • placements: every copy placed, with its sheet, position, angle, whether it was turned over, its box on the sheet and the matrix that moves the input part there;
  • parts: each part as read, with its kind, size, area, cut length, number of loops, and how many copies were placed;
  • left: copies that were not placed and why: the part's own problem, tooLargeForAnySheet, noStockLeft, timeBudget or verificationFailed;
  • totals: sheets used, parts placed and left, the part and sheet areas, the cost, the cut length and the number of pierces;
  • run: the seed, how many placements were tried, how long it took and whether it is reproducible.

Run it​

The template download holds the request with two scripts that send it, run.sh (curl and jq) and run.ts (the TypeScript SDK): each uploads the file, sends the request, waits for the task and saves every result beside it. Every request option is in the API reference.

Nesting also runs inside a pipeline, as an occtPro.nesting.nest step on shapes the pipeline made, so parts can be modelled and nested in one call. Pipelines shows how a pipeline is put together.

To unfold bent sheet-metal parts and nest their flat patterns in one call, use Sheet-metal unfold.