Python floor.create() with revit api 2022

Hi All,

i’m trying to create a floor within my python script using:

Floor.Create(doc,CurveArray, ‘Placa Maciza E=15cm’, level,True,0,0)

Can someone tell me the new process for use correct, new commmands FLOOR.CREATE with new revit api 2022.

this the code:

#importar revit api
import clr
clr.AddReference(‘ProtoGeometry’)
from Autodesk.DesignScript.Geometry import *

from math import *

import clr
clr.AddReference(“RevitNodes”)
import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference(“RevitServices”)

import RevitServices
from RevitServices.Persistence import *
from RevitServices.Transactions import *

doc = DocumentManager.Instance.CurrentDBDocument

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

#importar excel
import os

localapp = os.getenv(r’LOCALAPPDATA’)

sys.path.append(os.path.join(localapp, r’python-3.8.3-embed-amd64\Lib\site-packages’))

#DECLARACIÓN VARIABLES IMPORTAR EXCEL

import openpyxl
from openpyxl import *

book=load_workbook(r’D:\PINITOS.xlsx’)
sheet=book[“REVIT”]

#sheet=book.active
#a1=sheet[“B1”].value
#a2=sheet[“B2”].value

def conversion(x):
uid = UnitTypeId.Feet
uid2 = UnitTypeId.Meters
return UnitUtils.Convert(x,uid2,uid)

row_count = sheet.max_row
#column_count = sheet.max_column

x_1=
for col in range(row_count):
x_1.append(sheet.cell(col+1, 2).value)

y_1=
for col in range(row_count):
y_1.append(sheet.cell(col+1, 3).value)

level = UnwrapElement(IN[0]).Id

#dibujo de placas

#niveles = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Levels).WhereElementIsNotElementType().ToElements()
slabs = FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Floors).WhereElementIsElementType().ToElements()

for slab in slabs:
name = slab.get_Parameter(BuiltInParameter.SYMBOL_NAME_PARAM).AsString()
if name == ‘Placa Maciza E=15cm’:
floorType = slab

muros =

TransactionManager.Instance.EnsureInTransaction(doc)

for col in range(row_count):
try:
a=x_1[col]
a=conversion(a)
b=y_1[col]
b=conversion(b)
c=x_1[col+1]
c=conversion(c)
d=y_1[col+1]
d=conversion(d)
linea = Line.CreateBound(XYZ(a,b,0),XYZ(c,d,0))
curveArray = CurveLoop.Create(linea)
loop=[curveArray]
except IndexError:
c=x_1[col]
c=conversion(c)
d=y_1[col]
d=conversion(d)
e=x_1[0]
e=conversion(e)
f=y_1[0]
f=conversion(f)
linea = Line.CreateBound(XYZ(c,d,0),XYZ(e,f,0))
curveArray.Append(linea)
curveArray = CurveLoop.Create(linea)
loop=[curveArray]
muro = Wall.Create(doc, linea, level, True)
muros.append(muro)

slab_new = Floor.Create(doc,loop, ‘Placa Maciza E=15cm’, level,True,0,0)
offset = slab_new.get_Parameter(BuiltInParameter.FLOOR_HEIGHTABOVELEVEL_PARAM)
offset.Set(0)

TransactionManager.Instance.TransactionTaskDone()

OUT=doc

Thanks, DAVID CAMILO.

You need to pass a floor type element, not just use the string name of the floor type.

1 Like

Looks like Sean found the issue, but I’ve got a video as well which runs through in Python how to use this method correctly if it helps too:

I ended up using it to make a node in my package (Crumple) as well called ‘FloorsByCurveloops’.

I’ve pasted its code below for reference:

# 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)

def listpad(lst,count):
	padded = []
	length = len(lst)
	for i in range(0,count):
		if i < length:
			padded.append(lst[i])
		else:
			padded.append(lst[-1])
	return padded

# Preparing input from dynamo to revit
roomset = IN[0]
maxlst = len(roomset)

types  = listpad(uwlist(IN[1]),maxlst)
levels = listpad(uwlist(IN[2]),maxlst)

floors = []

TransactionManager.Instance.EnsureInTransaction(doc)

for rm,f,l in zip(roomset,types,levels):
	curveloops = []
	for crv_setd in rm:
		crv_setr = []
		for crv_d in crv_setd:
			crv_setr.append(crv_d.ToRevitType())
		curveloop = CurveLoop.Create(crv_setr)
		curveloops.append(curveloop)
	flr = Floor.Create(doc, curveloops, f.Id, l.Id)
	floors.append(flr)

TransactionManager.Instance.TransactionTaskDone()

# Preparing output to Dynamo
OUT = floors

As the naming implies, I typically use it to deal with room finish boundaries, and the node requires curves to be in closed sets, so it’s a list of list of lists in structure. I use the ‘listpad’ function primarily to simulate a longest lacing technique for the remaining inputs as I found ziplongest from itertools wasn’t working typically.

1 Like