I am working on this code, and I can make it work with the Create Section method. However, what I need is for this code to create a 2D section from the left or bottom of the conduit, depending on orientation. When i try the Create Detail method, I must not be passing the right arguements because I get an error. I am new to pyrevit and the revit api in general. Any help would be greatly appreciated!
import Autodesk.Revit.DB as DB
from pyrevit import revit, forms
# Prompt user to select a conduit
selection = revit.pick_elements()
conduit = selection # Select the first element if multiple are picked
# Acquire the bounding box of the conduit
bbox = conduit.get_BoundingBox(None)
min_point = bbox.Min
max_point = bbox.Max
# Create a 2D section view
view_family_type = revit.doc.GetDefaultElementTypeId(DB.ElementTypeGroup.ViewTypeSection)
with revit.Transaction("Create 2D Section"):
section_view = DB.ViewSection.CreateSection(revit.doc, view_family_type, bbox)
section_view.Name = "Conduit Section"
print("2D Section view created successfully.")
print("No conduit selected.")
It does but it only makes a plan view section. I’m not sure how exactly, but I need to make a section from the side. I have looked into transforming the bounding box so it looks at the element from the side but haven’t managed to make that work.
Create a section whose view volume corresponds geometrically with the specified sectionBox.
The view direction of the resulting section will be sectionBox.Transform.BasisZ and the up direction will be sectionBox.Transform.BasisY.
The right hand direction will be computed so that (right, up, view direction) form a left handed coordinate system.
The resulting view will be cropped, and far clipping will be active.
The crop region will correspond to the projections of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max onto the view’s cut plane.
The far clip distance will be equal to the difference of the z-coordinates of BoundingBoxXYZ.Min and BoundingBoxXYZ.Max.
The new section ViewSection will receive a unique view name.
So you have to pass in a bounding box that is already oriented in the direction you need.
if you already have a view aligned to the item, you can pass it to the get_BoundingBox method instead of None.
From Conduit.BoundingBox remarks:
Pass in a view to query view-specific (e.g., cut) geometry or a null reference (None) for model geometry.