Interior Elevation perpendicualr view to the wall

Interior Elevation perpendicualr view to the wall

manuel.serafin6ZWQC
Explorer Explorer
534 Views
2 Replies
Message 1 of 3

Interior Elevation perpendicualr view to the wall

manuel.serafin6ZWQC
Explorer
Explorer

I am working on the development of a tool that inserts interior elevations. The tool places an elevation in the center of the room or if the user decides to place an interior elevation in each of the walls of the room (taking the boundary segments). The problem I am having is that at the moment of inserting the interior elevations in each one I am not getting it to be perpendicual to the wall (Image 1 is how it should be and image 2 is how it is being).

 

Image 1:

manuelserafin6ZWQC_1-1715189818136.png

 

Image 2:

manuelserafin6ZWQC_0-1715189753513.png

 

This is the part of the code I am working with:

        private void CreateElevationBySegment(Document doc, Room room)
        {
            Transaction t = new Transaction(doc, "Create Elevation by Segment");
            t.Start();

            try
            {
                ViewFamilyType vft = new FilteredElementCollector(doc)
                    .OfClass(typeof(ViewFamilyType))
                    .Cast<ViewFamilyType>()
                    .FirstOrDefault(x => x.ViewFamily == ViewFamily.Elevation && x.Name.Contains("Interior"));

                if (vft == null)
                {
                    MessageBox.Show("No interior elevation view type was found.");
                    t.RollBack();
                    return;
                }

                List<Wall> walls = GetRoomWalls(room);
                foreach (Wall wall in walls)
                {
                    XYZ wallCenter = GetWallCenter(wall);
                    XYZ wallDirection = GetWallDirection(wall);
                    XYZ perpendicularDirection = new XYZ(-wallDirection.Y, wallDirection.X, 0);

                    ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, vft.Id, wallCenter, 1);
                    ViewSection elevationView = marker.CreateElevation(doc, activeView.Id, 0);

                    double angle = Math.Atan2(perpendicularDirection.Y, perpendicularDirection.X);
                    Line rotationAxis = Line.CreateBound(wallCenter, wallCenter + XYZ.BasisZ);
                    ElementTransformUtils.RotateElement(doc, elevationView.Id, rotationAxis, angle);
                }

                t.Commit();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create elevations: " + ex.Message);
                t.RollBack();
            }
        }

        private XYZ GetWallDirection(Wall wall)
        {
            LocationCurve curve = wall.Location as LocationCurve;
            XYZ start = curve.Curve.GetEndPoint(0);
            XYZ end = curve.Curve.GetEndPoint(1);
            return (end - start).Normalize();
        }

        private XYZ GetWallCenter(Wall wall)
        {
            LocationCurve wallLocation = wall.Location as LocationCurve;
            if (wallLocation != null && wallLocation.Curve is Line)
            {
                Line line = wallLocation.Curve as Line;
                return (line.GetEndPoint(0) + line.GetEndPoint(1)) / 2;
            }
            return null;
        }

 

I would appreciate any support you can give me.

0 Likes
Accepted solutions (1)
535 Views
2 Replies
Replies (2)
Message 2 of 3

TripleM-Dev.net
Advisor
Advisor
Accepted solution

Hi @manuel.serafin6ZWQC,

 

I didn't catch it directly but you're rotating the view and not the marker.

 

ElevationMarker marker = ElevationMarker.CreateElevationMarker(doc, vft.Id, wallCenter, 1);
                    ViewSection elevationView = marker.CreateElevation(doc, activeView.Id, 0);

                    double angle = Math.Atan2(perpendicularDirection.Y, perpendicularDirection.X);
                    Line rotationAxis = Line.CreateBound(wallCenter, wallCenter + XYZ.BasisZ);
                    ElementTransformUtils.RotateElement(doc, elevationView.Id, rotationAxis, angle);
// elevationView.Id => this is the view, replace with marker.id

 

Getting the view correcly sized and pointing to the right side of the wall will need some work.

 

- Michel

Message 3 of 3

manuel.serafin6ZWQC
Explorer
Explorer
I tell you in Spanish “SOS UN GRANDE!!” thank you very much for your answer, I was lost and I didn't know how to solve it.
0 Likes