Error creating multiple floors in Python

Hello, I’m new to Python. I’m trying to create floors from a list of polygon lines, but I get this error on the curveArray adding to list:

Could I get some help? I’m using this code by now:

# The inputs to this node will be stored as a list in the IN variables.
ArrayCurves = IN[0]
floorType = UnwrapElement(IN[1])
level = UnwrapElement(IN[2])
structural = IN[3]

curveList = []
out = []

for curve in ArrayCurves:
    curveArray = CurveArray()
    for c in curve:
        curveArray.Append(c.ToRevitType())
    curveList.Add(curveArray)
    
# Place your code below this line
for c in curveList:
        TransactionManager.Instance.EnsureInTransaction(doc)
        floor = Floor.Create(doc, c, floorType.Id, level.Id)
        TransactionManager.Instance.TransactionTaskDone()
# Assign your output to the OUT variable.
OUT = floor

Thank you!

1 Like

hi

import sys
import clr

import System
from System.Collections.Generic import List

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

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

clr.AddReference("RevitAPI")
import Autodesk 
from Autodesk.Revit.DB import Curve,CurveLoop,Floor,Transaction,Level,Line,XYZ

doc = DocumentManager.Instance.CurrentDBDocument

ArrayCurves=IN[0]
floortype=UnwrapElement(IN[1])
level=UnwrapElement(IN[2])
structural=IN[3]

revc=Autodesk.Revit.DB.Curve
outerCurv=List[revc]([c.ToRevitType() for c in ArrayCurves[1]])
innerCurv=List[revc]([c.ToRevitType() for c in ArrayCurves[0]])
outL=CurveLoop.Create(outerCurv)
innL=CurveLoop.Create(innerCurv)
listCL=List[CurveLoop]([outL,innL])
lslope=Line.CreateBound(XYZ(0,0,0),XYZ(1,0,0))
t=Transaction(doc,"Create a Floor")
t.Start()
floor=Floor.Create(doc,listCL,floortype.Id,level.Id,structural,lslope,0)
t.Commit()
OUT = type(outerCurv),type(outL),type(listCL),floor

cordially
christian.stan

Thank you for your quick answer!
Unless I’m wrong, doing those changes I get only 1 floor as a result. Unfortunately I need to proccess the list from python to create as many floors as polygons are in input[0]

Am I missing anything?

1 Like

I thought you were trying to create the ground between these 2 curveloops as there is common matter between the 2 grounds it will generate warnings
what you are trying to do is achievable with the ootb node
if you make a for on the list this should create 2 floors
I’m writing this from phone so be careful
t.Start() floors=[] for c in listCL: f=Floor.Create(doc,c,floortype.Id,level.Id,structural,lslope,0) floors.append(f) t.Commit() OUT = floors

edit:

t.Start()
floors=[]
for c in listCL:
    f=Floor.Create(doc,List[CurveLoop]([c]),floortype.Id,level.Id,structural,lslope,0)
    floors.append(f)
t.Commit()
OUT = floors

You will get a warning like previously explained


if you validate you will have your 2 floors

Cordially
Christian.stan

2 Likes

Good morning, and thank you very much. You made my day with your help! Now it’s working as I was expecting to, and can continue.

Have a good day, and a happy new year!
Regards

1 Like

Hi @jliebana , please mark Christians solution if it work for you so it probably could help other in the future…and happy newyear to you as well :wink: :wink:

2 Likes