Let's break down the problem and the modern solution:
The Challenge:
Section view markers are represented by ViewSection
elements. Their geometry, specifically the endpoint location, is tied to the view's crop region and internal Revit workings. Directly setting the endpoint coordinates can lead to unexpected behavior or exceptions because Revit manages the relationship between the section line and the generated section view.
The Modern Solution: CropBox
Manipulation
The key is to understand that the section line's endpoint is directly related to the section view's CropBox
. By modifying the CropBox
, we indirectly control the section line's endpoint. This avoids the transactional complexities of the older approach.
Here's a breakdown of the process and a C# code example:
-
Get the ViewSection
: Obtain the ViewSection
element representing the section view marker you want to modify. You can do this by selecting it, iterating through views, or other methods depending on your add-in's context.
-
Access the CropBox
: The ViewSection
has a CropBox
property. This is the crucial element we need to manipulate.
-
Modify the CropBox
's Max
or Min
Point: The CropBox
is defined by a BoundingBoxXYZ
. The section line's endpoint corresponds to one of the corner points of this bounding box. You'll typically adjust the Max
point in the direction of the section line.
-
Update the ViewSection
: After modifying the CropBox
, the ViewSection
will automatically update, reflecting the changed endpoint. No explicit transaction is required for this specific operation.
Key Improvements over the "Temporary Transaction Trick":
- Simplicity: Direct
CropBox
manipulation is much more straightforward than managing temporary transactions.
- Performance: Avoids the overhead of creating and committing transactions, resulting in better performance, especially when modifying multiple section endpoints.
- Clarity: The code is more readable and easier to understand, making maintenance and debugging simpler.
Important Considerations:
- Section Direction: Ensure you modify the correct
CropBox
point (Max
or Min
) and the appropriate coordinates (X, Y, or Z) based on the section view's direction.
- Units: Work with Revit's internal units (feet). Convert to/from your desired units as needed.
- Error Handling: Include robust error handling to handle cases where the selected element isn't a
ViewSection
or if other unexpected issues occur.
- View Refresh: The
uidoc.RefreshActiveView()
is often crucial to immediately visualize the change in the Revit UI.
By using this CropBox
approach, you can efficiently and reliably manipulate section view marker endpoints in your Revit add-ins, leveraging the power of the modern Revit API. This method is significantly more efficient and easier to maintain than the older transactional workarounds.
What say you? True, false, ridiculous, helpful? Exploring the new technology and its limits... Thank you for checking and letting us know.