looping and rotating a curve around axis from an angles list

looping and rotating a curve around axis from an angles list

REDO10
Collaborator Collaborator
995 Views
4 Replies
Message 1 of 5

looping and rotating a curve around axis from an angles list

REDO10
Collaborator
Collaborator

Hi all,

I'm writing a python script inside dynamo and I want to rotate a curve from a defined angles list, and I'm  stuck on how to set the rotation function, please check below a part of my code :

# curve to rotate
curv = IN[0][0].ToRevitType()
# circle defining path rotation
out_path = IN[0][1].ToRevitType()
spacing = IN[1]/0.3048
# computing rotation angle
def rebar_rotation(circle, space):
    sweepAngle = (space * 360) / (circle.Radius *  2 * math.pi)
    return sweepAngle
angle = rebar_rotation(out_path, spacing)
# angle count around 360°
count = int(math.ceil(360/angle))

for i in range(0, count):   
    a= i*angle
    # I'm stuck to define the rotation function
    rebar_curve = curv.Rotate(Line.CreateBound(XYZ(0,0,0), XYZ(0,0,1)), a)
    

rotation.png

 

Thanks for your help in advance

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

Mohamed_Arshad
Advisor
Advisor

HI @REDO10 
You need to do circular pattern right ? 158 lines needed?


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 3 of 5

REDO10
Collaborator
Collaborator

@Mohamed_Arshad @Organon 

 

You need to do circular pattern right ? 158 lines needed?

yes that exactly what I need

 

Thanks 

0 Likes
Message 4 of 5

Mohamed_Arshad
Advisor
Advisor
Accepted solution

HI @REDO10 
You have to use some geometry concepts to solve this, you can use two geometry concepts

01. Rotation Transformation

02. Trignometry Functions
Kindly refer to the below code and a reference image for an Idea.

Rotation Transformation Sample Code:

            #region Rotate Curve To 158 Times

            Line line = verticalLine;

            XYZ centerPoint = arc.Center;

            double angleinDeg = 360d / 158d;

            using (Transaction createArray = new Transaction(revitDoc, "Create Array"))
            {
                createArray.Start();

                for (int i = 1; i <= 158; i++)
                {
                    double angleinRad = (angleinDeg * Math.PI) / 180;

                    Transform rotationTransform = Transform.CreateRotationAtPoint(XYZ.BasisZ, angleinRad, centerPoint);

                    Curve c = line.CreateTransformed(rotationTransform);

                    //Create Sketch Plane
                    XYZ normal = XYZ.BasisX.CrossProduct(line.Direction);
                    Plane p = Plane.CreateByNormalAndOrigin(normal, c.GetEndPoint(0));
                    SketchPlane skp = SketchPlane.Create(revitDoc, p);

                    revitDoc.Create.NewModelCurve(c, skp);

                    angleinDeg +=360d/158d;

                }

                createArray.Commit();
            }

            #endregion

Kindly understand the logic behind the code and try to apply it in your Program using Python. Above program will create a Model Line array in the circular form.

Reference Image (Rotation Transformation):

arshad99_0-1684515998488.png

 

Trigonometry Function Concept:
https://www.mathsisfun.com/geometry/unit-circle.html#:~:text=Try%C2%A0It%C2%A0Yourself,negative%20va... 

Hope this will helps 🙂

 


Mohamed Arshad K
Software Developer (CAD & BIM)

Message 5 of 5

REDO10
Collaborator
Collaborator
Accepted solution

@Mohamed_Arshad 

 

Thanks for your solution...I know there are plenty thought solutions!!

I never worked with C#, I'm using Python and I solved my issue by correcting the error I made in my initial script, where I used CreateRotation Method  (sometimes a stupid mistake costs you all day!!)

 

here my corrected code:

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

curv = IN[0][0].ToRevitType()
out_path = 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

# compute the angle rotation
def rebar_rotation(circle, space):
    sweepAngle = (space * 360) / (circle.Radius *  2 * math.pi)
    return sweepAngle

angle = rebar_rotation(out_path, spacing)

# rotated rebars count
count = int(math.ceil(360/angle))

rebars = []

for i in range(0, count):   
    a= i*angle
    rot = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
    rot_curve = curv.CreateTransformed(rot)
    rebars.append(rot_curve.ToProtoType())
    
OUT = rebars

 

REDO10_0-1684520140258.png

 

Thanks again.