Skip to content

Instantly share code, notes, and snippets.

@teocomi
Created March 28, 2018 12:43
Show Gist options
  • Save teocomi/c6384b8d977326c8b35199017f35acb0 to your computer and use it in GitHub Desktop.
Save teocomi/c6384b8d977326c8b35199017f35acb0 to your computer and use it in GitHub Desktop.
Splits columns by level in Revit using Dynamo
#inspired by: https://danimosite.wordpress.com/2017/06/06/split-walls-and-columns-by-level/#comment-10
#as input provide only a list of the levels you want to cut with
import clr
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
clr.AddReference("RevitAPI")
from Autodesk.Revit.DB import *
import math, sys
# Import System Collections...
import System
from System.Collections.Generic import *
def tolist(obj1):
if hasattr(obj1, "__iter__"):
return obj1
else:
return [obj1]
levels = tolist(UnwrapElement(IN[0]))
cols = tolist(UnwrapElement(IN[1]))
TransactionManager.Instance.EnsureInTransaction(doc)
for c in cols:
if c.Category.Name == "Structural Columns":
pbase = c.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM)
base = doc.GetElement(pbase.AsElementId())
pbaseoff = c.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM)
ptop = c.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM)
top = doc.GetElement(ptop.AsElementId())
ptopoff = c.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM)
baseheight = base.Elevation + pbaseoff.AsDouble()
topheight = top.Elevation + ptopoff.AsDouble()
for l in levels:
lev = l.Elevation
if lev > baseheight and lev < topheight:
a = lev - baseheight
b = topheight - baseheight
s = a/b
# added tolerance otherwise it would fail for values very close to 0 or 1
if round(s,6) > 0 and round(s,6) < 1:
c.Split(s)
TransactionManager.Instance.TransactionTaskDone()
OUT = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment