Rebar.ByCurve in python

Hi Friends,

I am trying to make a python code to create rebars :

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

from System.Collections.Generic import IList, List

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

# dynamo curves as input
geo_lists = IN[0]
host = UnwrapElement(IN[1])
bar_type = UnwrapElement(IN[2])
vect_lists = IN[3]

rebars = []
TransactionManager.Instance.EnsureInTransaction(doc)
  
for curves, vectors, b, h in zip(geo, vect, bar_type, host):
    for c, v in zip(curves, vectors):

        rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, b, None, None, h, c.ToRevitType(), v.ToRevitType(), RebarHookOrientation.Left, RebarHookOrientation.Left, False, False)
        rebars.append(rebar)

TransactionManager.Instance.TransactionTaskDone()

But i still getting this error , and i don’t know why:

Appreciate your help in advance.

is there any ideas, Why am i getting this error?

Error message is pretty straight forward - you’re providing something other than what it expects.

Assuming you want to use this method: CreateFromCurves Method

It takes the following inputs:

  • Document (you provided doc)
  • RebarStyle (you provided RebarStyle.Standard)
  • RebarBarType (you provided b from the input bar_type)
  • RebarHookType (you provided None)
  • RebarHookType (you provided None)
  • Element (you provided h from the input host)
  • XYZ (you provided c.ToRevitType() from the curves list from the input geo_lists)
  • IList (you provided v.ToRevitType()from the vectors list from the vect variable which hasn’t been defined - perhaps you meant vect_lists?)
  • RebarHookOrientation (you provided RebarHookOrientation.Left)
  • RebarHookOrientation (you provided RebarHookOrientation.Left)
  • bool (you provided False)
  • bool (you provided False)

The XYZ and IList inputs are wrong and will need to be edited.

  • XYZ needs to be the vector, not the curve.
  • The curve needs to be a .net list of curves so you’ll have to convert things before you call them.

Feels like you’d benefit from using an out of the box node or package here rather than developing your own.

1 Like

I really appreciate your help,
You are right i just replaced the positions of vectors and rebars, and when i fixed that the code worked fine.

but after i faced another issue, I am trying to create rebars with L shape but the i got error that the polycurve must be a closed shape but i did not it to be closed shape.

Any suggestions?

Can’t comment on ‘why’ without seeing the code, but my guess is that you have a normal misoriented. Might be best to take the normal of the polycurve here rather than providing your own. Also best to move into ONE python node not many, or start using custom nodes as they’ll facilitate management.

@jacob.small Exactly what happened with me is this issue Press here for receiving “The input PolyCurve must be closed” error.

And when I tired to do a trail of making the PolyCurve of L Shape by points and pull it on the Normal plan it give me the same error as it is.

And when I tried to pull the curves itself on the plan it give me error “NurbsCurves not implemented”.

Any help will be appreciated.

Thanks in advance.

[I am sure that the python code it correct because it work perfect with the one item curve but the issue happened only with the PolyCurves ]

Did u try to Add that L in the curve itself…??

I’ve got minimal time today, but I can give it a shot if you can post the graph and a dataset to replicate the issue. Any newmodel with two elements to host rebar and the required rebar types and such setup should suffice.

@jacob.small
Kindly find my Script and Revit file to have a look clearly.
I create the same issue with one element for one rebar only.
Hope to hear your opinion soon.
Thanks in advance.

Polycurve to Rebar Test RVT.rvt (6.1 MB)
Polycurve to Rebar Test.dyn (86.7 KB)

@jacob.small Did you get any time to give this issue a shot ?
Thanks

@bharat.minocha , i did not get your idea yet

Maybe you can try to use CreateFreeForm method instead


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

from System.Collections.Generic import IList, List

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

clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)

doc = DocumentManager.Instance.CurrentDBDocument

# dynamo curves as input
geo_lists = IN[0]
host = UnwrapElement(IN[1])
bar_type = UnwrapElement(IN[2])
vect_lists = IN[3]


def CreateRebarFromCurve(geo, bar_type, host, vect):
    rebars = []
    TransactionManager.Instance.EnsureInTransaction(doc)    	
    for c, v, b, h in zip(geo, vect, bar_type, host):
        #curv = List[Curve]()
        #curv.Add(c.ToRevitType())
        #rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, b, None, None, h, v.ToRevitType(), curv, RebarHookOrientation.Left, RebarHookOrientation.Left, True, False)
        #rebars.append(rebar)
        #curv = List[Curve]()      
        arrayIList = List[IList[Autodesk.Revit.DB.Curve]]()
        arrayIList.Add(List[Autodesk.Revit.DB.Curve]([ds_cuve.ToRevitType() for ds_cuve in c.Curves()]))
        out_error = clr.Reference[RebarFreeFormValidationResult]()
        rebar = Rebar.CreateFreeForm(doc, b, h, arrayIList, out_error) #  
        print(out_error.Value)
        rebars.append(rebar)
        
        
    TransactionManager.Instance.TransactionTaskDone()
    return rebars

OUT = CreateRebarFromCurve(geo_lists, bar_type, host, vect_lists)
2 Likes

@c.poupin Thanks for your response, i really appreciate.

The code work perfect, but actually i am looking to :
1- Add vectors to these bars so i can use MaxSpacing function to them after that.
2- Make the code handle both cases if the bar is single curve or PolyCurve.

Do you think is there a chance to do that?

Thanks in advance.

Sounds like what you are after may already be managed via the rebar tools in some of the Revir Structural team’s Dynamo packages. Any reason you are doing this in Python?

Yes, actually i am after to do a python script free of using any dynamo packages, So i am doing my best to learn how to do that.

Hi @hanywillim ,

What i meant was to ask u that did u add the hook as well into the curve and i checked your script u did add the hook into it which is not meant to be added instead Dynamo curves that define the shape of the rebar curve and must belong to the plane defined by the normal and origin. Bends and hooks should not be included in the curve definition

It’ll resolve the issue and you’ll be able to do what u are after.

As here u can see this is method CreateFromCurves Method (revitapidocs.com) You have the option to set the RebarHookOrientation but if say you don’t wanna use this method and want to keep the hook as well in your curve then please proceed with this method CreateFromCurves Method (revitapidocs.com) This method allows you to keep the hooks as well into the shape definition.

Wish you the best.
Regards,
BM

2 Likes