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

8 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?

1 Like

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

2 Likes

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.

5 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).