Question about the project method in Revit API

Hello,
I tried to convert my old Dynamo scripts to Python scripts and failed at using the Project Method to get the closest points by projecting a list of points to a curve. Please see my error message and script below and let me know where I did wrong. Thanks a lot!

error message:
Warning: TypeError : No method matches given arguments for Project: (<class ‘Autodesk.Revit.DB.XYZ’>) [’ File “”, line 29, in \n’]

script

import clr
clr.AddReference('ProtoGeometry')
clr.AddReference('RevitAPI')
clr.AddReference('RevitServices')
clr.AddReference("RevitNodes")

import System,Revit
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)
from Autodesk.DesignScript.Geometry import *
from Autodesk.Revit.DB import *
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

doc = DocumentManager.Instance.CurrentDBDocument

# collect inputs into center point list
if not isinstance(IN[0], list):
    centerPtLst= UnwrapElement([IN[0]])
else:
    centerPtLst = UnwrapElement(IN[0])
# collect input curve
curve = UnwrapElement(IN[1])

# closest point
closestPtLst = []

for pt in centerPtLst:
    closestPt = curve.Project(pt.ToXyz())
    closestPtLst.append(closestPt)
	
# Assign your output to the OUT variable.
OUT = closestPtLst

You have to convert the curve also to API type.

1 Like

Deniz,
Thank you so much! Here is the corrected script in case anyone else interested.

for pt in centerPtLst:
    # curve convert to Dyanmo Type
    curveGeoobj = curve.ToRevitType()
    closestPt = curveGeoobj.Project(pt.ToXyz()).XYZPoint
    closestPtLst.append(closestPt)