Our Recent Posts

Tags

No tags yet.

Revit <--> Excel (Export and Import)


In this topic we will discuss how to export Revit schedule to excel and import it back with reflecting back the changes on element. Please watch the video below.

Exporting to excel:

For any created schedule in Revit you will be able to export it directly by a push of button with maintaining the schedule formatting. Also dynamo will create automatically new parameter for Element ID which will be used later for linking data with elements while importing,

Dynamo Script:

Dynamo Script Request Here

Python Code:

  • You need to install the following packages:

  • Data-shapes

  • Clockwork

  • MEPover

  • Archi-Lab

Collect Elements:

StartFragment# Copyright(c) 2018, Mohammad Nawar # http://BIM-hex.com import clr clr.AddReference('RevitAPI') clr.AddReference("RevitNodes") clr.AddReference('ProtoGeometry') clr.AddReference('RevitServices') import Revit clr.ImportExtensions(Revit.Elements) import Autodesk, RevitServices from Autodesk.Revit.DB import * from Autodesk.DesignScript.Geometry import * from RevitServices.Persistence import DocumentManager import System import sys pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib' sys.path.append(pyt_path) #The inputs to this node will be stored as a list in the IN variable. dataEnteringNode = IN doc = DocumentManager.Instance.CurrentDBDocument item = UnwrapElement(IN[0]) objtype = item.GetType().ToString() try: if objtype == "Autodesk.Revit.DB.ViewSchedule": element = Revit.Elements.Category.ById(item.Definition.CategoryId.IntegerValue) elif objtype == "Autodesk.Revit.DB.Family": element = Revit.Elements.Category.ById(item.FamilyCategoryId.IntegerValue) elif objtype == "Autodesk.Revit.DB.GraphicsStyle": element = Revit.Elements.Category.ById(item.GraphicsStyleCategory.Id.IntegerValue) else: element = Revit.Elements.Category.ById(item.Category.Id.IntegerValue) except: element = None

category = element result = []

errorReport = None filter = ElementCategoryFilter(System.Enum.ToObject(BuiltInCategory, category.Id)) result.append(FilteredElementCollector(doc).WherePasses(filter).WhereElementIsNotElementType().ToElements()) OUT = element, result

If statement:

StartFragment# Copyright(c) 2018, Mohammad Nawar # http://BIM-hex.com import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import * #The inputs to this node will be stored as a list in the IN variables. dataEnteringNode = IN x = IN[0] for i in x: if i == True: o = None break else: o = "ELEMENT-ID" #Assign your output to the OUT variable. OUT = oEndFragment

Write to excel:

StartFragment#Copyright 2016. All rights reserved. Bimorph Consultancy LTD, 5 St Johns Lane, London EC1M 4BH www.bimorph.co.uk #Written by Thomas Mahon @Thomas__Mahon info@bimorph.co.uk import clr clr.AddReference('ProtoGeometry') from Autodesk.DesignScript.Geometry import * # Import DocumentManager and TransactionManager clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager from System.Collections.Generic import * # # Import RevitAPI clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * doc = DocumentManager.Instance.CurrentDBDocument uiapp = DocumentManager.Instance.CurrentUIApplication app = uiapp.Application schedule = UnwrapElement(IN[0]) # "Start" the transaction TransactionManager.Instance.EnsureInTransaction(doc) #count the number of rows and columns in the schedule table = schedule.GetTableData().GetSectionData(SectionType.Body) nRows = table.NumberOfRows nColumns = table.NumberOfColumns #Collect all of data from the schedule dataListRow = [] for row in range(nRows): #Iterate through the rows. The second row is always a blank space dataListColumn = [] for column in range(nColumns): #Iterate through the columns dataListColumn.Add( TableView.GetCellText(schedule, SectionType.Body, row, column) ) dataListRow.Add( dataListColumn ); # "End" the transaction TransactionManager.Instance.TransactionTaskDone() OUT = dataListRowEndFragment

Import to Revit:

The exported schedule can be imported back to Revit and reflect all your changes on the elements, but keep in mind you can only reflect the changes for modifiable elements for e.g. you can't edit area or volume of the element but you can edit description or comment or any new parameter. The linking process depends on the element ID so make sure not to edit it. Also the created excel file should maintain the sheet name and if not, you need to edit the sheet name in dynamo script as been explained earlier in the video.

Dynamo Script:

Dynamo Script Request Here

Python Code:

  • You need to install the following packages:

  • Data-shapes

  • Clockwork

  • MEPover

  • Archi-Lab.net

Element ID:

StartFragmentimport clr clr.AddReference("RevitServices") import RevitServices from RevitServices.Persistence import DocumentManager from RevitServices.Transactions import TransactionManager doc = DocumentManager.Instance.CurrentDBDocument clr.AddReference("RevitAPI") import Autodesk from Autodesk.Revit.DB import * ids = IN[0] elements = [ElementId(x) for x in ids] OUT = [doc.GetElement(x) for x in elements]EndFragment

#Revit #Dynamo #Excel #Programming #Export #Import #API #Coding

©2018 by Nawar.

  • YouTube Social  Icon
  • LinkedIn Social Icon