TypeError: expected Curve, got Curve - Dynamo + Python

Hi Everybody.
I´m trying to create a wall with python node.
I’m using " Wall.Create(doc,curve,level.Id,bool)

I’m not sure about this error.

Python Script got crash:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.
Traceback (most recent call last):
File “”, line 41, in
TypeError: expected Curve, got Curve

This is my Script:

import clr
#Revit API permite usar elementos de Revit (geometría, líneas, etc)
clr.AddReference(‘RevitAPI’)
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
#Get Revit Elements
clr.AddReference(‘RevitNodes’)
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)

#Access Revit Document
clr.AddReference(‘RevitServices’)
import RevitServices
from RevitServices.Persistence import DocumentManager
#Transaction permite ejecutar acciones en Revit
from RevitServices.Transactions import TransactionManager
doc = DocumentManager.Instance.CurrentDBDocument

#Preparing input from dynamo to revit
Curve = (IN[0])
level = UnwrapElement(IN[1])
bool = IN[2]

refLines=

if isinstance(Curve, list):
refLines.extend(IN[0])
else:
refLines.append(IN[0])

#Do some action in a Transaction
TransactionManager.Instance.EnsureInTransaction(doc)

wall =
for i in refLines:

  wall.append(Wall.Create(doc,refLines[-1+1],level.Id,bool))

TransactionManager.Instance.TransactionTaskDone()

OUT = wall

1 Like

This is a namespace conflict. Both DesignScript (Dynamo) and the Revit API have a Curve class. Judging by what it shown in this blog post, you should be able to take your curve from Dynamo and convert it to a proper Revit object like this:

curves = IN[0]
level = UnwrapElement(IN[1])
is_structural = IN[2]

walls = []
for curve_ds in curves:
    curve_rvt = gc.ProtoToRevitCurve.ToRevitType(curve_ds)
    walls.append(Wall.Create(doc, curve_rvt, level.Id, is_structural))

Edit: See @Kulkul’s post for proper syntax.

The error is telling you that you are providing a Dynamo Curve, but it expects an Autodesk.Revit.DB.Curve. It is also good practice to avoid naming variables the same as Python built-in functions or other objects. For example:

bool (Python object)
Curve (Revit and DS class)

2 Likes

Thank you!!
But, when I use your script,I get a new error :S
Help me pls!!!
AttributeError: ‘Curve’ object has no attribute 'ProtoToRevitCurve’

Hi @niojuri22

You need to convert to RevitType() as @cgartland pointed and make sure you import clr.ImportExtensions(Revit.GeometryConversion) in order to use RevitType():

import clr
clr.AddReference('RevitNodes')

import Revit
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
clr.ImportExtensions(Revit.GeometryConversion)
from Revit import GeometryConversion as gc

import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

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

doc = DocumentManager.Instance.CurrentDBDocument

curves = IN[0]
level = UnwrapElement(IN[1])
is_structural = IN[2]
TransactionManager.Instance.EnsureInTransaction(doc)
walls = []
for curve_ds in curves:
    curve_rvt = gc.ProtoToRevitCurve.ToRevitType(curve_ds)
    walls.append(Wall.Create(doc, curve_rvt, level.Id, is_structural))
TransactionManager.Instance.TransactionTaskDone()

OUT = walls
3 Likes

Thank You Very Much!!!
It works!