Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How get coordinates of Section Box?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
AndrewButenko
1709 Views, 5 Replies

How get coordinates of Section Box?

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

 

 

5 REPLIES 5
Message 2 of 6
aignatovich
in reply to: AndrewButenko

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

Message 3 of 6
AndrewButenko
in reply to: aignatovich

Do you have example?

Message 4 of 6
aignatovich
in reply to: AndrewButenko

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();
            }
Message 5 of 6
AndrewButenko
in reply to: aignatovich

Thank you. It's work!

Message 6 of 6
User_2011
in reply to: AndrewButenko

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.

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


Rail Community