Hi,
I'm working on an application that converts Polyline3D objects into Region objects. The routine works as follows:
1. create a polyline3d object from a set of vertixes (the shape is always closed)
2. add polyline3d to DBObjectCollection
3. Call Region.CreateFromCurves(acDBObjColl);
Most of the times this routine works fine, but depending on the shape of the polyline3d, the CreateFromCurves() method will fail with an exception error eInvalidInput. When this happens multiple times in a file, autocad will eventually crash/become unstable.
My question is: is there a smart way to check if a polyline3d is a valid Region element before attempting to run it through Region.CreateFromCurves()?
Below is some sample code showing the issue:
Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true);
DBObjectCollection acDBObjColl.Add(face);
DBObjectCollection myRegionColl;
try
{
myRegionColl = Region.CreateFromCurves(acDBObjColl);
}
catch()
{
// eInvalidInput exception
Debug.WriteLine("Error: unable to create region collection: " + ex->Message);//
}
Regards
Bjørn Egil Jenssen
I'm testing if the polyline is in a plane before passing it to a region. But the main issue I'm having is to have a method to check if a polyline is valid on all points (planar, non-intersecting, closed, etc) before passing it to CreateFromCurves(). Is there a method that does this kind of verification? What requirements do a polyline3d have to fullfill to be a used as a Region?
Reg.
Bjørn Egil Jenssen
Alternativly, is there a way to safely handle sending an invalid polyline3d to CreateFromCurves()?
Reg.
Bjørn Egil Jenssen
Bjørn,
Try use this code snip instead (just an idea not tested)
DBObjectCollection objColl = new DBObjectCollection(); Polyline3d face = new Polyline3d(); //ETC... // or from your settings // Polyline3d face = new Polyline3d(Poly3dType.SimplePoly, vertices, true); if (!face.IsPlanar) { throw new System.Exception("out of luck, bud, it ought be planar"); } else { objColl.Add(face); DBObjectCollection myRegionColl = new DBObjectCollection(); // create a single region Autodesk.AutoCAD.DatabaseServices.Region objreg = new Autodesk.AutoCAD.DatabaseServices.Region(); DBObjectCollection objRegions = new DBObjectCollection(); try { objRegions = Autodesk.AutoCAD.DatabaseServices.Region.CreateFromCurves(objColl); objreg = objRegions[0] as Autodesk.AutoCAD.DatabaseServices.Region; } catch (Autodesk.AutoCAD.Runtime.Exception ex) { // eInvalidInput exception Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Error: unable to create region collection:\n" + ex.Message); } }