.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Region.CreateFromCurves() issues

5 REPLIES 5
Reply
Message 1 of 6
bej
Contributor
2336 Views, 5 Replies

Region.CreateFromCurves() issues

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

5 REPLIES 5
Message 2 of 6
_gile
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
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 6
bej
Contributor
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

Message 4 of 6
bej
Contributor
in reply to: bej

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

 

 

Reg.

Bjørn Egil Jenssen

Message 5 of 6
SEANT61
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.

************************************************************
May your cursor always snap to the location intended.
Message 6 of 6
Hallex
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost