Floor.Create(Document, IList(CurveLoop), ElementId, ElementId) give two floors

Hi everyone !

Can’t understand why but my code returns two floors where I expect it to only create one.

For a bit more context, rooms and Curves lists do have the same length. listCurveLoop is a unique closed loop for each index i
I tried to place only an f = Floor.Create(doc, listCurveLoop, UnwrapElement(floorType).Id, rooms[i].Level.Id) inside the Transaction handler

I get only one floor in my log output but two in my Revit model

Here is the code :

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

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

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

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

log = []
ERROR = []

Curves = UnwrapElement(IN[0])

floorType = IN[1]
rooms = UnwrapElement(IN[2])

TransactionManager.Instance.EnsureInTransaction(doc)

for i in range(len(Curves)) :
    listCurveLoop = []
    for c in Curves[i] :
        newLoop = CurveLoop()
        for m in c :
            try :
                ri = m.ToRevitType()
                newLoop.Append(ri)
            except :
                pass
        listCurveLoop.append(newLoop)
    if listCurveLoop :
        try :
            
            
            log.append([rooms[i],[Floor.Create(doc, listCurveLoop, UnwrapElement(floorType).Id, rooms[i].Level.Id)]])
            
           
        except :
            ERREUR.append([rooms[i],sys.exc_info()[1]])
    else :
        ERREUR.append([rooms[i],"Invalid Curve"])
        
TransactionManager.Instance.TransactionTaskDone()

OUT = log, ERROR

I suspect I did something wrong with for loops but I can’t put my finger onto what and tried asking GTP for help which wasn’t successful

Thank you for the time taken to tackle this issue with me

Hi @Yorick try look into @GavinCrump crumple package there is a node for that written in python so you can checkout how it can be done

1 Like

Here is an example of a loop working with the output of Room.FinishBoundary for multiple rooms. Hope it helps. One key to this workflow is to ensure each object is represented in a list of list of list of curves (effectively a list of curveloops per object). Even if an element only has one list of curves, it has to sit at a predictable depth for iteration.

# Made by Gavin Crump
# Free for use
# BIM Guru, www.bimguru.com.au

# Boilerplate text
import clr

clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

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

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

# Current doc/app/ui
doc = DocumentManager.Instance.CurrentDBDocument

# Define list/unwrap list functions
def uwlist(input):
	result = input if isinstance(input, list) else [input]
	return UnwrapElement(result)

# Preparing input from dynamo to revit
loopsList = IN[0]
typ = UnwrapElement(IN[1])
lvl = UnwrapElement(IN[2])

floors = []

TransactionManager.Instance.EnsureInTransaction(doc)

for loopList in loopsList:
	curveloops = []
	for loop in loopList:
		crvs = []
		for crv in loop:
			crvs.append(crv.ToRevitType())
		curveloop = CurveLoop.Create(crvs)
		curveloops.append(curveloop)
	flr = Floor.Create(doc, curveloops, typ.Id, lvl.Id)
	floors.append(flr)

TransactionManager.Instance.TransactionTaskDone()

# Preparing output to Dynamo
OUT = floors
4 Likes

Hello guys !
Sooooo …
Problem solved, reopened my graph, haven’t made a change, re-ran it and it now works without the double floors issue ¯\ _ (ツ) _/¯
Tested on several projects with different type of geometry porblems (nurbs, small boundaries, …) works like a charm

Thanks for the time you put in trying to solve this !!