I am trying to develop my code to change the window sizes and wall types.
How ever it is a loop so that I have lists for window dimensions and wall types, at the end I will get exported gbXML files for all the options regarding the window modifications and the export to gbXML the code is working, but I have problem in changing the wall types and to access the wall type class
# Import necessary modules
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import os
doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
# Get the window elements from Dynamo
windows = UnwrapElement(IN[0])
# Get the lists of width and height values from Dynamo
width_list = IN[1]
height_list = IN[2]
# Get the list of walls from Dynamo
walls = UnwrapElement(IN[3])
# Get the list of wall type names from Dynamo
wall_type_names = IN[4]
path = IN[5]
# Function to modify window dimensions
def modify_window_dimensions(window, width, height):
width_parameter = window.LookupParameter('Width')
height_parameter = window.LookupParameter('Height')
if width_parameter and height_parameter:
# Start a transaction to modify the model
TransactionManager.Instance.EnsureInTransaction(doc)
# Set the width and height parameters of the window
width_parameter.Set(width/304.8)
height_parameter.Set(height/304.8)
# Commit the changes to the model
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
else:
raise ValueError("One or both of the specified parameters not found.")
# Function to change wall type
def change_wall_type(wall, wall_type_name):
# Get all wall types in the document
collector = FilteredElementCollector(doc)
wall_types = collector.OfClass(WallType).ToElements()
# Find the wall type with the specified name
wall_type = None
for wt in wall_types:
if wt.Name == wall_type_name:
wall_type = wt
break
if not wall_type:
raise ValueError("Wall type with the specified name not found.")
# Start a transaction to modify the model
TransactionManager.Instance.EnsureInTransaction(doc)
# Change the wall type of the wall
wall.WallType = wall_type
# Commit the changes to the model
TransactionManager.Instance.TransactionTaskDone()
doc.Regenerate()
# Main script
def main():
# Loop through each window and create variations
for width in width_list:
for height in height_list:
# Modify the dimensions of all windows for this variation
for window in windows:
modify_window_dimensions(window, width, height)
# Change the wall type for all walls for this variation
for i, wall in enumerate(walls):
change_wall_type(wall, wall_type_names[i])
# Export the variation to gbXML format
filename = "DO_Window_{}_{}.gbxml".format(width, height)
# Delete any existing Energy Analysis Detail Model
eadm = Autodesk.Revit.DB.Analysis.EnergyAnalysisDetailModel.GetMainEnergyAnalysisDetailModel(doc)
if eadm is not None:
doc.Delete(eadm.Id)
# Create a new Energy Analysis Detail Model
energyOptions = Autodesk.Revit.DB.Analysis.EnergyAnalysisDetailModelOptions()
energyOptions.EnergyModelType = Autodesk.Revit.DB.Analysis.EnergyModelType.BuildingElement
eadm = Autodesk.Revit.DB.Analysis.EnergyAnalysisDetailModel.Create(doc, energyOptions)
# Export the gbXML file
GBopt = GBXMLExportOptions()
GBopt.ExportEnergyModelType = ExportEnergyModelType.BuildingElement
doc.Export(path, filename, GBopt)
doc.Regenerate()
# Run the main script
main()
OUT = "Exported Successfully"
Can someone advise.