In this tutorial we will explore different ways to perform Cutting, Marking and Holes. Requires IGEMS version newer than IGEMS 2025.1.4216.
Toolpath from polyline attached to a part
Marking on a polyline and attach to a part
Text marking attached to a part
Hole cutting attached to a part
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("CuttingTutorial", "Cutting tutorial", null, Cutting);
}
private static void Cutting()
{
ToolpathAutomatic();
ToolpathOnContour();
ToolpathFromPoly();
ToolpathFromPolyAttched();
MarkingOnPart();
MarkingFromPoly();
MarkingFromPolyAttached();
MarkingText();
MarkingTextAttaced();
HoleCutting();
HoleCuttingAttached();
API.ZoomExtents();
}
}
In the Cutting function we will call several other functions, one for each example.
Toolpath automatic
This example shows how to create a part from code and then apply an automatic toolpath using the current settings in the Contour dialog box.
private static void ToolpathAutomatic()
{
Region2d region = new Region2d();
region.Add((new Extents2d(0, 0, 300, 300)).ToPoly());
region.Add((new Circle2d(150, 150, 50)).ToPoly());
var part = API.CreatePart(region, "Demo", 1, "", DateTime.Now)[0];
API.CreateToolpath(part);
}
First we create a part using the API.CreatePart function. We create a Region2d to hold the geometry of the part. Note! that API.CreatePart always returns a list of parts so we take the first part in that list.
Now we simply call API.CreateToolpath(part). This function will apply the current Contour cutting settings on the part and create the toolpaths. So, this is the same as pressing Contour in IGEMS.
To override the current settings in the Contour dialog you can use the ToolpathSettings class.
// Load the toolpath settings used in the Contour command
ToolpathSettings tp = new ToolpathSettings();
// Make a copy to be able to reset them after creating the toolpath
ToolpathSettings old = new ToolpathSettings(tp);
// Set sorting to Closest
tp.Sorting = 0;
// Make sure external and internal contours are cut
tp.EnableInternal = true;
tp.EnableExternal = true;
// Set the Lead for external contours
tp.LeadExternal = "Circular";
// We must save the settings before calling CreateToolpath
tp.Save();
API.CreateToolpath(part);
// Now we save the copied old settings to reset
old.Save();
This is the result.
Toolpath on contour
In this example we will add toolpaths to the contours manually.
private static void ToolpathOnContour()
{
Region2d region = new Region2d();
region.Add((new Extents2d(0, 0, 300, 300)).ToPoly());
region.Add((new Circle2d(150, 150, 50)).ToPoly());
region.Translate(400, 0);
var part = API.CreatePart(region, "Demo", 1, "", DateTime.Now)[0];
API.CreateToolpath(part, region[1].Arc(0).Start, 0, true, 3, 2, 4, 90, 4, 3, 90, 0, "ToolpathOnContour");
if(API.GetLead("circular",out var piercing,out var overcut,out var linlength, out var linangle,out var linradius,out var loutlength,out var loutangle,out var loutradius))
API.CreateToolpath(part, region[0].Arc(0).MidPoint, 0, true, piercing,overcut,linlength,linangle,linradius,loutlength, loutangle,loutradius, "ToolpathOnContour");
}
We first create a part, then we use an overload of API.CreateToolpath that gives full control over the toolpath. This function takes the following arguments.
- Part
- Point
- This is a 2d point that will be the starting point of the toolpath. If the point is not on the contour you like to cut the system will find the closest point and use that.
- Dir
- This is the direction of the cut 0=CW 1=CCW
- Compensated
- true of false
- Piercing type
- 0=Blind 1=Linear 2=Stationary 3=Circular 4=Drilling 5=Air start 6=User
- Overcut in mm
- Leadin length in mm
- Leadin angle in degrees
- Leadinnradius in mm
- Leadout length in mm
- Leadout angle in degrees
- Leadout radius in mm
So, for the hole in the part we set all these values manually in code.
API.CreateToolpath(part, region[1].Arc(0).Start, 0, true, 3, 2, 4, 90, 4, 3, 90, 0, "ToolpathOnContour");
For the outer contour we get the Lead settings from the lead database using the API.GetLead function.
If the lead we look for is found we use that data and create a toolpath on the outer contour.
if(API.GetLead("circular",out var piercing,out var overcut,out var linlength, out var linangle,out var linradius,out var loutlength,out var loutangle,out var loutradius))
API.CreateToolpath(part, region[0].Arc(0).MidPoint, 0, true, piercing,overcut,linlength,linangle,linradius,loutlength, loutangle,loutradius, "ToolpathOnContour");
Toolpath from polyline
In this example we will create a toolpath from a polyline. We can create toolpaths without attaching them to any part. Here we use the Poly2d class to create our geometry. All entities can be converted to polylines in the API so you can use existing entities on the drawing to cut on instead.
private static void ToolpathFromPoly()
{
Poly2d poly = new Poly2d();
poly.Add(new Point2d(0, 400));
poly.Add(new Point2d(300, 400));
poly.Add(new Point2d(300, 700));
poly.Add(new Point2d(0, 700));
API.CreateToolpath(poly,null,0,3,4,0,0,0,0,0, "ToolpathFromPoly","");
}
We use the API.CreateToolpath function that takes a Poly2d as its first argument. The second argument is an optional Part entity. If the Part is null like in this case the toolpath is generated as what we call a "void" part or a detached toolpath. If you add a part for the second argument the toolpath will be attached to that part and we will show this in the next example.
Note! If you like to cut just a section of the polyline you need to use the geometry functions in the API to extract that geometry before cutting. The CreateToolpath function always cuts the polyline as it is defined from start to end. This is also why this function does not have an argument for overcut.
Toolpath from polyline attached to a part
In this example we create a toolpath from a polyline and attaches that to a part.
private static void ToolpathFromPolyAttched()
{
Region2d region = new Region2d();
region.Add((new Extents2d(400, 400, 700, 700)).ToPoly());
var part = API.CreatePart(region, "Demo", 1, "", DateTime.Now)[0];
Poly2d poly = new Poly2d();
poly.Add(new Point2d(400, 410));
poly.Add(new Point2d(600, 410));
poly.Add(new Point2d(600, 690));
poly.Add(new Point2d(500, 690));
API.CreateToolpath(poly, part, 0, 3, 4, 0, 0, 0, 0, 0, "ToolpathFromPolyAttached", "");
}
The only difference compared to the last example is that we first create a part and adds that as our second argument. This will attach the toolpath to the part.
Marking on a part
In this example we will add some marking on a part. We create a rectangular part with a circle as an other object. We then add marking to the circle.
private static void MarkingOnPart()
{
Region2d region = (new Extents2d(800, 0, 1100, 300)).ToRegion(0);
Circle2d c = new Circle2d(950, 150, 50);
var circle = API.DrawCircle(c.Center.x,c.Center.y,c.Radius);
List<object> other = [circle];
var part = API.CreatePart(region,"Demo part",1,"",DateTime.Now,false,0,other,2,2,2)[0];
API.Delete(circle);
API.CreateMarking(c.Quadrant(0),part, "Mark circle", "", false);
}
We begin by creating a Region2d for the part rectangle. Next, we create a Circle2d object and add it to the drawing. This circle is then stored in a list of objects, which we pass as OtherObjects to CreatePart. The reason we created a Circle2d object is that we will use that to get a coordinate to this object when adding the marking.
To include other objects when creating a part, we must use entities from the drawing. This requires first adding the circle to the drawing, and once the part is created, we remove the circle.
After the part is created we can create the marking with API.CreateMarking. The function takes a point as its first argument. This point is only used to locate the object we like to mark. The arguments are.
- Point
- To locate the "other object" we like to mark
- Part
- The part to mark on
- Name
- Name of the marking
- Attribute
- Attribute
- Special
- Flag to indicate special marking
Marking on a polyline
As with cutting you can create marking just from a polyline without attaching it to a part.
private static void MarkingFromPoly()
{
Poly2d poly = new Poly2d();
poly.Add(new Point2d(1200, 0));
poly.Add(new Point2d(1500, 0));
poly.Add(new Point2d(1500, 300));
API.CreateMarking(poly,null, "MarkingFromPoly", "", false);
}
So, we create a polyline and call API.CreateMarking with the polyline and null as the part.
Marking on a polyline and attach to a part
Same as the last example except we create a part and attach the marking to that part.
private static void MarkingFromPolyAttached()
{
Region2d region = (new Extents2d(1700, 0, 2000, 400)).ToRegion(0);
Poly2d poly = new Poly2d();
poly.Add(new Point2d(1710, 10));
poly.Add(new Point2d(1900, 10));
poly.Add(new Point2d(1900, 300));
var part=API.CreatePart(region, "Demo part", 1, "", DateTime.Now)[0];
API.CreateMarking(poly, part, "MarkingFromPolyAttached", "", false);
}
Text marking
You can also mark text instead of polylines. When marking text the text must an entity in the drawing. After the marking is created we can remove the text if we like.
private static void MarkingText()
{
var text=API.DrawText("IGEMS", 1200, 600, 20);
API.CreateMarkingText(text, null);
API.Delete(text);
}
Text marking attached to a part
Same as with cutting and polyline marking we can mark a text and attach it to a part.
In this example we also show how to create a True Type text.
private static void MarkingTextAttaced()
{
Region2d region = (new Extents2d(1700, 600, 2000, 1000)).ToRegion(0);
var part = API.CreatePart(region, "Demo part", 1, "", DateTime.Now)[0];
var c = region.Centroid;
var text = API.DrawText("Arial","IGEMS", c.x,c.y, 30,0,0,2,2);
API.CreateMarkingText(text,part);
API.Delete(text);
}
Hole cutting
Cutting holes is done with the function API.CreateHole. In this example we add 6 holes with different hole types.
The CreateHole command takes the following arguments.
- Hole type
- 0=drilling 1=marking 2=piercing 3=cutting 4=Stationary 5=subroutine
- Position
- Radius
- Sub height
- Text height for sub routine text. Only used when the hole type is 5=subroutine
- Part
- Attach to this part
- If null the hole is detached and not connected to a part
- Name of the hole
- Attribute
private static void HoleCutting()
{
API.CreateHole(0, new Point2d(2200, 100), 10, 0, null, "HOLE0", "Attr0");
API.CreateHole(1, new Point2d(2300, 110), 11, 0, null, "HOLE1", "Attr1");
API.CreateHole(2, new Point2d(2400, 120), 12, 0, null, "HOLE2", "Attr2");
API.CreateHole(3, new Point2d(2500, 130), 13, 0, null, "HOLE3", "Attr3");
API.CreateHole(4, new Point2d(2600, 140), 13, 0, null, "HOLE4", "Attr4");
API.CreateHole(5, new Point2d(2700, 150), 13,10, null, "HOLE5", "Attr5");
}
Hole cutting attached to a part
Same as above but we also attach the holes to a part.
private static void HoleCuttingAttached()
{
Region2d region = (new Extents2d(2100, 500, 2800, 750)).ToRegion(0);
var part = API.CreatePart(region, "Demo part", 1, "", DateTime.Now)[0];
API.CreateHole(0, new Point2d(2200, 600), 10, 0, part, "HOLE0", "Attr0");
API.CreateHole(1, new Point2d(2300, 610), 11, 0, part, "HOLE1", "Attr1");
API.CreateHole(2, new Point2d(2400, 620), 12, 0, part, "HOLE2", "Attr2");
API.CreateHole(3, new Point2d(2500, 630), 13, 0, part, "HOLE3", "Attr3");
API.CreateHole(4, new Point2d(2600, 640), 13, 0, part, "HOLE4", "Attr4");
API.CreateHole(5, new Point2d(2700, 650), 13, 10, part, "HOLE5", "Attr5");
}