Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
Image 2:
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.
Solved! Go to Solution.