API to get bounding box of Baseline region

API to get bounding box of Baseline region

Anonymous
Not applicable
1,621 Views
3 Replies
Message 1 of 4

API to get bounding box of Baseline region

Anonymous
Not applicable

Hi,

I am implementing zoom for baseline Region.

For that I need a bounding box of baseline Region.

Is there any API to get bounding box of Baseline region.

 

Thanking you for all your help,
Mahesh

0 Likes
Accepted solutions (1)
1,622 Views
3 Replies
Replies (3)
Message 2 of 4

Anonymous
Not applicable
Hi,

Please keep this open. I want to calculate bounding box of Baseline Region from API so that I can implement zoom functionality from API which works as possible close to zoom in for Baseline region from GUI.
Is there any API to get the bounding box extents of Baseline Region? (Or is there any API to directly Zoom In to any Baseline Region using API)

Regards,
Mahesh
0 Likes
Message 3 of 4

Jeff_M
Consultant
Consultant
Accepted solution

Here is an extension method for a BaseLineRegion that returns the Extents3D bounding box (at 0 elevation, it wouldn't take too much to convert to a true 3d box if you need that). Note that the Subassemblies used must have a "Top" link for this to work.

 

/// 
/// Created by Jeff Mishler
/// Quux Software LLC
/// http://www.quuxsoft.com
/// All rights reserved.
/// 


using System;
using System.Collections.Generic;
using System.Linq;
using Autodesk.AutoCAD.DatabaseServices;
using AcDb = Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.Civil.DatabaseServices;
using Quux.AcadUtilities;


namespace Quux.C3DUtilities.Extensions
{
    public static class BaselineRegionExtensions
    {
        public static Extents3d BoundingBox(this BaselineRegion bsregion)
        {
            List<OffsetPoints> pts = new List<OffsetPoints>();
            Baseline bsline = null;
            using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
            {
                var corr = (Corridor)tr.GetObject(bsregion.CorridorId, OpenMode.ForRead);
                foreach (Baseline bsl in corr.Baselines)
                {
                    foreach (BaselineRegion bsr in bsl.BaselineRegions)
                    {
                        if (bsr.Name== bsregion.Name && bsr.StartStation == bsregion.StartStation && bsr.EndStation==bsregion.EndStation)
                        {
                            bsline = bsl;
                            break;
                        }
                    }
                    if (bsline != null)
                        break;
                }
                tr.Commit();
            }
            foreach (AppliedAssembly assy in bsregion.AppliedAssemblies)
            {
                CalculatedLinkCollection links = assy.GetLinksByCode("Top");
                double maxLeftOffset = 0, maxRightOffset = 0;
                OffsetPoints offpts = new OffsetPoints();
                bool firstpt = true;
                foreach (CalculatedLink link in links)
                {
                    foreach (CalculatedPoint cpt in link.CalculatedPoints)
                    {
                        Point3d offPt = cpt.StationOffsetElevationToBaseline;
                        double offset = offPt.Y;
                        if (firstpt)
                        {
                            maxLeftOffset = offset;
                            maxRightOffset = offset;
                            offpts.LeftOffset = bsline.StationOffsetElevationToXYZ(offPt);
                            offpts.RightOffset = bsline.StationOffsetElevationToXYZ(offPt);
                            firstpt = false;
                        }
                        else
                        {
                            if (offset < maxLeftOffset)
                            {
                                maxLeftOffset = offset;
                                offpts.LeftOffset = bsline.StationOffsetElevationToXYZ(offPt);
                                continue;
                            }
                            else if (offset > maxRightOffset)
                            {
                                maxRightOffset = offset;
                                offpts.RightOffset = bsline.StationOffsetElevationToXYZ(offPt);
                            }
                        }
                    }
                }
                pts.Add(offpts);
            }
            Point2dCollection bndypts = new Point2dCollection();
            for (int i = 0; i < pts.Count; i++)
            {
                bndypts.Add(new Point2d(pts[i].LeftOffset.X, pts[i].LeftOffset.Y));
            }
            for (int i = pts.Count - 1; i > -1; i--)
            {
                bndypts.Add(new Point2d(pts[i].RightOffset.X, pts[i].RightOffset.Y));
            }
            Polyline pline = new Polyline(bndypts.Count);
            for (int i = 0; i < bndypts.Count; i++)
            {
                pline.AddVertexAt(i, bndypts[i], 0, 2, 2);
            }
            pline.Closed = true;
            pline.Elevation = 0;
            var retval = pline.GeometricExtents;
            pline.Dispose();
            return retval;
        }
    }
}
Jeff_M, also a frequent Swamper
EESignature
0 Likes
Message 4 of 4

Anonymous
Not applicable
Thank you Jeff_M.
It is working well for my scenario.
-Mahesh
0 Likes