Hi All,
I want to rotate a vertical line (curve) along a circle based on a computed rotation angle (counted lines = 158) and I’m stuck how to define the rotation function according to this code: Rotate Method , 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)
Thanks in advance for your help.
Alien
May 18, 2023, 9:31pm
2
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
import math
# curve to rotate
curv = IN[0]
# circle defining path rotation
out_path = IN[1]
spacing = 10
# 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))
rebar_curve = []
for i in range(0, count):
a = i * angle
rebar_curve.append(curv.Rotate(Point.ByCoordinates(0, 0, 0), Vector.ZAxis(), a))
OUT = rebar_curve
Like that?
1 Like
REDO10
May 18, 2023, 10:04pm
3
@Alien
As I said above, I want to do the rotation using Revit API not using ProtoGeometry
Thanks.
Alien
May 18, 2023, 10:22pm
4
import sys
import clr
import math
# curve to rotate
curve = IN[0]
# circle defining path rotation
out_path = IN[1]
spacing = 10
plane = IN[2]
# 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))
rebar_curve = []
for i in range (count):
a = i * angle
rebar_curve.append(curve.Rotate(plane, a))
OUT = rebar_curve
You mean more like this?
2 Likes
REDO10
May 18, 2023, 10:54pm
5
@Alien
Thanks for your reply but as I said I want that everything will be done using Revit API according the method I linked above.
Thanks.
Full code and a sample showing the given input instead of 9 lines of a clearly much larger data set would help quite a bit…
I suggest you look into this method of the curve class: CreateTransformed Method
2 Likes
REDO10
May 19, 2023, 11:03am
7
Hi @jacob.small ,
1- I tried rotation using CreateTransformed Method
but I got a syntax error and I dont know it’s due to what?
Please check my references below:
1st script: Dynamo curves
import sys
import clr
import math
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]
spacing = IN[3]
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
if out_direct.Z > 0 :
out_V_crv = out_V_crv
else:
out_V_crv = out_V_crv.reverse()
vect = out_direct.Cross(Vector.ByCoordinates(0,1,0))
out_V_rebar = out_V_crv.Translate(vect, cover)
overlap_length = rebar_type.GetParameterValueByName("Diamètre de barre")*50/1000
out_V_rebar = out_V_rebar.ExtendEnd(overlap_length)
out_path = surf[1].GetIsoline(1, 0).Explode()[0]
out_path = out_path.Offset(-cover)
2nd script: rotation with Transformed Method
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*math.2*pi/360)
rebar_curve = curv.CreateTransformed(rot)
rebars.append(rebar_curve)
OUT = rebars
rot_curve.dyn (14.9 KB)
Shaft_rebar.rvt (3.4 MB)
Thanks.
Hello, I tried but it seems that Class Location is only done for cf support elements. example
wal=UnwrapElement(IN[0])
pos=wal.Location
vec_Z=XYZ(0,0,1)
Line_Revit=Line.CreateBound(XYZ(5/0.3048,0,0),XYZ(5/0.3048,0,5/0.3048))
container=[]
test=Line_Revit.IsReadOnly
TransactionManager.Instance.EnsureInTransaction(doc)
res_move=pos.Move(XYZ(1/0.3048,0,0))
deb=pos.Curve.GetEndPoint(0)
res_rotate=pos.Rotate(Line.CreateBound(deb,XYZ(deb.X,deb.Y,(deb.Z)+1)),2*30*math.pi/360)
TransactionManager.Instance.TransactionTaskDone()
OUT = pos,res_move,res_rotate
Do not forget to place this in a transaction
Cordially
christian.stan
1 Like
Hi @christian.stan
I’ve a line to rotate not a wall (they have the same class method?)
should I use Multiply Method after the first rotation by CreateRotation Method to generate all rotated curves?
Thanks.
1 Like
As the expression says: there are always plenty of roads that lead to Rome
Let’s say that for these parts (and many others) the dynamo nodes largely do the job (there is no point in reinventing the wheel) it already turns well
Pt_revit=IN[0].ToRevitType()
def li(pdeb,ray,elev,angle):
return Line.CreateBound(XYZ(pdeb.X+ray/0.3048*math.cos(angle*math.pi/180),pdeb.Y+ray/0.3048*math.sin(angle*math.pi/180),pdeb.Z),XYZ(pdeb.X+ray/0.3048*math.cos(angle*math.pi/180),pdeb.Y+ray/0.3048*math.sin(angle*math.pi/180),pdeb.Z+elev/0.3048)).ToProtoType()
curv=[li(Pt_revit,12,3,i) for i in range(0,285,15)]
OUT = curv
Have a good day
Cordially
christian.stan
1 Like
REDO10
May 19, 2023, 5:59pm
11
@christian.stan
Pfff!!!..somtimes a stupid mistake costs you all day!!
I discoverd my error :
and I corrected it by this line and the rotation by CreateTransformed Method
works perfectly!
rot = Transform.CreateRotation(XYZ.BasisZ, a*2*math.pi/360)
Asyou said : there are always plenty of roads that lead to Rome
Sorry, I dont understand what pdeb
, ray
means in your function?
Thanks.
1 Like
pdeb I should have called it p_center of the circle (but that’s my starting point of everything)
and the ray as the radius of the line scan circle
to err is human, it is better to make a syntax error (normally not at all, but hey… nobody’s perfect End of the day philosophy: I’m done) than understanding, it takes less time to process
happy evening
cordially
christian.stan
3 Likes
Alien
May 19, 2023, 6:30pm
13
OK, could be because I’ve been off work sick with Covid all week…
But I found that hilarious.
2 Likes
start off topic:
a pure malt whiskey of +15 years that overcomes everything
cheers
end Off topic: cordially
christian.stan
2 Likes
REDO10
May 19, 2023, 6:36pm
15
@Alien
it doesn’t matter!!!..I made you work your brain
Thanks.
1 Like
Hello, Slight off topic more knowledge sharing found
the LocationCurve class is really nice (translate rotate and scale)
here is an example
wal=UnwrapElement(IN[0])
pos=wal.Location
newpos=Line.CreateBound(XYZ(0,0,0),XYZ(6/0.3048,1/0.3048,0))
TransactionManager.Instance.EnsureInTransaction(doc)
pos.Curve=newpos
TransactionManager.Instance.TransactionTaskDone()
OUT = pos,newpos
Cordially
christian.stan