Create Subregions from CAD file

Hello community,

I would like to know if it is possible to generate subregions in a topo based on a list of curves from a dwg?

I have started the definition but I cannot find a subregion node or I am not sure if there is a package that could help us with the exercise.

Revit file, dwg and dyn attached.

Drawing1.dwg (1.0 MB)

topo.rvt (1.9 MB)
Generate multiple subregions.dyn (11.8 KB)

Thanks jbo it would be great, we are not familiar with python yet

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

6 Likes

Amazing!!!, Can you attach the .Dyn so I can make sure I got the python node correctly please?

it works perfectly!!!
Thank you very muuuuuuch jbo

how to convert the output to Revit element?

Change the last lines to look like this:

	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.TopographySurface)
	
TransactionManager.Instance.TransactionTaskDone()

# Output
OUT = createdSubRegions

That should output the associated topo for each sub region

1 Like

I’ve been trying to use the above python script to convert a filled region to a sub-region, but I keep getting this error:

File “”, line 42, in
TypeError: iteration over non-sequence of type Curve.

Any thoughts?

You need to feed the first input in the python node with close polycurves.

Can you post a snapshot with the graph if you want a hand here.

What do I have to select here ? Topography?

Sure!

Can you send me the dynamo file? Something is not working here

Do someone know how to fix it?

You need to get the curves (as a list) from the poly curve like you did previously

Hi All,
really interesting this post, thanks for the great Python code.

my workflow is slightly different from the previous explained here and the python doesn’t work in my case.

I try to explain:
I use a linked toposurface created in Civil3D linked trough BIM360.
When inside revit you draw a subregion inside a linked toposuface, for some reason unknown to me, the subregion becomes like a normal subregion created from a native revit topography.
this new subregion can be used without problem with Dynamo to create other elements, like floor.

Because I have a lot of subregion to create before use them to create floors, I’d like to create this subregion with dynamo instead of manually.

I’ve tried to use this python to do this but i receive an error when I use it with linked toposurface, as show in the following images.

my knowledge of python is limited and I don’t know if it is possible fix the problem.

thanks for any help


Great post!
Can i create a single subregion with “holes” like a street with a median strip between lanes?
I tried editing the code but i dont know how to put 2 loops in one subregion.

1 Like

Hi, really interesting script! Thank you. I wanna ask if it is possible to modify the script and avoid the creation of “nested” subregion. I attach images of the expected result, which i have obtained manually. I want to do it in dynamo, because i will have hundreds of those subregions.

1 Like

Someone deleted their solution so this isn’t showing anymore, so I’m replying here so that the content is available for future reference.

2 Likes

Good afternoon Jacob,
I’m trying to create multiple subregions from Autocad drawings with multiple closed polylines. But I keep getting the “…more than one wire” error. What am i doing wrong?

thanks for your expertise and help,
Mi

ke

This error is pretty self explanatory - effectively your sublists of lines are branching or are part of multiple loops. That is to say they are shaped like a Y or all curves in a given sub-list don’t form a single closed loop but multiple.

First confirm there are no overlapping or doubling back lines by looking closely at the data labels in your geometry preview. If there are multiple indicies listed in what looks like it should be one line you may have to clean up your source data.

Next confirm there are no ‘donut’ shapes with holes in the middle. If this is the case the node “Group Curves” will help resolve the values, but there may be unavoidable errors when creating the subregions.

If these tips don’t straighten you out please start a new thread and provide a simplified version of your source data (the dwg with unnecessary info purged out and cleaned, and an rvt with the link and minimal associated elements in it).