I create while loop for creating Rebar.FreeForm but was shown with AttributeError: 'module' object has no attribute 'StrongBoxStructure' error

These are my 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('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
from System.Collections.Generic import IList

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure 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, number9, number10):
    XR1 = clr.StrongBoxStructure.RebarFreeFormValidationResult
	    XR2 = clr.StrongBoxStructure.RebarFreeFormValidationResult
    x1 = number1
    y1 = number2
    z1 = number3
    x2 = number4
    y2 = number5
    z2 = number6
    nx1 = number1 + number7
    count = 0
    #While loop to auto create point that move 300 mm in y direction everytime loop goes.
    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)
	    line2 = DB.Line.CreateBound(pt3, pt4)
	    #Start Transaction
	    TransactionManager.Instance.EnsureInTransaction(doc)
	    rebar_list = []
	    #Create Rebar from Line that use pt1 and pt2 as start and finish point
	    rebar1 = Structure.Rebar.CreateFreeForm.Overloads[Document, RebarBarType, Element, IList[IList[Curve]], RebarFreeFormValidationResult](doc, number9, number10, line1, XR1)
	    #Create Rebar from Line that use pt3 and pt4 as start and finish point
	    rebar2 = Structure.Rebar.CreateFreeForm.Overloads[Document, RebarBarType, Element, IList[IList[Curve]], RebarFreeFormValidationResult](doc, number9, number10, line1, XR2)
	    rebar_list.append(rebar1.ToDSType(False))
	    rebar_list.append(rebar2.ToDSType(False))
	    #End Transaction
	    TransactionManager.Instance.TransactionTaskDone()
	    #y-axis coordination move
	    y1 = y1 + number7
	    y2 = y2 + number7
	    #increase loop count
	    count = count + 1

 #Scripts Inputs
 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])

 #Call Function
 result = line(num1, num2, num3, num4, num5, num6, num7, type, model)

 OUT = rebar_list

When I run these code its shown AttributeError: ‘module’ object has no attribute ‘StrongBoxStructure’ what system did I forget to import? or Is there a mistake among those line of code of my?

RebarFreeFormValidationResult is listed under Autodesk.Revit.DB.Structure:

so where XR1 and XR2 are defined in your code, you do not need to use “clr.StrongBoxStructure”

I already imported Autodesk.Revit.DB.Structure but this error still remain. I should change my XR1 and XR2 to = RebarFreeFormValidationResult? XR1 is on this code line

rebar1 = Structure.Rebar.CreateFreeForm.Overloads[Document, RebarBarType, Element, IList[IList[Curve]], RebarFreeFormValidationResult](doc, number9, number10, line1, XR1)
def line(number1, number2, number3, number4, number5, number6, number7, number9, number10):
	XR1 = RebarFreeFormValidationResult
	XR2 = RebarFreeFormValidationResult

ie. under your function definition statement, if you want to track the result in these two variables.

1 Like

@habdirad After I try to fixed it shown something that I confused is that after I run these code it shown these error

TypeError: No match found for the method signature CreateFreeForm[Document, RebarBarType, Element, IList1, RebarFreeFormValidationResult]. Expected [Document, RebarBarType, Element, IList1, RebarFreeFormValidationResult&], [Document, RebarBarType, Element, IList`1, RebarFreeFormValidationResult&]

How do I get RebarFreeFormValidationResult& While my input is RebarFreeFormValidationResult?

I am not familiar with this form of picking overloads (my guess is it does not work because of all the wrappers around .Net and Revit API interfaces), I am not familiar with the StrongBox interface either. However, the following solution worked for me; ie. without passing RebarFreeFormValidationResult as an input, you will receive it as the second output of the rebar creator method (first output is the Rebar element).

import clr

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


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


clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
doc = DocumentManager.Instance.CurrentDBDocument

clr.AddReference('RevitAPI')
clr.AddReference('RevitAPIUI')

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

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument
host = UnwrapElement(IN[0])

curve = IN[1][0].ToRevitType()

rebarbartype = UnwrapElement(IN[2])[0]

carray = [System.Array[RCurve]([curve])]

carray2 = System.Array[System.Array[RCurve]](carray)

TransactionManager.Instance.EnsureInTransaction(doc)

rebar1, XR1 = Rebar.CreateFreeForm(doc, rebarbartype, host,carray2)

TransactionManager.Instance.TransactionTaskDone()

OUT = rebar1, XR1
1 Like

Thank you so much let me try to understand ur coding procedure first and try to make some change so that it compatible with my current code. Is IN[1][0] is meaning same as curve1 = IN[1] and curve2 = IN[2]?

:grin:

found it! use this one:

rebar1 = Rebar.CreateFreeForm(doc, rebarbartype, host,carray2,clr.StrongBox[RebarFreeFormValidationResult]())

and if you want to store it in a variable, pass it your XR1 and XR2:

XR1 = clr.StrongBox[RebarFreeFormValidationResult]()
rebar1 = Rebar.CreateFreeForm(doc, rebarbartype, host,carray2,XR1)

ur carray2 is curve right? maybe I have to take a few hour to make understand hahahaha I quite new to python in dynamo

@habdirad what is [0] used for? I never add [0] behind so I didnt hv a clue for what it does and how it affect code as a whole.