How get coordinates of Section Box?

How get coordinates of Section Box?

AndrewButenko
Advocate Advocate
2,330 Views
5 Replies
Message 1 of 6

How get coordinates of Section Box?

AndrewButenko
Advocate
Advocate

Hello!

 

I draw boundary lines of section box with next code:

 

 Dim startView As View3D = doc.ActiveView


            Dim ln As Line


            Dim p1 As XYZ = New XYZ(startView.GetSectionBox.Min.X, startView.GetSectionBox.Min.Y, 0)
            Dim p2 As XYZ = New XYZ(startView.GetSectionBox.Min.X, startView.GetSectionBox.Max.Y, 0)



            ln = Line.CreateBound(p1, p2)
            drawCurveDoc(doc, ln)


            p1 = p2
            p2 = New XYZ(startView.GetSectionBox.Max.X, startView.GetSectionBox.Max.Y, 0)
            ln = Line.CreateBound(p1, p2)
            drawCurveDoc(doc, ln)

            p1 = p2
            p2 = New XYZ(startView.GetSectionBox.Max.X, startView.GetSectionBox.Min.Y, 0)
            ln = Line.CreateBound(p1, p2)
            drawCurveDoc(doc, ln)

            p1 = p2
            p2 = New XYZ(startView.GetSectionBox.Min.X, startView.GetSectionBox.Min.Y, 0)
            ln = Line.CreateBound(p1, p2)
            drawCurveDoc(doc, ln)

  

But my model lines  far away of selection box:

еееее.png

 

 

0 Likes
Accepted solutions (1)
2,331 Views
5 Replies
Replies (5)
Message 2 of 6

aignatovich
Advisor
Advisor

Hi!

 

Your bounding box has transform, that differs from Transform.Identity. So, you should apply transform to min & max points and use transform basic vectors to determine box lines direction, or calculate corner points and apply transform to them

0 Likes
Message 3 of 6

AndrewButenko
Advocate
Advocate

Do you have example?

0 Likes
Message 4 of 6

aignatovich
Advisor
Advisor
Accepted solution

Look at this:

 

            var uiapp = commandData.Application;
            var uidoc = uiapp.ActiveUIDocument;

            var doc = uidoc.Document;

            var view = doc.ActiveView as View3D;

            if (view == null || !view.IsSectionBoxActive)
            {
                message = "This works only in 3D views with activated section box";

                return Result.Failed;
            }

            var box = view.GetSectionBox();

            var points = new[]
                {
                    box.Min,
                    new XYZ(box.Max.X, box.Min.Y, box.Min.Z),
                    new XYZ(box.Max.X, box.Max.Y, box.Min.Z),
                    new XYZ(box.Min.X, box.Max.Y, box.Min.Z)
                }
                .Select(box.Transform.OfPoint)
                .Select(x => new XYZ(x.X, x.Y, 0))
                .ToList();

            var lines = new[]
                {
                    Line.CreateBound(points[0], points[1]),
                    Line.CreateBound(points[1], points[2]),
                    Line.CreateBound(points[2], points[3]),
                    Line.CreateBound(points[3], points[0])
                };

            using (var transaction = new Transaction(doc, "draw box"))
            {
                transaction.Start();

                var sketchPlane = SketchPlane.Create(doc, Plane.CreateByNormalAndOrigin(XYZ.BasisZ, XYZ.Zero));

                foreach (var line in lines)
                    doc.Create.NewModelCurve(line, sketchPlane);

                transaction.Commit();
            }
0 Likes
Message 5 of 6

AndrewButenko
Advocate
Advocate

Thank you. It's work!

0 Likes
Message 6 of 6

User_2011
Advocate
Advocate

How do you upload it in Revit and how do you execute it, what command / shortcut?

I'm sure is similar to CAD with APPLOAD lisp, but I am new in Revit and frustrated that i am forced to work in Revit.

0 Likes