# Create Floor with Python Script (First script)

**URL:** <https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890>\
**Category:** Developers\
**Created:** [February 24, 2017, 3:16pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890 "2017-02-24T15:16:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 24, 2017, 3:16pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/1 "2017-02-24T15:16:29Z")

</div>

Hello Everyone,

I have started my journey in learning to use the API in Dynamo. This is my first script and I cant figure out why it doesn’t work. I was attempting it in baby steps. I wanted to create a floor with this profile I created (all very simple while I figure it out). I receive this error. I was hoping someone could look at it and tell me what I am doing incorrectly. Thanks a lot for your help. (I choose to do something that already have an existing node for 2 reasons: 1. The knowledge knowing, If it doesn’t work it is because of me and 2. I would like to try the ToDSType (true))

\*My script in progress I know the issue is within the NewFloor command  
import clr  
clr.AddReference(‘ProtoGeometry’)  
from Autodesk.DesignScript.Geometry import \*

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

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

fl = IN[0]
type = IN[1]
lvl = IN[2]
struc = IN[3]
dynofl = []
dynofl2 = []

dynofl = fl.ToRevitType()

x = doc.Create.NewFloor(dynofl[0],type[0],lvl[0],struc[0])
y = x.ToDSType(True)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = [y]  

```

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/8/48e29ec4da0755c6eb73c867a8ba35e7ed793cbe.PNG)

---

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 26, 2017, 1:09am UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/2 "2017-02-26T01:09:13Z")

</div>

Hello Everyone,

I am still trying to work through this python script. This is what I have so far:

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

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

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

fl = IN[0]
type = UnwrapElement(IN[1])
lvl = UnwrapElement(IN[2])
struc = IN[3]
dynofl = CurveArray()

for c in dynofl:
	dynofl.append(c.ToRevitType())

x = doc.Create.NewFloor(dynofl,type,lvl,struc)
y = x.ToDSType(True)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = [dynofl]

```

The Error that I am getting now is “Could not compute the plane with the input curve”. I think the way I am inputting the geometry into the CurveArray() is the problem but I cant figure out how to change it. Would someone mind throwing in any tips or resources I can read to solve the issue. As I try other methods like feeding lines into the array I still get the same results. Any help would be great thanks.

---

<div class="post-metadata">

**Author:** ![T\_Pover](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/t_pover/32/19147_2.png) [@T\_Pover](https://forum.dynamobim.com/u/T_Pover)\
**Post date:** [February 26, 2017, 7:57am UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/3 "2017-02-26T07:57:26Z")

</div>

Not behind a computer at the moment, so I can’t check, but you are iterating over dynofl and then appending to that same dynofl. That should probably be something like this:

```
for c in fl:
	dynofl.append(c.ToRevitType())

```

Also because you are creating a new object that is not yet Revit owned, you should set the ToDSType to false: ToDSType(False)  
for more info: [https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#elements](https://github.com/DynamoDS/Dynamo/wiki/Python-0.6.3-to-0.7.x-Migration#elements)

---

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 26, 2017, 9:45pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/4 "2017-02-26T21:45:54Z")

</div>

Hello T Pover,

Thanks for your help. I corrected that mistake you pointed out. The error I get now is “‘CurveArray’ object has no attribute append.”

The .ToRevitType changes the rectangle to “Autodesk.Revit.DB.NurbSpline”. I thought those could not go into a CurveArray. Therefore I created 4 lines to place into the Array and was given the same error. I looked on the SDK about the CurveArray it has not provided any insight on where I am going wrong with this script. Thanks again for your help.

---

<div class="post-metadata">

**Author:** ![T\_Pover](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/t_pover/32/19147_2.png) [@T\_Pover](https://forum.dynamobim.com/u/T_Pover)\
**Post date:** [February 27, 2017, 8:33am UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/5 "2017-02-27T08:33:40Z")

</div>

Ah, I see the problem. It’s with a capital ‘A’. So it should be dynofl.Append()

---

<div class="post-metadata">

**Author:** ![Thomas\_Mahon](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/thomas_mahon/32/64209_2.png) [@Thomas\_Mahon](https://forum.dynamobim.com/u/Thomas_Mahon)\
**Post date:** [February 27, 2017, 8:35am UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/6 "2017-02-27T08:35:28Z")

</div>

Have you tried `doc.Regenerate()` before creation?

---

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 27, 2017, 12:10pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/7 "2017-02-27T12:10:10Z")

</div>

Hello,

Thanks again for your help everyone!

@Thomas_Mahon Thanks, I have not tried it yet. I have placed it in my script. I will place my code below

@T_Pover Thanks I corrected that error. I am not getting the message" Could not construct a proper face with the input curves to create a floor correctly". I tried using the same outline in the node that comes with Revit and it works fine. Therefore I tied using 4 lines. I first got the error that my lines did not create a continuous loop. After adjusting the order of the lines and got the same error " Could not construct a proper face with the input curves to create a floor correctly": Here is my code so far (I change it to accept the 4 lines instead of the 1 rectangle):

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

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

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

fl = UnwrapElement(IN[0])
type = UnwrapElement(IN[1])
lvl = UnwrapElement(IN[2])
struc = IN[3]
dynofl = CurveArray()
revitfl =[]

for z in fl:
	revitfl.append(z.ToRevitType())

doc.Regenerate()

for c in revitfl:
	dynofl.Append(c)

doc.Regenerate()
x = doc.Create.NewFloor(dynofl,type,lvl,struc)
y = x.ToDSType(True)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = [dynofl,revitfl]
```

---

<div class="post-metadata">

**Author:** ![T\_Pover](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/t_pover/32/19147_2.png) [@T\_Pover](https://forum.dynamobim.com/u/T_Pover)\
**Post date:** [February 27, 2017, 3:24pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/8 "2017-02-27T15:24:17Z")

</div>

What exactly is going into input IN[0] now? A Revit element?

---

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 27, 2017, 3:56pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/9 "2017-02-27T15:56:21Z")

</div>

I have 4 lines that create a rectangle.

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/5/d5be5d8bf021399466fd4c4c21449b8cd3686d77.PNG)

---

<div class="post-metadata">

**Author:** ![T\_Pover](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/t_pover/32/19147_2.png) [@T\_Pover](https://forum.dynamobim.com/u/T_Pover)\
**Post date:** [February 27, 2017, 4:20pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/10 "2017-02-27T16:20:26Z")

</div>

I guess it somehow doesn’t recognize the loop as closed. If I try this it does work (with a slightly altered code):

 ![](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/c/ec6cfa6a5bf5dba6e9363aab9557d7895c280fd6.jpg)

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

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

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

# Import ToDSType(bool) extension method
clr.AddReference("RevitNodes")
import Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

#The inputs to this node will be stored as a list in the IN variables.

doc = DocumentManager.Instance.CurrentDBDocument

TransactionManager.Instance.EnsureInTransaction(doc)

fl = IN[0]
type = UnwrapElement(IN[1])
lvl = UnwrapElement(IN[2])
struc = IN[3]
dynofl = CurveArray()

for c in fl:
	dynofl.Append(c.ToRevitType())

doc.Regenerate()
x = doc.Create.NewFloor(dynofl,type,lvl,struc)
y = x.ToDSType(False)

TransactionManager.Instance.TransactionTaskDone()

#Assign your output to the OUT variable.
OUT = y
```

---

<div class="post-metadata">

**Author:** ![donnellgrantham](https://avatars.discourse-cdn.com/v4/letter/d/f9ae1b/32.png) [@donnellgrantham](https://forum.dynamobim.com/u/donnellgrantham)\
**Post date:** [February 27, 2017, 4:48pm UTC](https://forum.dynamobim.com/t/create-floor-with-python-script-first-script/9890/11 "2017-02-27T16:48:23Z")

</div>

Thank you very much for your help!

I tried what you have done using R15 with 1.2 Dynamo and I receive the same error. I then switch to R17 and it worked fine. I find that weird. I will investigate so I can understand.

I really appreciate you helping though this.
