CircularArc2d boundings

CircularArc2d boundings

Anonymous
Not applicable
4,289 Views
19 Replies
Message 1 of 20

CircularArc2d boundings

Anonymous
Not applicable

Hi,

is there any way to obtain the boundings of an CircularArc2d object?

Thanks

0 Likes
4,290 Views
19 Replies
Replies (19)
Message 2 of 20

Hallex
Advisor
Advisor

Try this one

             BoundBlock2d bb = arc.BoundBlock;
             Point2d minp = bb.GetMinimumPoint();
             Point2d maxp = bb.GetMaximumPoint();

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 20

Anonymous
Not applicable

Why the attacched polyline has minimum point negative?

MinimumPoint:(-0.0784183035384186,-0.0333440291205946),

MaximumPoint: (0.339761703945585,0.452622696834632)

0 Likes
Message 4 of 20

Anonymous
Not applicable

See Attached Picture

I am not getting a Negative Value

0 Likes
Message 5 of 20

Anonymous
Not applicable

fro2001 is your resuts based on my disegno2.dwg?

 

Here is my code that produce the output:

MinimumPoint: (-0.0784183035384186,-0.0333440291205946),

MaximumPoint: (0.339761703945585,0.452622696834632)

 

 

Document doc Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            PromptEntityResult per = ed.GetEntity("Select a polyline\n");
            if (per.Status == PromptStatus.OK)
            {
                Transaction tr = db.TransactionManager.StartTransaction();
                using (tr)
                {
                    DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);
                    Polyline lwp = obj as Polyline;
                    if (lwp != null)
                    {
                        int vn = lwp.NumberOfVertices;
                        for (int i = 0; i < vn; i++)
                        {
                            SegmentType sg = lwp.GetSegmentType(i);
                            if (sg.ToString().CompareTo("Arc") == 0)
                            {
                                CircularArc2d ar = lwp.GetArcSegment2dAt(i);
                                ed.WriteMessage("ARC******************************************************\n");
                                ed.WriteMessage("Segment:" + i + "\n");
                                BoundBlock2d bb = ar.BoundBlock;
                                Point2d minp = bb.GetMinimumPoint();
                                Point2d maxp = bb.GetMaximumPoint();
                                ed.WriteMessage("MinimumPoint:" + minp + ", MaximumPoint: " + maxp + "\n");
                            }
                            if (sg.ToString().CompareTo("Line") == 0)
                            {
                                LineSegment2d li = lwp.GetLineSegment2dAt(i);
                                ed.WriteMessage("LINE*****************************************************\n");
                                ed.WriteMessage("Segment:" + i + "\n");
                                BoundBlock2d bb = li.BoundBlock;
                                Point2d minp = bb.GetMinimumPoint();
                                Point2d maxp = bb.GetMaximumPoint();
                                ed.WriteMessage("MinimumPoint:" + minp + ", MaximumPoint: " + maxp + "\n");
                            }
                        }
                    }
                }
            }

 

 

0 Likes
Message 6 of 20

Anonymous
Not applicable

First look at the picture and see if that is what you want

 

This draws a rectangle around around the arc using the Entity.GeometricExtents

 

 [CommandMethod("PolyLineExtents")]
        public void PolyLineExtents()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a polyline\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                    BlockTableRecord msBtr = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForRead);

                    Entity ent = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;
                    Point3d min = ent.GeometricExtents.MinPoint;
                    Point3d max = ent.GeometricExtents.MaxPoint;
                    
                    DocumentCollection docs = Application.DocumentManager;                   
                    AcadDocument acadDoc = (AcadDocument)doc.AcadDocument;
                    acadDoc.SendCommand("rec " + min.X + "," + min.Y + " " + max.X + "," + max.Y + " ");
                    tr.Commit();
                }
            }           
        }    

 

0 Likes
Message 7 of 20

Anonymous
Not applicable

The rectangle is exacly what I'm looking for, but I can convert CircularArc2d to Entity?

0 Likes
Message 8 of 20

Anonymous
Not applicable

Here is a different one run on revision cloud (which is nothing but a polyine with arcs) I am not using the GetBoundBlockOf because I can't figure out how to even put the parameter in the right way.

This does not explode the actual object

I changed the current layer before I ran the command to be able to see it better.

See Attached picture

 

 

 [CommandMethod("PolyLineExtents2")]
        public void PolyLineExtents2()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a polyline\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    
                    Entity ent = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Entity;
                    DBObjectCollection dbObjColl = new DBObjectCollection();
                    ent.Explode(dbObjColl);
                    foreach (Entity entExplode in dbObjColl)

                    {                     
                        Point3d min = entExplode.GeometricExtents.MinPoint;
                        Point3d max = entExplode.GeometricExtents.MaxPoint;
                        DocumentCollection docs = Application.DocumentManager;
                        AcadDocument acadDoc = (AcadDocument)doc.AcadDocument;
                        acadDoc.SendCommand("rec " + min.X + "," + min.Y + " " + max.X + "," + max.Y + " ");
                        ed.WriteMessage("\n Min: " + min.ToString() + "\n Max: " + max.ToString());

                    }



                    tr.Commit();
                }
            }
        }

 

0 Likes
Message 9 of 20

Anonymous
Not applicable

Where is included "AcadDocument"? I got the error: The type or namespace name 'AcadDocument' could not be found (are you missing a using directive or an assembly reference?)

Also I have the same problem to convert CircularArc2d to Entity not the selection with "per.ObjectId" that works fine.

 

0 Likes
Message 10 of 20

Hallex
Advisor
Advisor

Include to References acmgdinternal.dll

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 11 of 20

Anonymous
Not applicable
using Autodesk.AutoCAD.Interop;

reference

Autodesk.AutoCAD.Interop

 

I was being lazy and using the rectangle command

0 Likes
Message 12 of 20

Anonymous
Not applicable

Splines will not work right so here a little work around if the spline is small the precision might be set to high and it does not convert it to a polyline it just uses it for the extents.

To see the difference try the first method on a spline then this one or draw a spline and do a SplineEdit or EditSpline then choose purge and when you select it you will see the control points it uses for its extents

 

 

[CommandMethod("BoundBoxSpline")]
        public void BoundBoxSpline()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a Spline\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btrMs = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite);
                    Spline sp = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Spline;
                    Application.SetSystemVariable("PLINECONVERTMODE", 1);
                    sp.ToPolylineWithPrecision(99);
                    Point3d min = sp.GeometricExtents.MinPoint;
                    Point3d max = sp.GeometricExtents.MaxPoint;                    
                    DocumentCollection docs = Application.DocumentManager;
                    AcadDocument acadDoc = (AcadDocument)doc.AcadDocument;                
                    acadDoc.SendCommand("rec " + min.X + "," + min.Y + " " + max.X + "," + max.Y + " ");
                    ed.WriteMessage("\n Min: " + min.ToString() + "\n Max: " + max.ToString());
                    tr.Commit();
                }
            }
        }

 

0 Likes
Message 13 of 20

Anonymous
Not applicable
 CircularArc2d ar = lwp.GetArcSegment2dAt(i);

I do not know if you will have luck converting an entity to  part of entity

0 Likes
Message 14 of 20

Anonymous
Not applicable

I need to get StartPoint, EndPoint, Center for Arc and StartPoint, EndPoint for Line that compose a PolyLine.

Sorry for my inexperienced, but I don't know another way to decompose Polyline as Arc and Line:

CircularArc2d ar = lwp.GetArcSegment2dAt(i);
LineSegment2d li = lwp.GetLineSegment2dAt(i);

 

Is there a better way to do this job and get StartPoint, EndPoint, Center, ent.GeometricExtents.MinPoint, ent.GeometricExtents.MaxPoint?

0 Likes
Message 15 of 20

Anonymous
Not applicable

Do not if you cared are not but some how I changed the the code for spline and it is wrong it should

 

  [CommandMethod("BoundBoxSpline")]
        public void BoundBoxSpline()
        {
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed = doc.Editor;
            PromptEntityResult per = ed.GetEntity("Select a Spline\n");
            if (per.Status == PromptStatus.OK)
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
                    BlockTableRecord btrMs = (BlockTableRecord)bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite);
                    Spline sp = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Spline;
                    Application.SetSystemVariable("PLINECONVERTMODE", 1);
                    Polyline pl = sp.ToPolylineWithPrecision(99) as Polyline;
                    Point3d min = pl.GeometricExtents.MinPoint;
                    Point3d max = pl.GeometricExtents.MaxPoint;
                  
                    DocumentCollection docs = Application.DocumentManager;
                    AcadDocument acadDoc = (AcadDocument)doc.AcadDocument;                
                    acadDoc.SendCommand("rec " + min.X + "," + min.Y + " " + max.X + "," + max.Y + " ");
                    ed.WriteMessage("\n Min: " + min.ToString() + "\n Max: " + max.ToString());
                    tr.Commit();
                }
            }
        }

 

 

0 Likes
Message 16 of 20

Anonymous
Not applicable

For getting boundingbox of a polyline I use:

 

Polyline lwp = obj as Polyline;
object oAcadObj = lwp.AcadObject;
object[] args = new object[2];
args[0] = new VariantWrapper(0);
args[1] = new VariantWrapper(0);
ParameterModifier pm = new ParameterModifier(2);
pm[0] = true;
pm[1] = true;
ParameterModifier[] modifiers = new ParameterModifier[] { pm };
oAcadObj.GetType().InvokeMember("GetBoundingBox", BindingFlags.InvokeMethod, null, oAcadObj, args, modifiers, null, null);
Point3d lowerLeftCorner = new Point3d((double[])args[0]);
Point3d upperRightCorner = new Point3d((double[])args[1]);

 

but my problem remain to find boundingbox of

CircularArc2d ar = lwp.GetArcSegment2dAt(i);
LineSegment2d li = lwp.GetLineSegment2dAt(i);

 

 

Right now I solved for CircularArc2d with Radius and using it in combination with Center and for LineSegment2d with startpoint and endpoint.

Many thanks  fro2001

0 Likes
Message 17 of 20

Anonymous
Not applicable

Are you trying to get bounding box for each segment like the attached picture if so that is BoundBoxExplode which does not actually explode the object but you could iterate through and get all the points.

 

The picture has a polyine with arcs,lines, arcs and lines

 

 

0 Likes
Message 18 of 20

Anonymous
Not applicable

Yes, correct I'm trying to get it.

0 Likes
Message 19 of 20

bikelink
Contributor
Contributor

good solution but I'm not able to find this method from spline object!

ToPolylineWithPrecision()



 


0 Likes
Message 20 of 20

Anonymous
Not applicable

What year are you using?

I know it at least goes back to 2010.

 

0 Likes