Skip to content

Instantly share code, notes, and snippets.

@dobriai
Last active May 3, 2017 22:17
Show Gist options
  • Save dobriai/be39bd4e31111e3f0b41b3ddfa65ec20 to your computer and use it in GitHub Desktop.
Save dobriai/be39bd4e31111e3f0b41b3ddfa65ec20 to your computer and use it in GitHub Desktop.
Dynamo Revit Python Snippets
# Universal header
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.AddReference('RevitAPI')
import Autodesk
from Autodesk.Revit.DB import *
# Import DocumentManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
# uiapp = DocumentManager.Instance.CurrentUIApplication
# app = uiapp.Application
# ============================================================
# Get all Walls and put out the WallType for each one
collector = FilteredElementCollector(doc)
elems = collector.WherePasses(ElementClassFilter(Wall)).ToElements()
OUT = []
for elem in elems:
wt = elem.WallType
OUT.append(wt)
# ============================================================
# Get Walls from IN[0] and set all their types to the WallType IN[1]
TransactionManager.Instance.EnsureInTransaction(doc)
OUT = []
for elem in IN[0]:
# wt = elem.InternalElement.WallType
# OUT.append(wt)
elem.InternalElement.WallType = IN[1].InternalElement
OUT.append(elem) # For debugging or chaining
TransactionManager.Instance.TransactionTaskDone()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment