Error creating new floors Python

Hi everyone, I’m new with Python and I’ve been trying to create Revit Floors. When I create a Floor from a Polygon the code works. However, when I have a list polygons and I want to create multiple floors at the same times my code doesn’t work.

It seems that the error is when I try to create the CurveArray(), so I’m doing something wrong in the for loops. Also I’m not sure how to create the multiple floor in a for loop. I leave the code that I’ve done. Hopefully someone could help me with this. Thanks!

import clr

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

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

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

clr.AddReference('System')
from System.Collections.Generic import List

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

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

doc=DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument

Curvas = IN[0]
Nivel = UnwrapElement(IN[1])
Tipo = UnwrapElement(IN[2])
Boolean = IN[3]

Perimetro=CurveArray()
revitfl = []


for i in Curvas:
	revitfl.append(i.ToRevitType())
	for j in revitfl:
		Perimetro.Append(j)


#TransactionManager.Instance.EnsureInTransaction(doc)

#for k in Perimetro:
#Suelo = doc.Create.NewFloor(Perimetro(k),Tipo,Nivel,Boolean)

#TransactionManager.Instance.TransactionTaskDone()

OUT = (revitfl,Perimetro)

Floors

When sharing Python code be sure to use the ‘pre formatted text’ button or wrap the code in triple ` characters. That will keep the formatting. I edited your post but some stuff may have been lost when you posted it without the formatting - sorry if that’s the case.

What is the error message you are getting?

From what I can see you started a loop to convert the shapes to curve loops and appended those to a list. Likely you want to start a loop and for each shape generate a new curve loop, then make the floor, and append the floor element to the output. Because your floor creation is outside the loop you’re not getting the results you want.

1 Like

Hi Jacob, Thanks for editing my script, I’ll do it next time.

As it wasn’t working I checked step by step and I modified the code a litlle bit. I have the problem creating the CurveArray, I get null result, any idea? I’m working with Revit 2021.1

It looks like you are assigning the output of the Perimetro.Append(elem) process to the variable peri.
This output is likely to be None or null and then you are appending this to the contorno list

Perimetro=CurveArray()
for i in Curvas:
    Perimetro.Append(i.ToRevitType())

That should be enough to create your CurveArray

Hi Viktor,

I tried that but I get the next error: