Set rebar circular distribution path and fix wrong hook orientation

Set rebar circular distribution path and fix wrong hook orientation

REDO10
Collaborator Collaborator
979 Views
4 Replies
Message 1 of 5

Set rebar circular distribution path and fix wrong hook orientation

REDO10
Collaborator
Collaborator

Hi everyone,

@Organon  @jeremytammik 

 

I'm trying to write a python code which allows me to get vertial reinforcement of a circular shaft, but I'm stuck how to set a circular distibution path (I'm getting instead a straight distribution as shown bellow)

 

REDO10_0-1683828672942.png

 

  1. Is there a way to set a  circular path from one created rebar using only RebarShapeDrivenAccessor or should I  get all my rebars using ILIST curves and put them in a container?
  2.  As you can see in the image above, I'm getting once again the same issue here  related to a wrong Hook orientation espicially when I choose Hook at 90°!!!???... (so far I have tried more options to solve this issue without finding a solution and I do not understand it's due to what??)

Please check below my graph and my code for more details

 

fer_fut.png

1st code: rebar curve

 

 

 

 

 

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

clr.AddReference('RevitNodes')
import Revit
from Revit.Elements import Element

element = IN[0]
cover = IN[1]
rebar_type = IN[2]

geo = element.Geometry()
surfaces = geo[0].Explode()

s_area = []

for i in surfaces:
    s_area.append(i.Area)
    
S_area = ["%0.2f"%(round(i,2)) for i in s_area]
    
surf = []
surf_area = set()

for s, a in zip(surfaces, S_area):
    if a not in surf_area and S_area.count(a) == 2:
        surf.append(s)
        surf_area.add(a)
        

out_V_crv = surf[1].GetIsoline(0, 1).Explode()[0]
out_direct = out_V_crv.Direction

iner_V_crv = surf[0].GetIsoline(0, 1).Explode()[0]
iner_direct = iner_V_crv.Direction

if out_direct.Z > 0 :
    out_V_crv = out_V_crv
else:
    out_V_crv = out_V_crv.reverse()
    
if iner_direct.Z > 0 :
    iner_V_crv = iner_V_crv
else:
    iner_V_crv = iner_V_crv.reverse()    
    
vect = out_direct.Cross(Vector.ByCoordinates(0,1,0))  
out_V_rebar = out_V_crv.Translate(vect, cover)

iner_V_rebar = iner_V_crv.Translate(vect.Reverse(), cover)

overlap_length = rebar_type.GetParameterValueByName("Diamètre de barre")*50/1000
out_V_rebar = out_V_rebar.ExtendEnd(overlap_length)
iner_V_rebar = iner_V_rebar.ExtendEnd(overlap_length)
OUT = out_V_rebar, iner_V_rebar

 

 

 

 

 

2nd code: rebar creation

 

 

 

 

 

import sys
import clr
import math
import System
from System.Collections.Generic import IList, List 

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

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

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

doc = DocumentManager.Instance.CurrentDBDocument

out_V_rebar = IN[0][0].ToRevitType()
iner_V_rebar = IN[0][1].ToRevitType()
cover = IN[1]/0.3048
rebar_type = UnwrapElement(IN[2])
Hook_type = UnwrapElement(IN[3])
host= UnwrapElement(IN[4])
spacing = IN[5]/0.3048
crv = List[Curve]()
crv.Add(out_V_rebar)

Pt_radius = out_V_rebar.GetEndPoint(0)
line = Line.CreateBound(XYZ(0,0,Pt_radius.Z), Pt_radius)
radius = line.Length
vect = Pt_radius - (XYZ(0,0,Pt_radius.Z))
rot = Transform.CreateRotation(XYZ.BasisZ, math.pi/2)
cRot = line.CreateTransformed(rot)
startRot = cRot.GetEndPoint(0)
endtRot = cRot.GetEndPoint(1)
Norm = endtRot - startRot
path = Arc.Create(XYZ(0,0,Pt_radius.Z), radius, 0, 2*math.pi, XYZ(1, 0, 0), XYZ(0, 1, 0))

TransactionManager.Instance.EnsureInTransaction(doc)
out_V_rebar = Rebar.CreateFromCurves(doc, RebarStyle.Standard, rebar_type, Hook_type, Hook_type, host, Norm, crv, RebarHookOrientation.Left, RebarHookOrientation.Right, True, True)
out_V_rebar.GetShapeDrivenAccessor().SetLayoutAsFixedNumber(math.ceil(path.Length/spacing), path.Length, True, True, True)
TransactionManager.Instance.TransactionTaskDone()

OUT = out_V_rebar

 

 

 

 

 

Thanks.

 

0 Likes
Accepted solutions (1)
980 Views
4 Replies
Replies (4)
Message 2 of 5

REDO10
Collaborator
Collaborator

Waiting for an answer to my 1st question, I crated All my rebar curves in dynamo then transformed them to Revit curves , but I still get wrong hook direction for the angle 90°!!?

 

Shaft_rebar.png

 

What's weird, I asked the question in dynamobim forum and somebody has run my script with my attached file without any changes and it works for him!!??

 

REDO10_0-1683923487918.png

 

I can't figure out  what’s the cause of this issue and how to fix it!!?

 

Please check my references below for more details

 

Thanks.

 

Message 3 of 5

REDO10
Collaborator
Collaborator

@architect.bim 

Have you any idea to solve this issue?

 

Thanks

Message 4 of 5

REDO10
Collaborator
Collaborator

@jeremy_tammik @moturi.magati.george @jayhar 

 

Please, have you any idea how to solve this issue?

 

Thanks.

Message 5 of 5

REDO10
Collaborator
Collaborator
Accepted solution

Hi All, 

My issue is solved here 

In fact, it is due to the citation in the image below related to the CreateFromCurves Method (In my case "shape 23" which have opposed hooks  was selected instead "shape00")

 

Capture d’écran 2023-05-30 215233.jpg

 

Thanks.

0 Likes