Floor By Nested Loops

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 and a brief summary here 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

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

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 (36.9 KB)

Cheers
Giovanni

3 Likes