Description
Isolate objects according to their “building” key/value.
See also
Building, BuildingSelect, BuildingRemove scripts.
Author and license
Script by MLAV.LAND, licensed under the GNU GPL 3 License.
Code
import rhinoscriptsyntax as rs
def isolate_building():
# Get all objects in the document
all_objects = rs.AllObjects()
if not all_objects:
print("No objects in the document.")
return
unique_building_values = set()
# Collect unique 'building' values
for obj in all_objects:
building_value = rs.GetUserText(obj, "building")
if building_value:
unique_building_values.add(building_value)
if not unique_building_values:
print("No 'building' values found in the document.")
return
# Convert the set to a sorted list for the user to choose from
unique_building_values = sorted(list(unique_building_values))
# Let the user choose multiple values
search_values = rs.MultiListBox(unique_building_values, "Select one or more building(s):", "Select Buildings")
if not search_values:
print("No 'building' values selected.")
return
# Filter objects that match any of the selected 'building' values using list comprehension
matching_objects = [obj for obj in all_objects if rs.GetUserText(obj, "building") in search_values]
if not matching_objects:
print("No objects found with the selected 'building' values.")
return
# Isolate matching objects
rs.UnselectAllObjects()
rs.SelectObjects(matching_objects)
rs.Command("_Isolate", False)
# Run the function
isolate_building()