Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

List all walls currently in use

2 REPLIES 2
Reply
Message 1 of 3
Tom_Kunsman
146 Views, 2 Replies

List all walls currently in use

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.
2 REPLIES 2
Message 2 of 3
Yien_Chao
in reply to: Tom_Kunsman

hi

 

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

 

Message 3 of 3
jeremy_tammik
in reply to: Tom_Kunsman

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report