I try to writing a python scripts to create rebar as node move using WHILE LOOP but get this error NameError: global name 'Rebar' is not defined

I try to create rebar base on these following code

# Load the Python Standard and DesignScript Libraries
# Import Common Language Runtime
import clr
# 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

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

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

import System
from System.Collections.Generic import *

#get the document
doc = DocumentManager.Instance.CurrentDBDocument

#Function
def line(number1, number2, number3, number4, number5, number6, number7, number8, number9, 
number10):
    x1 = number1
    y1 = number2
    z1 = number3
    x2 = number4
    y2 = number5
    z2 = number6
    nx1 = number1 + number7
    count = 0
    while (count < 2):
	    pt1 = XYZ(x1, y1, z1)
	    pt2 = XYZ(x2, y2, z2)
	    pt3 = XYZ(nx1, y1, z1)
	    pt4 = XYZ(nx1, y2, z2)
	    line1 = DB.Line.CreateBound(pt1, pt2)
	    line2 = DB.Line.CreateBound(pt3, pt4)
	    rebar1 = Rebar.CreateFromCurves(doc, number8, number9, startHook, endHook, 
                number10, norm, line1, SHorient, EHorient, True, False)
	    rebar2 = Rebar.CreateFromCurves(doc, number8, number9, startHook, endHook, 
                number10, norm, line2, SHorient, EHorient, True, False)
	    y1 = y1 + number7
	    y2 = y2 + number7
	    count = count + 1
	
num1 = IN[0]
num2 = IN[1]
num3 = IN[2]
num4 = IN[3]
num5 = IN[4]
num6 = IN[5]
num7 = IN[6]
style = UnwrapElement(IN[8])
type = UnwrapElement(IN[9])
model = UnwrapElement(IN[10])


rebar = []

result = line(num1, num2, num3, num4, num5, num6, num7, style, type, model)

OUT = rebar1, rebar2

But its shown NameError: global name ‘Rebar’ is not defined. My target is to repeating create rebar as node move. I mean for example loop 1 start point (0,0,0) end point (0,0,10000) then loop 2 start point (0,300,0) end point (0,300,10000) which I already succeed in make looping node creation with these code but creating line and use that line to create rebar using Rebar.By.Curve is still unable to run. So how do I solve NameError: global name ‘Rebar’ is not defined and how can I reduce these

public static Rebar CreateFromCurves(
    Document doc,
    RebarStyle style,
    RebarBarType barType,
    RebarHookType startHook,
    RebarHookType endHook,
    Element host,
    XYZ norm,
    IList<Curve> curves,
    RebarHookOrientation startHookOrient,
    RebarHookOrientation endHookOrient,
    bool useExistingShapeIfPossible,
    bool createNewShape

Largely requirement to more simple like this

public static Rebar CreateFromCurves(
    Document doc,
    RebarStyle style,
    RebarBarType barType,
    Element host,
    IList<Curve> curves,

you should import Autodesk.Revit.DB.Structure

Import like this? I have tried but it still shown same error.

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

Add this line :

from Autodesk.Revit.DB.Structure import *

1 Like

Can i ask u something? according to RevitAPIDoc in order to create rebar these variable need to be fill up

public static Rebar CreateFromCurves(
    Document doc,
    RebarStyle style,
    RebarBarType barType,
    RebarHookType startHook,
    RebarHookType endHook,
    Element host,
    XYZ norm,
    IList<Curve> curves,
    RebarHookOrientation startHookOrient,
    RebarHookOrientation endHookOrient,
    bool useExistingShapeIfPossible,
    bool createNewShape

But is there another way to reduce those variable to more simple like

public static Rebar CreateFromCurves(
    Document doc,
    RebarStyle style,
    RebarBarType barType,
    Element host,
    IList<Curve> curves,

Because just now I import as u said and it fixed rebar but it started asking for StartHook which I actually dont really want these parameter.

What parameter you don’t understand ?

Rebar.CreateFromCurves(doc, style, bartype, startHook, endHook, host, norm, curves, startHookOrient, endHookOrient, True, False)

This is full code for rebar creation according RevitAPIdoc but I didnt really need all hook related parameter can I just type Null on that parameter name? and how do I know which one I should import so that my scripts is running fine?

Rebar.CreateFromCurves(doc, style, bartype, Null, Null, host, norm, curves, Null, Null, True, False)

no you can not put null, you can instead put a default value of the element, for example for the startHook you can do:
startHookDefault = FilteredElementCollector(doc).OfClass(typeof(RebarHookType)).FirstOrDefault()
and then put the startHookDefault in the function CreateFromCurves.

1 Like

Thank you so much @ridaabderrahmane I try to understand and learn how to properly write scripts while used RevitAPIdoc as reference but I not yet get a clear image of what system should I import to make each of my code work properly.