List all walls currently in use

Tom_Kunsman
Collaborator
Collaborator

List all walls currently in use

Tom_Kunsman
Collaborator
Collaborator

Since I am still trying to Learn python, I used Chat GPT to ry and generate code to lsit all walls currently in use in the model.

 

This is what Chat GPT came up with:

 

# Import necessary modules
from Autodesk.Revit.DB import FilteredElementCollector, BuiltInCategory
from pyrevit import revit, DB

# Initialize the Revit document
doc = revit.doc

# Define the BuiltInCategory for Walls
walls_category = BuiltInCategory.OST_Walls

# Create a FilteredElementCollector to get all wall elements in the document
wall_collector = FilteredElementCollector(doc).OfCategory(walls_category)

# Create a list to store the in-use walls
in_use_walls = []

# Iterate through each wall and check if it's in use
for wall in wall_collector:
    if not wall.IsDemolished(doc.ActiveView) and not wall.IsHidden(doc.ActiveView):
        in_use_walls.append(wall)

# Print the names of in-use walls
for wall in in_use_walls:
    print(wall.Name)

# You can also access other properties of the walls if needed
# For example, wall parameters like height, thickness, etc.

 

when I use the PythonShell to test it, it gives me an error saying there is no module 'pyrevit'. I do have pyRevit installed. 

 

Hope someone can help with this. Thanks!

If you find my post interesting, feel free to give a Kudo.
If it solves your problem, please click Accept to enhance the Forum.
0 Likes
Reply
185 Views
2 Replies
Replies (2)

Yien_Chao
Advisor
Advisor

hi

 

if you want all instance of any categories, just simply add ".WhereElementIsnotElementType()" at the end of you wall_collector.

 

0 Likes

jeremy_tammik
Autodesk
Autodesk

I'm afraid ChatGPT s not savvy enough about the Revit API for it to be much use. I have heard reports of people using it to improve their Python programming skills inside a Revit add-in, but those people had prior basic Revit add-in implementation experience. To get started with the Revit API and programming Revit add-ins, I suggest that you follow the old-school approach of reading the getting started material and working through the My First Plugin video tutorial:

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open