.NET

Reply
Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 11 of 20 (609 Views)

Re: CircularArc2d boundings

09-20-2010 02:05 AM 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
Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 12 of 20 (605 Views)

Re: CircularArc2d boundings

09-20-2010 02:14 AM 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
Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 13 of 20 (603 Views)

Re: CircularArc2d boundings

09-20-2010 02:25 AM 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
Contributor
mperelli
Posts: 20
Registered: ‎07-15-2010
Message 14 of 20 (597 Views)

Re: CircularArc2d boundings

09-20-2010 03:07 AM 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?

Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 15 of 20 (574 Views)

Re: CircularArc2d boundings

09-23-2010 11:20 PM in reply to: mperelli

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
Contributor
mperelli
Posts: 20
Registered: ‎07-15-2010
Message 16 of 20 (565 Views)

Re: CircularArc2d boundings

09-24-2010 01:46 AM 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

Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 17 of 20 (559 Views)

Re: CircularArc2d boundings

09-24-2010 03:17 AM in reply to: mperelli

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
Contributor
mperelli
Posts: 20
Registered: ‎07-15-2010
Message 18 of 20 (552 Views)

Re: CircularArc2d boundings

09-24-2010 04:58 AM in reply to: Jeffrey_H

Yes, correct I'm trying to get it.

Valued Contributor
bikelink
Posts: 54
Registered: ‎11-25-2001
Message 19 of 20 (418 Views)

Re: CircularArc2d boundings

10-22-2010 09:02 AM in reply to: Jeffrey_H

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

ToPolylineWithPrecision()



 


Valued Mentor
Jeffrey_H
Posts: 372
Registered: ‎01-20-2010
Message 20 of 20 (406 Views)

Re: CircularArc2d boundings

10-22-2010 01:26 PM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.