Here's a code snippet to extrude a 2D profile generated in a CAD program.
// Reads the Autodesk file
var ra = new ReadAutodesk("filename.dxf");
ra.DoWork();
// Extracts a collection of curve entities
List<ICurve> curves = new List<ICurve>();
foreach (Entity ent in ra.Entities)
{
var curve = ent as ICurve;
if (curve != null)
curves.Add(curve);
}
// Groups the curves that are connected into CompositeCurves.
ICurve[] newCurves = devDept.Geometry.Utility.GetConnectedCurves(curves, 1);
// Fills inner gaps with short linear segments
double gapTolerance = 3;
foreach (var myCurve in newCurves)
{
CompositeCurve myCc = myCurve as CompositeCurve;
if (myCc != null)
{
// Checks only the first curve with the last one, but in some cases it could be necessary also to check curve-by-curve.
double gap = Point3D.Distance(myCc.CurveList[0].StartPoint, myCc.CurveList[myCc.CurveList.Count - 1].EndPoint);
if (!myCc.IsClosed && gap <= gapTolerance)
myCc.CurveList.Add(new Line(myCc.CurveList[myCc.CurveList.Count - 1].EndPoint, myCc.CurveList[0].StartPoint));
}
}
// Creates a Region with outer and inners profiles
var rr = devDept.Geometry.Utility.DetectRegionsFromContours(newCurves);
// Extrudes the Region
Brep extruded = rr[0].ExtrudeAsBrep(30);
// Adds the extruded profile to the Entities collection
design1.Entities.Add(extruded, Color.Beige);
|
Original profile |
Extruded profile |
Comments
Very nice! I did not know about the 'UtilityEx.GetConnectedCurves()' until now. I've already developed my own 2d chain routine.
Thanks for the code snippet. Very useful.
Hi, I'm new to Eyeshot and dwf/dfx and I'm trying to test this extrude feature but AutodeskReader Entities are always null. What am I doing wrong?
Hi Marcello
Does this work only in XY Plane ?
Regards,
Chirag
Please sign in to leave a comment.