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]
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.
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:
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.
@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]
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
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.