Create Subregions from CAD file

The script doesn’t check if the boundaries are on the surface of the topography. Just a quick and dirty try to solve the problem. The first input are the curves (not the polycurve, create out of the polycurves again curves) and the second one is the topography you want the subregions on.

import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Architecture import *
import System.Collections.Generic
from System.Collections.Generic import List

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

clr.AddReference('RevitServices')
from RevitServices.Transactions import TransactionManager
from RevitServices.Persistence import DocumentManager

doc = DocumentManager.Instance.CurrentDBDocument

# Get input variables
subregions = IN[0]
host = UnwrapElement(IN[1])

# Init variables
curveLoops = []
createdSubRegions = []
error = []

TransactionManager.Instance.EnsureInTransaction(doc)

# Get groups of curves (exploded polycurves!) and creates per group a SubRegion
for i in subregions:
	# Init CurveLoop for every curve group
	x = CurveLoop()
	
	# Iterate the seperate curves -> convert type to Revit Type -> add to CurveLoop
	for j in i:
		x.Append(j.ToRevitType())
	curveLoops.append(x)
	
	# Add layer to list
	y = [x]
	yI = List[CurveLoop](y)
	
	if SiteSubRegion.IsValidBoundary(yI):
		# Create SubRegion out of the CurveLoop group and add its to 'createdSubregions'
		newSubRegion = SiteSubRegion.Create(doc, yI, host.Id)
		createdSubRegions.append(newSubRegion)
	
TransactionManager.Instance.TransactionTaskDone()

# Output
OUT = createdSubRegions

8 Likes