Creating a rebar coupler

Hi guys, I’m trying to create a coupler for 2 steel bars, but I get an error like in the image. Below is the code I made. Can you guys help me fix this? Thank you very much

import clr
import System
from System.Collections.Generic import *

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

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

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView

rebar = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
def CreateRebarCoupler(doc,rebars):
    coupler = None
    if rebars.Count > 1:
        defaulttypeId = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_Coupler))
        if defaulttypeId != ElementId.InvalidElementId:
            rebarData1 = RebarReinforcementData.Create(rebars[0].Id, 0)
            rebarData2 = RebarReinforcementData.Create(rebars[1].Id, 1)
            error = RebarCouplerError
            coupler = RebarCoupler.Create(doc,defaulttypeId,rebarData1,rebarData2,out error)
            if error != RebarCouplerError.ValidationSuccessfuly:
                TaskDialog.Show("Revit", "Create Coupler failed: " + error.ToString())
    return coupler
create = CreateRebarCoupler(doc,rebar)
TransactionManager.Instance.TransactionTaskDone()
OUT = create

Hello
try this

import clr
import System
from System.Collections.Generic import *

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

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

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
view = doc.ActiveView

rebar = UnwrapElement(IN[1])

TransactionManager.Instance.EnsureInTransaction(doc)
def CreateRebarCoupler(doc,rebars):
	coupler = None
	if rebars.Count > 1:
		defaulttypeId = doc.GetDefaultFamilyTypeId(ElementId(BuiltInCategory.OST_Coupler))
		if defaulttypeId != ElementId.InvalidElementId:
			rebarData1 = RebarReinforcementData.Create(rebars[0].Id, 0)
			rebarData2 = RebarReinforcementData.Create(rebars[1].Id, 1)
			error = clr.Reference[RebarCouplerError]()
			coupler = RebarCoupler.Create(doc, defaulttypeId, rebarData1, rebarData2, error)
			if error.Value != RebarCouplerError.ValidationSuccessfuly:
				TaskDialog.Show("Revit", "Create Coupler failed: " + error.ToString())
	return coupler
create = CreateRebarCoupler(doc,rebar)
TransactionManager.Instance.TransactionTaskDone()
OUT = create
1 Like

Thanks You…! :heart_eyes: :heart_eyes: