# Floor By Nested Loops

**URL:** <https://forum.dynamobim.com/t/floor-by-nested-loops/13358>\
**Category:** Revit\
**Created:** [July 21, 2017, 10:58am UTC](https://forum.dynamobim.com/t/floor-by-nested-loops/13358 "2017-07-21T10:58:07Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![Giovanni\_Brogiolo](https://avatars.discourse-cdn.com/v4/letter/g/a9adbd/32.png) [@Giovanni\_Brogiolo](https://forum.dynamobim.com/u/Giovanni_Brogiolo)\
**Post date:** [February 17, 2018, 10:26am UTC](https://forum.dynamobim.com/t/floor-by-nested-loops/13358/13 "2018-02-17T10:26:26Z")

</div>

Hi Vincent,

1. Revit internally works with a fixed set of database units and Filled Regions require a list of points in Feet. One way to convert a Dynamo Point to a Revit Point is using ToRevitType(). See here for more info: [https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration](https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration) and a brief summary here [https://giobel.github.io/Dynamo-Python/](https://giobel.github.io/Dynamo-Python/)

2. The original script did not work with multiple inputs (i.e. it works with 1 room at a time). Also I think in your script you swap the inner and the outer curves.

3. Yes the error is related to the fact that you were feeding a list of inputs. Also the input lists must have a certain structure (rank) otherwise the for loop in the python node will not work.

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/9/09c483b6bbce982d27ba42a00d5d4dbb6f8f07f2.png)

This converts the dynamo points in revit points:

```
import clr

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

clr.AddReference("RevitNodes")
import Revit
# Import ToProtoType, ToRevitType geometry conversion extension methods
clr.ImportExtensions(Revit.GeometryConversion)

pts = IN[0]
elementlist = []

for i in range(0,len(pts)):
	p = []
	elementlist.append(p)
	for j in range(0,len(pts[i])):
		p.append(pts[i][j].ToRevitType())

newList = []

for el in elementlist:
	newList.append([el])

OUT = newList

```

And this creates the filled regions:

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application

regions = []
activeViewId = doc.ActiveView.Id;

outerCurves = UnwrapElement(IN[0])
innerCurves = UnwrapElement(IN[1])

filledRegionType = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

for pts,innerPts in zip(outerCurves,innerCurves):
	profileLoops = []
	outerProfileLoop = CurveLoop()
	profileLoops.Add(outerProfileLoop)
	#create filled region
	for i in range(0,len(pts)-1):
		outerProfileLoop.Append(Autodesk.Revit.DB.Line.CreateBound(XYZ(pts[i].X,pts[i].Y,pts[i].Z),XYZ(pts[i+1].X,pts[i+1].Y,pts[i+1].Z)))

	for j in range(0,len(innerPts)):
		innerProfileLoop = CurveLoop()
		profileLoops.Add(innerProfileLoop)
		for i in range(0,len(innerPts[j])-1):
			innerProfileLoop.Append(Autodesk.Revit.DB.Line.CreateBound(XYZ(innerPts[j][i].X,innerPts[j][i].Y,innerPts[j][i].Z),XYZ(innerPts[j][i+1].X,innerPts[j][i+1].Y,innerPts[j][i+1].Z)))
			
	region = FilledRegion.Create(doc,filledRegionType[0].Id,activeViewId,profileLoops)
	regions.Add(region)

TransactionManager.Instance.TransactionTaskDone()

#Assign your outputs to the OUT variable
OUT = regions

```

You could also directly extract the boundaries (both inner and outer) from an element instead of reconstructing them by points. This is more efficient than the previous method:

![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/2/829f0ef8d707454b2880b28667e9f64d6488b944.png)

```
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# Import DocumentManager and TransactionManager
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Import RevitAPI
clr.AddReference("RevitAPI")
import Autodesk
from Autodesk.Revit.DB import *

doc = DocumentManager.Instance.CurrentDBDocument
uiapp = DocumentManager.Instance.CurrentUIApplication
app = uiapp.Application
activeViewId = doc.ActiveView.Id;

area = UnwrapElement(IN[0])

filledRegionType = UnwrapElement(IN[1])

opt = SpatialElementBoundaryOptions()
opt.StoreFreeBoundaryFaces = False
opt.SpatialElementBoundaryLocation.Center

listRegions = []

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(0,len(area)):
	profileLoops = []
	segs = area[i].GetBoundarySegments(opt)
	for i in range(0,len(segs)):
		pL = CurveLoop()
		profileLoops.Add(pL)	
		for j in range(0,len(segs[i])):
			pL.Append(segs[i][j].GetCurve())
	listRegions.append(FilledRegion.Create(doc,filledRegionType[0].Id,activeViewId,profileLoops))

TransactionManager.Instance.TransactionTaskDone()

OUT = listRegions

```

[01 - Rooms outer hatch.dyn](https://forum.dynamobim.com/uploads/short-url/zhhYow3Vuj2rkSEqI7AeVzFFoGG.dyn) (36.9 KB)

Cheers  
Giovanni

---

_[View the full topic](https://forum.dynamobim.com/t/floor-by-nested-loops/13358)._
