Good day everyone,
Please read fully before suggesting custom packages to me chances are ive already tried them to no avail.
I am trying to make a 3d view with a section box applied to isolate a room for creating 3D Views for C Sheets however for some reason I cant get the section box to update in the new 3d view. The view I have been using has a section box applied to it already and it wont update I have also tried it with a 3d view without a section box applied and also doesnt work. I have tried every package under the sun and none seem to work for me hence why im asking for help from the big guns (the people in these forums)
I have attached the file so feel free to interrogate and alter.
Generate 3D View_script.dyn (76.6 KB)
It would be helpful if you shared a screenshot of your graph in action, with all node preview bubbles pinned and any warning messages you may be getting.
Hi Nick,
Im not getting any error messages its just simply not updating the section box but Ive attached a screenshot showing all node preview bubbles pinned as well as the custom Python code running in the graph.
Custom Code Below:
# Import necessary modules from Revit and Dynamo
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference('RevitNodes')
clr.AddReference('RevitAPIUI')
clr.AddReference('ProtoGeometry') # For converting Dynamo Points
from Autodesk.DesignScript.Geometry import Point as DSPoint # Import Dynamo Point
from Autodesk.Revit.DB import XYZ, BoundingBoxXYZ, View3D
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
# Inputs from Dynamo
min_ds_point = IN[0] # MinPoint (Dynamo's DesignScript Point or list of Points)
max_ds_point = IN[1] # MaxPoint (Dynamo's DesignScript Point or list of Points)
views = IN[2] # AxonometricView or list of views (Revit's View3D)
# Convert Dynamo DesignScript Points to Revit XYZ points
def convert_to_xyz(ds_point):
if isinstance(ds_point, list): # If it's a list, extract the first point
ds_point = ds_point[0]
return XYZ(ds_point.X, ds_point.Y, ds_point.Z)
# Convert min and max points from Dynamo to Revit XYZ
min_point = convert_to_xyz(min_ds_point)
max_point = convert_to_xyz(max_ds_point)
# Access the current Revit document
doc = DocumentManager.Instance.CurrentDBDocument
# Ensure views input is a list, even if a single item is provided
if not isinstance(views, list):
views = [views]
# Debugging: Output values of MinPoint and MaxPoint to check their validity
OUT = ["Converted MinPoint: {}".format(min_point), "Converted MaxPoint: {}".format(max_point)]
# Function to validate and log bounding box
def validate_bounding_box(min_pt, max_pt):
# Ensure MaxPoint > MinPoint in all axes
if min_pt.X >= max_pt.X or min_pt.Y >= max_pt.Y or min_pt.Z >= max_pt.Z:
raise Exception("Invalid bounding box: MaxPoint must be greater than MinPoint.")
return True
# Function to debug the current section box values
def log_current_section_box(view):
# Log the current section box of the view
section_box = view.GetSectionBox()
min_coords = (section_box.Min.X, section_box.Min.Y, section_box.Min.Z)
max_coords = (section_box.Max.X, section_box.Max.Y, section_box.Max.Z)
OUT.append("Current section box Min: {}, Max: {}".format(min_coords, max_coords))
OUT.append("Current section box size: X: {}, Y: {}, Z: {}".format(
max_coords[0] - min_coords[0],
max_coords[1] - min_coords[1],
max_coords[2] - min_coords[2]
))
# Start a transaction for modifying the Revit document
TransactionManager.Instance.EnsureInTransaction(doc)
try:
for view in views:
if isinstance(view, View3D): # Ensure the object is a 3D view
# Log current section box before applying the new one
log_current_section_box(view)
# Check if the section box is enabled in the view
if not view.IsSectionBoxActive:
view.IsSectionBoxActive = True # Enable the section box if it's not already enabled
# Validate the Min and Max points before applying them
validate_bounding_box(min_point, max_point)
# Create a new BoundingBoxXYZ with the MinPoint and MaxPoint
section_box = BoundingBoxXYZ()
section_box.Min = min_point
section_box.Max = max_point
# Explicitly apply the bounding box to the view's section box
view.SetSectionBox(section_box)
# Regenerate the document to apply the changes immediately
doc.Regenerate()
# Log new section box after applying it
log_current_section_box(view)
finally:
# Complete the transaction
TransactionManager.Instance.TransactionTaskDone()
# Output (optional)
OUT.append("Section box updated successfully")