Happy Friday everyone! Today has completed my second week of WFH and I have to say, I appreciate the short commute. I hope you have settled into a new routine as well and have all been staying safe and healthy.
As you know, I am tackling placing exterior elevations based on selected walls. An important step of our plug-in is to correctly align our elevation marker to our wall. When we placed our marker in Part 1, we put the ViewSection on the first available index on the marker. Now, we need to rotate the marker to correctly align to the wall. This will work for both orthogonal and angled walls.
Part 1: elevation by wall
Part 2: phases
In order to get the angle that we will use to rotate the elevation marker, we first need to get the normal of the ViewSection. This is the vector of the direction that the view is looking. The only points that you can look up for a ViewSection are the minimum and maximum corners of the crop box. Normally, when rotating elevation markers, you can work in the model coordinate system. This is because the ViewSection CropBox and the elevation Marker are both in the model coordinate system. However, it is not possible to find all four corners of a rectangle without also knowing the transform angle. Since we know that in the view’s coordinate system, the transform angle is zero, we need to transform our points into the view’s coordinate system. Once the points are transformed, we know that the vector we are looking for is in the negative Z direction. Then we apply the inverse transform to get the endpoints of the vector back into the model coordinate system and subtract them to get the ViewSection normal.
The second part is finding the normal of our wall. In Revit, the normal of an exterior walls points to the outside. Walls have an Orientation property which is the wall’s normal. Once we have the ViewSection normal and the Wall normal, we can determine the angle between. Since we want these two vectors facing each other, we want the angle between them to be Pi radians (180 degrees). So we take Pi radians and subtract the current angle between the two vectors that we found.
The other aspect to consider is that the AngleTo method does not return a negative angle. Because of this, we have to manually determine which direction to rotate the elevation marker (clockwise or counter clockwise). We can write a simple if statement to do this.
Finally, we have the angle we need to rotate our elevation Marker. We can create an axis of rotation at the center of the elevation Marker and rotate it by the angle we determined in the previous step.
The elevation marker needs to be rotated after it is placed so we can add our new methods to our Execute method after the marker is created.
And that is how we can rotate our markers to face our exterior walls regardless of if they are orthogonal or at a different angle. The last couple items we want to look at are associating the Marker with the correct level, cropping the view to the extents of the wall, and allowing users to select walls in their project.