.NET

Reply
Contributor bej
Contributor
bej
Posts: 15
Registered: ‎11-21-2012
Message 1 of 6 (216 Views)

Region.CreateFromCurves() issues

216 Views, 5 Replies
03-21-2014 06:17 AM

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

*Expert Elite*
_gile
Posts: 2,084
Registered: ‎04-29-2006
Message 2 of 6 (203 Views)

Re : Region.CreateFromCurves() issues

03-21-2014 07:12 AM in reply to: bej

hi,

 

It seems to me the curves passed to CreateFromCurves have to lie on the same plane. Are you sure your Polyline3d are stricly planar ?

Gilles Chanteau
Contributor bej
Contributor
bej
Posts: 15
Registered: ‎11-21-2012
Message 3 of 6 (198 Views)

Re : Region.CreateFromCurves() issues

03-21-2014 07:58 AM in reply to: _gile

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

Contributor bej
Contributor
bej
Posts: 15
Registered: ‎11-21-2012
Message 4 of 6 (195 Views)

Re : Region.CreateFromCurves() issues

03-21-2014 08:01 AM in reply to: bej

Alternativly, is there a way to safely handle sending an invalid polyline3d to CreateFromCurves()?

 

 

Reg.

Bjørn Egil Jenssen

Distinguished Contributor
SEANT61
Posts: 125
Registered: ‎09-23-2008
Message 5 of 6 (183 Views)

Re : Region.CreateFromCurves() issues

03-21-2014 11:32 AM in reply to: bej
Another issue that may come into play - with regard to decreasing AutoCAD stability – is the ultimate fate of that newly created Polyline3d.

You may already have this set up in some latter portion of code but; unless committed via Transaction, the poly3d needs to be disposed.
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 6 of 6 (165 Views)

Re: Region.CreateFromCurves() issues

03-22-2014 05:28 AM in reply to: bej

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);

                    }
                }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.