Rebar hook orientation issue

Rebar hook orientation issue

s.matsumura-atn
Explorer Explorer
775 Views
4 Replies
Message 1 of 5

Rebar hook orientation issue

s.matsumura-atn
Explorer
Explorer

Hello, this is my first post.
I am creating a command to make multiple rebars into a single one. The problem there is to keep the hook orientation and make it single.
I am developing in C#.

//select rebar hook orientation
RebarHookOrientation orientation1 = bendData.HookOrient0;
RebarHookOrientation orientation2 = bendData.HookOrient1;

//create new rebar
newRebar=Rebar.CreateFromCurvesAndShape(doc,shape,type,startHook,endHook,element1,Vec,curves2,orientation1,orientation2);

This is before and after the command is executed.

Why does the orientation of the hook change?

smatsumuraatn_0-1685516366370.png

Please advise me.

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

Mohamed_Arshad
Advisor
Advisor

Ohayo @s.matsumura-atn  San

What have you assigned for RebarHookOrientation variable? Can you provide the Detail Code For Rebar Which you have created. Or Else Kindly refer the below Link to create a Rebar.

 

https://www.revitapidocs.com/2021.1/e8365754-0811-8d4e-864a-55bf34af3a87.htm 

https://github.com/jeremytammik/RevitSdkSamples/tree/d08e310350b0f42bd2a87939c0d05cedaa77215c/SDK/Sa... 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 3 of 5

s.matsumura-atn
Explorer
Explorer

Thanks for the links and replies.
The hook orientation of the selected multiple reinforcing bars is entered in the reinforcing bar hook orientation.

The value right is retrieved.
Detailed code.

foreach (Rebar item in els)
                {
                    ElementId elid = item.GetHostId();

                    var rebarinstans = item.LookupParameter("a");

                    Element element1 = doc.GetElement(elid);

                    RebarShape shape = doc.GetElement(item.GetShapeId()) as RebarShape;

                    RebarStyle style1 = shape.RebarStyle;
int i1 = item.NumberOfBarPositions;
                    RebarHookType startHook = doc.GetElement(item.GetHookTypeId(0)) as RebarHookType;
                    RebarHookType endHook = doc.GetElement(item.GetHookTypeId(1)) as RebarHookType;

                    RebarBendData bendData = item.GetBendData();
                    RebarHookOrientation orientation1 = bendData.HookOrient0;
                    RebarHookOrientation orientation2 = bendData.HookOrient1;
                    double hookdouble = rebarinstans.AsDouble();
                    double barlength = hookdouble;

                    XYZ Vec = null;

                    List<Curve> curves2 = new List<Curve>();

                    Rebar newRebar = null;

                    string name = doc.GetElement(item.GetTypeId()).Name;

                    RebarBarType type = Cmd_CreateRebar.rebarBarType(name, doc);

                    if (category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming)
                    {
                        LocationCurve point = element1.Location as LocationCurve;
                        stpoint = point.Curve.GetEndPoint(0);
                        enpoint = point.Curve.GetEndPoint(1);
                        XYZ beamVec = enpoint - stpoint;
                        Curve curve = point.Curve;

                        Line li = Line.CreateBound(stpoint, enpoint);
                        curves2.Add(li);
                    }

                    for (int i = 0; i < i1; i++)
                    {
                        curves = item.GetTransformedCenterlineCurves(false, true, false, MultiplanarOption.IncludeOnlyPlanarCurves, i);
                       
                        foreach (Curve c in curves)
                        {

                            startpoint = c.GetEndPoint(0);
                            endpoint = c.GetEndPoint(1);
                            direction = (endpoint - startpoint).Normalize();

                            Vec = new XYZ(direction.Y, direction.X, 0.0);
                            if (category.Id.IntegerValue == (int)BuiltInCategory.OST_StructuralFraming)
                            {
                               
                                XYZ movepoint = (startpoint - stpoint);
                                
                                newRebar = Rebar.CreateFromCurvesAndShape(doc,shape,type,startHook,endHook,element1,Vec,curves2,orientation1,orientation2);
  
                                ElementTransformUtils.MoveElement(doc, newRebar.Id, movepoint);
                            }

 

Message 4 of 5

s.matsumura-atn
Explorer
Explorer
Accepted solution

Cause found.
The cause was not the orientation of the hook, but a problem with the rebar shape.
The first rebar shape I was using had the default position defined on the right, which I was using pointing the other way. So when I created the rebar, the orientation was to the right because it was facing the default value.
To solve the problem I added a new rebar shape, with the default value set to the left. When I executed the command, the correct orientation was achieved.

 

Both rebar shape3

smatsumuraatn_0-1685608408136.png

smatsumuraatn_1-1685608435936.png

This is the result of the correct command.

One side is rebar shape3 the other side is rebar shape4

smatsumuraatn_2-1685608456777.png

 

Message 5 of 5

Mohamed_Arshad
Advisor
Advisor

HI @s.matsumura-atn 
Great!! Thanks for Sharing the Right Answer


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes