Generate a single Subregion from a large number of curveLoops

I’m trying to generate siteSubregion through Python. In fact, I can already do this with the help of the code provided by PowellDesign.

https://forum.dynamobim.com/t/creating-a-subregion-then-using-it-to-shape-edit-a-floor/31108

In the code he provided, every time curveLoop generates a new Subregion. But what I expect is to make multiple sets of curveLoop generate a single Subragion.

The following is my attempt to modify the code provided by PowellDesign, and I swear it succeeded several times based on the same data! But in most cases it is paralyzed. I don’t know what went wrong.

@_yoyo

Try this:
SiteSubRegion.Create(doc, List[CurveLoop](curveloops), host.Id)

1 Like

I seem to have found a key factor that caused the “SiteSubRegion Method” to fail. This method does not seem to allow the specified “curveloop” to intersect. When I try to offset all Polygons inward by 0.01 meters and delete the Polygons that have self-intersections, everything works fine.

I don’t know if I solved the problem correctly, but everything looks good from the current results. Thank you for your reply!

1 Like

I’m posting the final code here, with a slight modification, for reference and in case somebody needs it someday.

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 = UnwrapElement(IN[0])
host = UnwrapElement(IN[1])

def Func_subregions(L2):
# Init variables
	curveLoops = []
	createdSubRegions = []

	TransactionManager.Instance.EnsureInTransaction(doc)

	# Get groups of curves (exploded polycurves!) and creates per group a SubRegion
	for i in L2:
		# 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)

	
	if SiteSubRegion.IsValidBoundary(curveLoops):
		# Create SubRegion out of the CurveLoop group and add its to 'createdSubregions'
		newSubRegion = SiteSubRegion.Create(doc, curveLoops, host.Id)
		createdSubRegions.append(newSubRegion.TopographySurface)
	
	TransactionManager.Instance.TransactionTaskDone()
	
	return createdSubRegions

# Output
if IN[2]:
	newList = []
	newList.append(Func_subregions(subregions))
	OUT = newList
else:
	OUT = "set IN[2] to True to run"
1 Like

the output does not work with multiple sublist of curves, it shows only the first, although it creates many subregions as the given curve list group
image