In this tutorial we will look at two ways to do nesting using the API.
The tutorial covers these tasks.
- Selecting parts and sheets
- Start Auto nesting using the Auto Nest dialog box
- Manually adding parts and sheets and perform Auto Nesting
Start by creating an IGEMS API project.
Register the APP
In your DLL register an APP using this code.
public class Class1
{
public static void DLLMain()
{
API.RegisterCommand("NestingTutorial1", "NestingTutorial1", null, NestingTutorial1);
API.RegisterCommand("NestingTutorial2", "NestingTutorial2", null, NestingTutorial2);
}
}
Auto nest using the dialog box
The NestingTutorial1 will use the API.NestOpen function. This will open the normal AutoNest dialog and start nesting with the parts and sheets supplied. It uses the settings in the dialog box. We implement the NestingTutorial1 method like this.
private static void NestingTutorial1()
{
var parts=API.SelectParts("Select parts");
var sheets=API.Select("Select sheets and obstacles");
API.NestOpen(parts, sheets);
}
As you can see it's very simple. First the user selects the parts to be nested. Then the user selects the sheets and possible obstacles to nest on. The API.NestOpen function will open the AutoNest dialog box and automatically start nesting. This is exactly the same as when the AutoNest command is performed in IGEMS. The quantity of each part is the Quantity property in the part. In the next example we will look at how we can change for example the Quantity and that technique can also be used here if you like.
Auto nest without the dialog box
You can also perform nesting without using the AutoNest dialog box. You do this by using the API.NestCreate, API.NestAddPart, API.NestAddSheet and API.NestRun functions. With this method you have to set a time in seconds for how long the nest should be performed.
private static void NestingTutorial2()
{
var parts=API.SelectParts("Select parts");
var sheets = API.SelectSheets("Select sheets");
var nest = API.NestCreate();
foreach (var part in parts)
{
var pi=API.GetPartInfo(part);
pi.Quantity = 10;
pi.UseHoles = false;
API.SetPartInfo(pi);
API.NestAddPart(nest, part);
}
foreach (var sheet in sheets)
API.NestAddSheet(nest,sheet);
API.NestRun(nest, 3);
}
We start by selecting parts and sheets to be used in the nesting.
Then we create the nest object using API.NestCreate. Here you can set the part distance if you like, if you don't set it the part distance in the current material will be used.
Then we loop over the selected parts and add them to the nest using the API.NestAddPart function.
In addition we modify the Quantity and the UseHoles property of the part. In this example we set UseHoles=false for all parts, this means no other parts can be nested inside any holes of the part. We utilize the API.GetPartInfo and API.SetPartInfo to modify these properties in the part. You can also for example control rotation and priority etc using the PartInfo functions.
var pi=API.GetPartInfo(part);// Get a partinfo object for the part
pi.Quantity = 10; // Modify quantity
pi.UseHoles = false; // Modify use holes
API.SetPartInfo(pi); // Save the changes
API.NestAddPart(nest, part); // Add the part to the nesting
Finally we add the selected sheets and call the API.NestRun. The nesting will run for three seconds before producing a result. The API.NestRun will also return a list of all nested parts if you need to continue processing them after nesting. You might want to add toolpaths and a cut order and postprocess. Or you might want to export the result in some way.
Complete code
using IGEMSAPI;
namespace NestingTutorial
{
public class Class1
{
public static void DLLMain()
{
API.RegisterCommand("NestingTutorial1", "NestingTutorial1", null, NestingTutorial1);
API.RegisterCommand("NestingTutorial2", "NestingTutorial2", null, NestingTutorial2);
}
private static void NestingTutorial1()
{
var parts=API.SelectParts("Select parts");
var sheets=API.Select("Select sheets and obstacles");
API.NestOpen(parts, sheets);
}
private static void NestingTutorial2()
{
var parts=API.SelectParts("Select parts");
var sheets = API.SelectSheets("Select sheets");
var nest = API.NestCreate();
foreach (var part in parts)
{
var pi=API.GetPartInfo(part);
pi.Quantity = 10;
pi.UseHoles = false;
API.SetPartInfo(pi);
API.NestAddPart(nest, part);
}
foreach (var sheet in sheets)
API.NestAddSheet(nest,sheet);
API.NestRun(nest, 3);
}
}
}