Hide menu
Loading...
Searching...
No Matches
Nesting Example

Demonstrates how to optimize the arrangement of patterns on material sheets minimizing waste.

Overview

In this example demonstrates how to optimize the layout of 2D patterns (drawings) on material sheets using the nesting tool (Nesting_Computer ). For this purpose, a console application is used, which defines nesting parameters, creates patterns, and executes the nesting process. The tool computes an optimal arrangement of parts to minimize material waste and maximize placement efficiency.


For more information about nesting, refer to the Nesting Process.

Implementation

The nesting process begins by creating an instance of the Nesting_Computer class, which serves as the primary tool for optimizing the arrangement of 2D patterns. This is followed by defining and configuring the nesting parameters using the Nesting_ComputerParameters class:

aComputer = mtk.Nesting_Computer()
# Configuring nesting parameters
aParams = mtk.Nesting_ComputerParameters()
aParams.SetIterationCount(10) # Number of iterations for optimization process
aParams.SetGenerationSize(10) # Initial count of random layouts
aParams.SetMutationRate(0.5) # Probability of random shape rearrangement to escape local optima
aParams.SetPartToPartDistance(1.0) # Minimum distance between shapes
aParams.SetPartToSheetBoundaryDistance(1.0) # Minimum distance between shapes and sheet edges
aParams.SetMirrorControl(False) # Enables or disables the use of mirrored patterns
aParams.SetRotationCount(4) # Number of allowed rotation angles (e.g., 4 allows 0°, 90°, 180°, and 270°)
aParams.SetCurveTolerance(10) # Side length of squares used for polygonal approximation of curves
aComputer.SetParameters (aParams);

The dimensions and number of sheets are defined using AddMaterial() method:

# Define material size and number (e.g., 1 sheets of 100x100 mm)
aComputer.AddMaterial (100.0, 100.0, 1);

A Pattern is essentially a Drawing_View combined with metadata, such as the pattern name and number:

class Pattern:
def __init__(self, theShape: mtk.Drawing_CurveSet, theName: str, theNumber: int):
self.myDrawingDrawing_View = mtk.Drawing_View()
self.myDrawingDrawing_View.Add(theShape)
self.myName = theName
self.myNumber = theNumber

Rectangular patterns are created using the CreateRectangle function and added to a PatternVector:

def CreateRectangle(theWidth: float, theHeight: float) -> mtk.Drawing_CurveSet:
aRectangle = mtk.Drawing_CurveSet()
aL1 = mtk.Geom_Line2d(mtk.Geom_Point2d(0, 0), mtk.Geom_Direction2d(1, 0))
aL1.SetTrim(0, theWidth)
aL2 = mtk.Geom_Line2d(mtk.Geom_Point2d(theWidth, 0), mtk.Geom_Direction2d(0, 1))
aL2.SetTrim(0, theHeight)
aL3 = mtk.Geom_Line2d(mtk.Geom_Point2d(theWidth, theHeight), mtk.Geom_Direction2d(-1, 0))
aL3.SetTrim(0, theWidth)
aL4 = mtk.Geom_Line2d(mtk.Geom_Point2d(0, theHeight), mtk.Geom_Direction2d(0, -1))
aL4.SetTrim(0, theHeight)
aRectangle.AddCurve(aL1)
aRectangle.AddCurve(aL2)
aRectangle.AddCurve(aL3)
aRectangle.AddCurve(aL4)
return aRectangle
aPatterns = [
Pattern(CreateRectangle(50.0, 50.0), "Rectangle 50x50", 1),
Pattern(CreateRectangle(20.0, 10.0), "Rectangle 20x10", 10)
]

The patterns are loaded into the Nesting_Computer , which performs the nesting process and generates a Nesting_Data object containing the results.

# Load patterns into the computer
for aPattern in aPatterns:
aComputer.AddPattern(aPattern.myDrawingDrawing_View, aPattern.myNumber)
# Start the Nesting process
aData = aComputer.Perform()

Example output

Below is the example output:

------- Patterns Info -------
Rectangle 50x50: 1
Rectangle 20x10: 10
------- Nesting Info -------
#0 Sheet
Nested Parts: 11
Scrap: 55%
Placement Efficiency: 90.58%
Average Scrap: 55%
Average Placement Efficiency: 90.58%

Files