In this tutorial we will create a part and a sheet from code.
The tutorial covers these tasks.
- Using Genamo, the IGEMS geometry API, to create a part
- Create a sheet
Start by creating an IGEMS API project.
Code
using IGEMSAPI;
using IGS.Genamo;
using System;
namespace PartFromCodeTutorial
{
public class Class1
{
public static void DLLMain()
{
API.RegisterCommand("PartFromCodeTutorial", "PartFromCodeTutorial", null, PartFromCodeTutorial);
}
private static void PartFromCodeTutorial()
{
Extents2d rectangle = new Extents2d(0,0,100,100);
Circle2d hole1 = new Circle2d(20, 20, 8);
Circle2d hole2 = new Circle2d(80, 20, 8);
Circle2d hole3 = new Circle2d(80, 80, 8);
Circle2d hole4 = new Circle2d(20, 80, 8);
Region2d region = new Region2d();
region.Add(rectangle.ToPoly());
region.Add(hole1.ToPoly());
region.Add(hole2.ToPoly());
region.Add(hole3.ToPoly());
region.Add(hole4.ToPoly());
API.CreatePart(region,"PART",1,"",DateTime.Now);
API.CreateSheet("SHEET", 2000, 1000, 5);
API.ZoomExtents();
}
}
}
We start by registering the APP command using the API.RegisterCommand function.
In the PartFromCodeTutorial function we do the following.
First we create a rectangle using the Extents2d class, this will be the outer geometry for our part.
We create four circular holes in the part using the Circle2d class.
We add the outer rectangle and the four holes to a Region2d object that is used to create the part. A Region2d contains a list of polylines so the objects needs to be converted to polylines when adding them to the region. This is why we call the ToPoly() method when adding them to the region.
Now the region contains all the geometry for the part and we call the API.CreatePart function.
We also create a sheet using the API.CreateSheet command.
Finally we do a ZoomExtents to make sure everything is visible in the drawing.
Comments
Creating parts from code is quite simple and the Genamo API has all the tools needed to generate complex geometry.