bb_filter below in the code is not finding any intersection with RevitLinkInstances… When set to invert (True) I see them. Also if I change the Class to say walls in the filter it finds them, so the Outline is properly sized. I have also used the “tolerance” property both negative and positive with no results where a RevitLinkInstance is found. I am missing something fundamental here… Any help on the concept(s) I am missing would be apreciated.
The goal is to find all the Unit links in the 3D View and tag them. By the way I am struggleing with the regeneration within the transaction of every tag being procced. First things first, the BoundingBoxIntersectsFilter(), I need to understand. Note: I commented out the tag feature as it will take forever with the regenerations during testing and the xxx is just for checking the output.
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from System.Collections.Generic import *
# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Define constant offsets in feet
OFFSET_HORIZONTAL_FEET = 10.0
OFFSET_VERTICAL_FEET = 20
xxx = []
# Get all levels in the current document that are not from a linked model
levels = FilteredElementCollector(doc).OfClass(Level)
levels_not_linked = []
for level in levels:
if not level.Document.IsLinked:
levels_not_linked.append(level)
# Get all floors on each level and find the one with the largest area
largest_floors = {}
for level in levels_not_linked:
floors = FilteredElementCollector(doc).OfClass(Floor).WherePasses(ElementLevelFilter(level.Id)).ToElements()
if floors: # Check if there are any floors on the level
max_area = 0
largest_floor = None
for floor in floors:
area = floor.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble() # Get area as a double
if area > max_area:
max_area = area
largest_floor = floor
largest_floors[level.Name] = largest_floor
#get ViewFamilyType for a 3D View
collector = FilteredElementCollector(doc)
viewTypeColl = collector.OfClass(ViewFamilyType)
for i in viewTypeColl:
if i.ViewFamily == ViewFamily.ThreeDimensional:
viewType = i
else:
continue
# "Start" the transaction
TransactionManager.Instance.EnsureInTransaction(doc)
for level_name, floor in largest_floors.items():
# Set viewName to match the level name with a prefix of "Iso - "
viewName = f"Iso - {level_name}"
# Get the bounding box of the largest floor
bbox_floor = floor.get_BoundingBox(doc.ActiveView)
# Get the thickness parameter of the largest floor
largest_floor_thickness = floor.get_Parameter(BuiltInParameter.FLOOR_ATTR_THICKNESS_PARAM)
if largest_floor_thickness:
thickness_value = largest_floor_thickness.AsDouble()
adjusted_thickness = thickness_value - 0.333
# Define bounding box enclosing the largest floor with offset and adjusted thickness
bbox = BoundingBoxXYZ()
bbox.Min = XYZ((bbox_floor.Min.X - OFFSET_HORIZONTAL_FEET), (bbox_floor.Min.Y - OFFSET_HORIZONTAL_FEET), (bbox_floor.Min.Z + adjusted_thickness))
bbox.Max = XYZ((bbox_floor.Max.X + OFFSET_HORIZONTAL_FEET), (bbox_floor.Max.Y + OFFSET_HORIZONTAL_FEET), bbox_floor.Max.Z + OFFSET_VERTICAL_FEET)
# Convert the bounding box to an outline
outline = Outline(bbox.Min, bbox.Max)
# Create 3D View
view = View3D.CreateIsometric(doc, viewType.Id)
view.Name = viewName
# Ensure that the Section Box is active
view.IsSectionBoxActive = True
# Update the section box to match the size defined in the bbox herein
view.SetSectionBox(bbox)
# Lock the view (bottom center of Revit screen house with padlock icon)
#view.Pinned = True
# Locks the view and saves its orientation
view.SaveOrientationAndLock()
# Get all link instances in the document
collectorOfRVTLinks = FilteredElementCollector(doc).OfClass(RevitLinkInstance)
# Create a filter for bounding box intersection
bb_filter = BoundingBoxIntersectsFilter(outline, 0.0, False)
# Apply the filter to the collector
links_in_bb = collectorOfRVTLinks.WherePasses(bb_filter).ToElements()
xxx.append(links_in_bb)
# Filter links by name
links_with_U = [link for link in collectorOfRVTLinks if '-U' in link.Name]
xxx.append(links_with_U)
for e in links_with_U:
r = Reference(e)
v = view
m = TagMode.TM_ADDBY_CATEGORY
o = TagOrientation.Horizontal
l = e.GetTransform().Origin
#tag = IndependentTag.Create(doc, v.Id, r, False, m, o, l)
# "End" the transaction
TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable
OUT =xxx
In the Revit API in RevitLinkInstance Members > Properties there is a BoundingBox for which can be intersected (I think)
