# Python floor.create() with revit api 2022

**URL:** <https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113>\
**Category:** Developers\
**Tags:** excel, python, dynamo\
**Created:** [November 8, 2021, 12:39am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113 "2021-11-08T00:39:01Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![DCRAING](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@DCRAING](https://forum.dynamobim.com/u/DCRAING)\
**Post date:** [November 8, 2021, 12:39am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/1 "2021-11-08T00:39:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![SeanP](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/seanp/32/42560_2.png) [@SeanP](https://forum.dynamobim.com/u/SeanP)\
**Post date:** [November 8, 2021, 1:46am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/2 "2021-11-08T01:46:31Z")

</div>

> [@DCRAING](#):
>
> slab\_new = Floor.Create(doc,loop, ‘Placa Maciza E=15cm’, level,True,0,0)

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

---

<div class="post-metadata">

**Author:** ![GavinNicholls](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/gavinnicholls/32/190442_2.png) [@GavinNicholls](https://forum.dynamobim.com/u/GavinNicholls)\
**Post date:** [November 8, 2021, 1:55am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/3 "2021-11-08T01:55:36Z")

</div>

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:

[![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/c/f/cf2f73b7de94ae4f0a894095a69d60f24a8677ed.jpeg "Floors/Ceilings with holes in Revit (2022) using Dynamo!") ](https://www.youtube.com/watch?v=E3Fx8QlebS0)

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:

```auto
# 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.

---

<div class="post-metadata">

**Author:** ![DCRAING](https://avatars.discourse-cdn.com/v4/letter/d/f04885/32.png) [@DCRAING](https://forum.dynamobim.com/u/DCRAING)\
**Post date:** [December 23, 2021, 2:51pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/4 "2021-12-23T14:51:20Z")

</div>

thanks a lot

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 11, 2023, 1:14pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/5 "2023-04-11T13:14:41Z")

</div>

Hi there! I am troubled with a similar issue in [pyRevit](https://discourse.pyrevitlabs.io/). Here’s my script for creating a simple new Revit triangular Floor starting from three vertices. I am currently using Revit 2023.

When I run my code, I get the error message “_ArgumentException : The input curve loops cannot compose a valid boundary, that means: the “curveLoops” collection is empty; or some curve loops intersect with each other; or each curve loop is not closed individually; or each curve loop is not planar; or each curve loop is not in a plane parallel to the horizontal(XY) plane; or input curves contain at least one helical curve. Parameter name: profile at Autodesk.Revit.DB.Floor.Create(Document document, IList`1 profile, ElementId floorTypeId, ElementId levelId)_”. Upon further inspection, I have checked the CurveLoop() and everything seems to be in order (it’s planar, closed, and counterclockwise).

I would greatly appreciate any help in resolving this issue.

```auto
#! python3

#----------------------------------------------------------------------------------------------
# IMPORT LIBRARIES
# System library
import sys

# Autodesk Revit API
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import XYZ, UV, Line, CurveLoop, Level, Floor, FloorType
from System.Collections.Generic import List

# Function to convert centimeters to feet
def centimeters_to_feet(centimeters):
    return centimeters * 0.0328084

doc = __revit__.ActiveUIDocument.Document

# Coordinates
a = 0.0
b = 10.0
c = 0.0

# Input elevation (in centimeters)
elevation_cm = c
elevation_ft = centimeters_to_feet(elevation_cm)

# Create a new level at the given elevation
new_level = None

# Start a new transaction to modify the Revit document creating a new level
transaction = Transaction(doc, 'Create New Level')
transaction.Start()

try:
    new_level = Level.Create(doc, elevation_ft)
    
    # Assign a new name to the level
    new_level_name = "elBS_BuildingStorey_{:.0f}cm".format(elevation_cm)
    new_level.Name = new_level_name

    transaction.Commit()
except Exception as e:
    # If an error occurs, roll back the transaction and show an error message
    transaction.RollBack()
    TaskDialog.Show('Error', 'Failed to create level. Error: {}'.format(e))

if new_level:
    TaskDialog.Show('Success', 'Level created at elevation: {} centimeters'.format(elevation_cm))

# Create new floor

point0 = XYZ(a, a, c)
point1 = XYZ(b, a, c)
point2 = XYZ(b, b, c)

line01 = Line.CreateBound(point0,point1).ToRevitType()
line12= Line.CreateBound(point1,point2).ToRevitType()
line23 = Line.CreateBound(point2,point0).ToRevitType()

curveloop = CurveLoop()

curveloop.Append(line01)
curveloop.Append(line12)
curveloop.Append(line23)

print("numberOfcurves: ",curveloop.NumberOfCurves())
print("IsOpen: ",curveloop.IsOpen())
print("HasPlane: ",curveloop.HasPlane())

# Collect floor types
floortypes = FilteredElementCollector(doc).OfClass(FloorType)
floortypes = [f for f in floortypes]
floortypes_id = [f.Id for f in floortypes]
floortype_id = floortypes_id[0]
print("floortype id:",floortype_id)

# Collect building storeys
el_BuildingStoreys = FilteredElementCollector(doc).OfClass(Level)
el_BuildingStoreys_id = []
for el in el_BuildingStoreys:
    el_BuildingStoreys_id.append(el.Id)
level_id = el_BuildingStoreys_id[0]
print("level id: ",level_id)

# Start transaction
t = Transaction(doc, "Create new floor")
t.Start()

# Create the floor
new_floor = Floor.Create(doc, List[CurveLoop](curveloop), floortype_id, new_level.Id)
t.Commit()

```

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 11, 2023, 1:24pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/6 "2023-04-11T13:24:01Z")

</div>

Not sure if it matters, but try removing the `.ToRevitType()` in the lines where you create the curves.

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 11, 2023, 1:39pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/7 "2023-04-11T13:39:45Z")

</div>

Sorry, with ToRevitType() the code returns a different error. Without it, it returns the error reported in my previous message.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 11, 2023, 2:02pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/8 "2023-04-11T14:02:42Z")

</div>

Hello, I feel like you miss him  
`import System`

edit: with additions and change to your code ended up working:

```auto
#! python3

#----------------------------------------------------------------------------------------------
# IMPORT LIBRARIES
# System library
import sys
import System
# Autodesk Revit API
import clr
clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.DB import Transaction
from Autodesk.Revit.UI import TaskDialog
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB import XYZ, UV, Line, CurveLoop, Level, Floor, FloorType
from System.Collections.Generic import List
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

# Function to convert centimeters to feet
def centimeters_to_feet(centimeters):
    return centimeters * 0.0328084

doc = DocumentManager.Instance.CurrentDBDocument

# Coordinates
a = 0.0
b = 10.0
c = 0.0

# Input elevation (in centimeters)
elevation_cm = c
elevation_ft = centimeters_to_feet(elevation_cm)

# Create a new level at the given elevation
new_level = None

# Start a new transaction to modify the Revit document creating a new level
transaction = Transaction(doc, 'Create New Level')
transaction.Start()

try:
    new_level = Level.Create(doc, elevation_ft)
    
    # Assign a new name to the level
    new_level_name = "elBS_BuildingStorey_{:.0f}cm".format(elevation_cm)
    new_level.Name = new_level_name

    transaction.Commit()
except Exception as e:
    # If an error occurs, roll back the transaction and show an error message
    transaction.RollBack()
    TaskDialog.Show('Error', 'Failed to create level. Error: {}'.format(e))

if new_level:
    TaskDialog.Show('Success', 'Level created at elevation: {} centimeters'.format(elevation_cm))

# Create new floor

point0 = XYZ(a, a, c)
point1 = XYZ(b, a, c)
point2 = XYZ(b, b, c)

line01 = Line.CreateBound(point0,point1)
line12= Line.CreateBound(point1,point2)
line23 = Line.CreateBound(point2,point0)

curv=CurveLoop()
curv.Append(line01)
curv.Append(line12)
curv.Append(line23)

print("numberOfcurves: ",curv.NumberOfCurves())
print("IsOpen: ",curv.IsOpen())
print("HasPlane: ",curv.HasPlane())
print("type: ",type(curv))

# Collect floor types
floortypes = FilteredElementCollector(doc).OfClass(FloorType)
floortypes = [f for f in floortypes]
floortypes_id = [f.Id for f in floortypes]
floortype_id = floortypes_id[0]
print("floortype id:",floortype_id)

# Collect building storeys
el_BuildingStoreys = FilteredElementCollector(doc).OfClass(Level)
el_BuildingStoreys_id = []
for el in el_BuildingStoreys:
    el_BuildingStoreys_id.append(el.Id)
level_id = el_BuildingStoreys_id[0]
print("level id: ",level_id)

# Start transaction
t = Transaction(doc, "Create new floor")
t.Start()

# Create the floor
new_floor = Floor.Create(doc,List[CurveLoop]([curv]), floortype_id, new_level.Id)
t.Commit()

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/5/25d9aa85cf1bfbf264456741710904ceaa719769.png)

cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 11, 2023, 3:58pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/10 "2023-04-11T15:58:56Z")

</div>

Thank you very much for the code! In my case, I noticed that it only runs with IronPython by removing the first `#! python3` line. However, I need to run it with the CPython interpreter in order to work with the numpy library in Revit-Python, so the issue is still open.

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 11, 2023, 4:09pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/11 "2023-04-11T16:09:12Z")

</div>

I got there with this engine, but as I’m a beginner it’s not what you’re probably talking about.

I thought the # canceled the rest of the command line

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/5/352103fec461b816ecbf21d1a63e3ff299cdf2ee.png)

Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 11, 2023, 4:14pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/12 "2023-04-11T16:14:43Z")

</div>

I am also new to the topic. I think that when working in [pyRevit](https://discourse.pyrevitlabs.io/) the ‘#! python3’ line serves for running the code with CPython and not with IronPython, but I’m not sure. I’ll wait for a reply from an expert. Thanks again a lot! 🙂

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 11, 2023, 9:18pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/13 "2023-04-11T21:18:04Z")

</div>

The engine selector in Dynamo being set to CPython3 is the equivalent of the [PyRevit](https://discourse.pyrevitlabs.io/) comment `#!python3` at the start of your code.

If the issue persists it may be best to take this to the [PyRevit](https://discourse.pyrevitlabs.io/) forum as the Python posted by @christian.stan certainly works in CPython3 (thereby giving access to numpy and the rest if you’ve configured your environment for such).

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [April 11, 2023, 9:26pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/14 "2023-04-11T21:26:59Z")

</div>

> [@christian.stan](#):
>
> I’m a beginner

Read this and laugh out loud…

@christian.stan you’re selling yourself very short here! You are well past that - I’d go so far as to say expert level, and by all means an awesome member of the community!

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 12, 2023, 3:51am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/15 "2023-04-12T03:51:54Z")

</div>

hello, thanks for the compliment always had the soul of a technician rather than commercial.  
I will decide on advanced beginner 😉  
Cordially  
christian.stan

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 12, 2023, 9:45am UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/16 "2023-04-12T09:45:00Z")

</div>

Got! Many thanks for your reply.

---

<div class="post-metadata">

**Author:** ![angelo.massafra2](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@angelo.massafra2](https://forum.dynamobim.com/u/angelo.massafra2)\
**Post date:** [April 12, 2023, 5:14pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/17 "2023-04-12T17:14:44Z")

</div>

Hi @christian.stan! Can I ask you what python version are you using?

---

<div class="post-metadata">

**Author:** ![christian.stan](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/christian.stan/32/166296_2.png) [@christian.stan](https://forum.dynamobim.com/u/christian.stan)\
**Post date:** [April 12, 2023, 5:24pm UTC](https://forum.dynamobim.com/t/python-floor-create-with-revit-api-2022/70113/18 "2023-04-12T17:24:46Z")

</div>

Hello, no worries, nothing secret Cpython3, I only have this default engine installed  
But I want to install IronPython3 soon (Mr. Poupin is testing it extensively and across)  
cordially  
christian.stan
