.NET

Reply
Active Contributor
42 Posts
0 Kudos
Registered: ‎07-02-2013
Post 1 of 4

All values of bounding box

228 Views, 3 Replies
07-03-2013 04:57 AM

Hi,

Is it possible to get all the 4 values of the bounding box for a particular object.I have to plot a curve of maximum point for a particular object on a given path at certain intervals(ex: a block on a curved line and distance between each block should be maintained say 10mm).The problem im facing when im connecting the maximum points is if the path is inclined then the maximum point coonecting line intersects the block at some places.Can anyone suggest any other solution?

*Expert Elite*
2,142 Posts
255 Kudos
Registered: ‎04-29-2006
Post 2 of 4

Re : All values of bounding box

07-03-2013 05:09 AM in reply to: gulzar25

Hi

 

The edges of a 'bounding box' are parallel to the WCS axis, so the 4 2d points are (assuming ext is an Extents3d instance as returned by Entity.GeomatricExtents) :

 

Point3d p1 = new Point2d(ext.MinPoint.X, ext.MinPoint.Y, 0.0);
Point3d p2 = new Point2d(ext.MaxPoint.X, ext.MinPoint.Y, 0.0);
Point3d p3 = new Point2d(ext.MaxPoint.X, ext.MaxPoint.Y, 0.0);
Point3d p4 = new Point2d(ext.MinPoint.X, ext.MaxPoint.Y, 0.0);

 

Gilles Chanteau
*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 3 of 4

Re: All values of bounding box

07-03-2013 12:10 PM in reply to: gulzar25

Try this code, just use a filtered selection set for your blocks selection:

         [CommandMethod("bbx")]
        public void testBlockReferencesBounds()
        {
           
            Document doc=Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
            Database db = doc.Database;
            Editor ed=doc.Editor;
            try
            {
                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                    // for the quick test iterate through objects in the current space,
                    // use filtered selection by block name instead: //
                    foreach (ObjectId obj in btr)
                    {
                        Entity ent = (Entity)tr.GetObject(obj, OpenMode.ForRead);
                        BlockReference bref = ent as BlockReference;
                        if (bref != null)
                        {
                            bref.UpgradeOpen();
                            Point3d pp = bref.Position;
                            double rot = bref.Rotation;
                            bref.TransformBy(Matrix3d.Rotation(-1.0 * rot, Vector3d.ZAxis,pp));

                            Extents3d ext = bref.GeometryExtentsBestFit(ed.CurrentUserCoordinateSystem);                                                   
                             Autodesk.AutoCAD.Geometry.Point3d min = ext.MinPoint;
                             Autodesk.AutoCAD.Geometry.Point3d max = ext.MaxPoint;

                             Polyline pl = new Polyline();
                             pl.SetDatabaseDefaults();
                             Point2d p1 = new Point2d(min.X, min.Y);
                             Point2d p2 = new Point2d(min.X, max.Y);
                             Point2d p3 = new Point2d(max.X, max.Y);
                             Point2d p4 = new Point2d(max.X, min.Y);
                             pl.AddVertexAt(0, p1, 0, 0, 0);
                             pl.AddVertexAt(1, p2, 0, 0, 0);
                             pl.AddVertexAt(2, p3, 0, 0, 0);
                             pl.AddVertexAt(3, p4, 0, 0, 0);
                             pl.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(Autodesk.AutoCAD.Colors.ColorMethod.ByAci, 16);
                             pl.Closed = true;
                             
                             btr.AppendEntity(pl);
                             tr.AddNewlyCreatedDBObject(pl, true);
                             pl.TransformBy(Matrix3d.Rotation(rot, Vector3d.ZAxis, pp));
                             bref.TransformBy(Matrix3d.Rotation( rot, Vector3d.ZAxis, pp));
                  
                        }
                    }
                    tr.Commit();
                }
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ax) 
            { 
                ed.WriteMessage("\n" + ax.Message); 
            }
            catch (System.Exception ex) 
            { 
                ed.WriteMessage("\n" + ex.Message);
            }
            finally
            {
                ed.WriteMessage("\nCheck bounding boxes.");
            }
        }

 

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Active Contributor
42 Posts
0 Kudos
Registered: ‎07-02-2013
Post 4 of 4

Re : All values of bounding box

07-03-2013 08:47 PM in reply to: _gile
Hi,
Thanks a lot for the reply im looking for 3d point and im facing collision problem between the maximum points connecting line and the block when the path is at an inclination.
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!