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

CircularArc2d boundings

19 REPLIES 19
Reply
Message 1 of 20
flovo
1135 Views, 19 Replies

CircularArc2d boundings

Hi,

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

Thanks

19 REPLIES 19
Message 2 of 20
Hallex
in reply to: flovo

Try this one

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

 

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 20
flovo
in reply to: Hallex

Why the attacched polyline has minimum point negative?

MinimumPoint:(-0.0784183035384186,-0.0333440291205946),

MaximumPoint: (0.339761703945585,0.452622696834632)

Message 4 of 20
Jeffrey_H
in reply to: flovo

See Attached Picture

I am not getting a Negative Value

You can also find your answers @ TheSwamp
Message 5 of 20
flovo
in reply to: Jeffrey_H

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

 

 

Message 6 of 20
Jeffrey_H
in reply to: flovo

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

 

You can also find your answers @ TheSwamp
Message 7 of 20
flovo
in reply to: flovo

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

Message 8 of 20
Jeffrey_H
in reply to: flovo

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

 

You can also find your answers @ TheSwamp
Message 9 of 20
flovo
in reply to: flovo

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.

 

Message 10 of 20
Hallex
in reply to: flovo

Include to References acmgdinternal.dll

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 11 of 20
Jeffrey_H
in reply to: Hallex

using Autodesk.AutoCAD.Interop;

reference

Autodesk.AutoCAD.Interop

 

I was being lazy and using the rectangle command

You can also find your answers @ TheSwamp
Message 12 of 20
Jeffrey_H
in reply to: Jeffrey_H

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

 

You can also find your answers @ TheSwamp
Message 13 of 20
Jeffrey_H
in reply to: Jeffrey_H

 CircularArc2d ar = lwp.GetArcSegment2dAt(i);

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

You can also find your answers @ TheSwamp
Message 14 of 20
flovo
in reply to: Jeffrey_H

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?

Message 15 of 20
Jeffrey_H
in reply to: flovo

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

 

 

You can also find your answers @ TheSwamp
Message 16 of 20
flovo
in reply to: Jeffrey_H

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

Message 17 of 20
Jeffrey_H
in reply to: flovo

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

 

 

You can also find your answers @ TheSwamp
Message 18 of 20
flovo
in reply to: Jeffrey_H

Yes, correct I'm trying to get it.

Message 19 of 20
bikelink
in reply to: Jeffrey_H

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

ToPolylineWithPrecision()



 


Message 20 of 20
Jeffrey_H
in reply to: bikelink

What year are you using?

I know it at least goes back to 2010.

 

You can also find your answers @ TheSwamp

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