Hello there!
I am trying to create a script that will take all the room parameters I need from Revit and export each value to an excel worksheet corresponding its name and populate specific cells the coordinates of which I will specify. I have made some progress with existing dynamo nodes and packages but I believe python would be a more efficient alternative. Unfortunately I am still new to coding so the python script isn’t working! Basically I am trying to write a python node the will iterate through a list of room names and the worksheet names in the excel files, match the room with its respective worksheet (the worksheet name will be Space Data Sheet {name of room}) and populate the parameter values corresponding to that room in the specific cells (the coordinates of which will stay the same through all the worksheets). I really hope that makes sense and would really appreciate any feedback or advice! I will be attaching what I have been working on so far!
Thank you in advance for your help! I have been learning a lot in this forum and I hope I can give back some day once I get enough experience!
import clr
clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import openpyxl
rooms_list = IN[0] # List of lists containing room names
excel_file_path = IN[1] # Path to the Excel file
Rooms_Paramenter_List = IN[2]
TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument)
workbook = openpyxl.load_workbook(excel_file_path)
for room_name in rooms_list:
if room_name in workbook.sheetnames and Rooms_Parameter_List:
worksheet = Space Data Sheet [room_name]
worksheet["J2"] = [1] # Use the index number as the parameter value
else:
print("No worksheet found for room: {room_name}")
workbook.save(excel_file_path)
TransactionManager.Instance.TransactionTaskDone()
OUT = excel_file_path