How to fix this error? AttributeError: 'Line' object has no attribute 'ToRevitType'

This is my code

import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
# Import Revit Services
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
import Autodesk.Revit.DB as DB
from Autodesk.Revit.DB import Curve as RCurve
from Autodesk.Revit.DB.Structure import *

clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *

clr.AddReference("RevitNodes")
import Revit
from Revit.Elements import *
clr.ImportExtensions(Revit.Elements)
clr.ImportExtensions(Revit.GeometryConversion)

import System
import System.Array
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(x1, y1, z1, x2, y2, z2, increment, host, type):
    nx1 = x1 + increment
    count = 0
    outLine = []
    #While loop to auto create point that move with incremental
    while (count < 2):
	    pt1 = XYZ(x1, y1, z1)
	    pt2 = XYZ(x2, y2, z2)
	    pt3 = XYZ(nx1, y1, z1)
	    pt4 = XYZ(nx1, y2, z2)
	    #Create line using pt1, pt2, pt3 and pt4
	    line1 = DB.Line.CreateBound(pt1, pt2)
	    outLine.append(line1)
	    line2 = DB.Line.CreateBound(pt3, pt4)
	    outLine.append(line2)
	    #Processing
	    curve1 = outLine[0].ToRevitType()
	    curve2 = outLine[1].ToRevitType()
	    #Create array A
	    Aarray = [System.Array[RCurve]([curve1])]
	    Aarray2 = System.Array[System.Array[RCurve]](Aarray)
	    #Create array B
	    Barray = [System.Array[RCurve]([curve2])]
	    Barray2 = System.Array[System.Array[RCurve]](Barray)
	    #Start Transaction
	    TransactionManager.Instance.EnsureInTransaction(doc)
	    #Rebar List
	    rebar_list = []
	    #Rebar A
	    rebar1 = Rebar.CreateFreeForm(doc, type, host,Aarray2,clr.StrongBox[RebarFreeFormValidationResult]())
	    rebar_list.append(rebar1)
	    #Rebar B
	    rebar2 = Rebar.CreateFreeForm(doc, type, host,Barray2,clr.StrongBox[RebarFreeFormValidationResult]())
	    rebar_list.append(rebar2)
	    #End
	    TransactionManager.Instance.TransactionTaskDone()
	    #Incremental Function
	    y1 = y1 + increment
	    y2 = y2 + increment
	    count = count + 1
    return rebar_list

NumX1 = IN[0]
NumY1 = IN[1]
NumZ1 = IN[2]
NumX2 = IN[3]
NumY2 = IN[4]
NumZ2 = IN[5]
increment = IN[6]
Rebartype = UnwrapElement(IN[7])
Element = UnwrapElement(IN[8])


result = line(NumX1, NumY1, NumZ1, NumX2, NumY2, NumZ2, increment, Element, Rebartype)

OUT = rebar_list, rebar1, rebar2

I presume that problem is this line of code but I hv no idea how to fix it

        #Create line using pt1, pt2, pt3 and pt4
	    line1 = DB.Line.CreateBound(pt1, pt2)
	    outLine.append(line1)
	    line2 = DB.Line.CreateBound(pt3, pt4)
	    outLine.append(line2)
	    #Processing
	    curve1 = outLine[0].ToRevitType()
	    curve2 = outLine[1].ToRevitType()

I make line base on point then I try to convert those line into revit type so that I can use it with rebar free form. Any idea how I can fix this?

line1 and line2 are already Revit lines (Revit.DB.Line)

2 Likes