Hi,
because you are using an old version of Dynamo
I update the code in my previous post
I attach the dyn for test
offset curve keep length.dyn (10.8 KB)
Hi,
because you are using an old version of Dynamo
I update the code in my previous post
I attach the dyn for test
offset curve keep length.dyn (10.8 KB)
Can you please made modification to the script to get rotations of created arcs with an overlap of 1.00 m ?
Thanks.
Good evening,
that should solve your problem
script:
23 octobre forum anglais rep2_v2 .dyn (105.5 KB)
Cordially
christian.stan
In addition to @christian.stan 's answer
import sys
import clr
import math
import random
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
def isClockwise(arc):
pStart = arc.StartPoint
pCenter = arc.CenterPoint
pEnd = arc.EndPoint
vecta = Vector.ByTwoPoints(pCenter, pStart)
vectb = Vector.ByTwoPoints(pCenter, pEnd)
cp = vecta.Cross(vectb)
return cp.Z < 0
def arcAngle_by_Length(current_arc, need_length):
# arclength = (2 * math.pi * current_arc.Radius) * (current_arc.SweepAngle / 360)
sweepAngle = (need_length * 360) / (2 * math.pi * current_arc.Radius)
return sweepAngle
def offset_Curve_keepLength(input_arc, factor):
global normal_vect
# input arc attribute
lengthArc = input_arc.Length
init_startAngle = input_arc.StartAngle
init_sweepAngle = input_arc.SweepAngle
if isClockwise(input_arc):
input_arc = input_arc.Reverse()
# offset arc
temparc = input_arc.Offset(factor)
try:
radius = temparc.Radius
except:
temparc = temparc.Explode()[0]
radius = temparc.Radius
new_sweepAngle = arcAngle_by_Length(temparc, lengthArc)
offsetAngle = (new_sweepAngle - init_sweepAngle) / 2
newarc = Arc.ByCenterPointRadiusAngle(
input_arc.CenterPoint,
radius,
temparc.StartAngle - offsetAngle,
temparc.StartAngle + new_sweepAngle - offsetAngle,
normal_vect
)
return newarc
input_arc = IN[0]
lstOffset = [0] + IN[1]
len_Bar = IN[2]
overlap_LenghtBar = 1 # in meter
normal_vect = Vector.ByCoordinates(0,0,1)
out = []
for d in lstOffset:
temp = []
offset_arc = offset_Curve_keepLength(input_arc, d)
start_Angle = offset_arc.StartAngle
end_Angle = offset_arc.StartAngle + offset_arc.SweepAngle
#
perimeter = offset_arc.Radius * 2 * math.pi
quotient, remainder = divmod(perimeter, len_Bar)
temp.append(offset_arc)
val = 0
for j in range(int(quotient) - 1):
# compute angle to get the same length overlap
marginAngle = (overlap_LenghtBar * 360) / (2 * math.pi * offset_arc.Radius)
# perform swapping beetween 0 and 1
val ^= 1
# rotate the new arc
offset_arc = offset_arc.Rotate(offset_arc.CenterPoint, Vector.ByCoordinates(0,0,1), offset_arc.SweepAngle - marginAngle)
# add a small vertical offset
offset_arc = offset_arc.Translate(0,0, val * 0.1)
# update end angle
end_Angle = offset_arc.StartAngle + offset_arc.SweepAngle
temp.append(offset_arc)
val ^= 1
# compute the arc remainder
restArc = Arc.ByCenterPointRadiusAngle(offset_arc.CenterPoint, offset_arc.Radius, end_Angle - marginAngle, start_Angle + marginAngle, normal_vect)
# add a small vertical offset
restArc = restArc.Translate(0,0, val * -0.1)
temp.append(restArc)
out.append(temp)
OUT = out
offset curve keep length_v4.dyn (21.6 KB)
Hi @c.poupin
I get error when executing your script
the error is saying:
Could not find method or static constructor DSCore.Math.RandomList()
A zero value cannot be projected to Int32
Thanks.
What version of Dynamo are you using?
Try Adding DSCore. in front of all functions.
How to do that please? I’m a new dynamo user and I dont know how to add this function
Thanks.
Important to go and learn the fundamentals from the dynamo primer. Once this workflow has been solved I encourage you to do that.
Try putting the phrase provided (DSCore.) in front of the highlighted words in the code block, so for example, DSCore.List instead of just List. The same applies to all Color and Math references I think.
@REDO10
besides this problem (DSCore), I realize that my solution is not perfect for small curves, use the @christian.stan 's solution
Finally, fixed
import sys
import clr
import math
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
def isClockwise(arc):
pStart = arc.StartPoint
pCenter = arc.CenterPoint
pEnd = arc.EndPoint
vecta = Vector.ByTwoPoints(pCenter, pStart)
vectb = Vector.ByTwoPoints(pCenter, pEnd)
cp = vecta.Cross(vectb)
return cp.Z < 0
def arcAngle_by_Length(current_arc, need_length):
# arclength = (2 * math.pi * current_arc.Radius) * (current_arc.SweepAngle / 360)
sweepAngle = (need_length * 360) / (2 * math.pi * current_arc.Radius)
return sweepAngle
def offset_Curve_keepLength(input_arc, factor):
global normal_vect
# input arc attribute
lengthArc = input_arc.Length
init_startAngle = input_arc.StartAngle
init_sweepAngle = input_arc.SweepAngle
if isClockwise(input_arc):
input_arc = input_arc.Reverse()
# offset arc
temparc = input_arc.Offset(factor)
try:
radius = temparc.Radius
except:
temparc = temparc.Explode()[0]
radius = temparc.Radius
new_sweepAngle = arcAngle_by_Length(temparc, lengthArc)
offsetAngle = (new_sweepAngle - init_sweepAngle) / 2
newarc = Arc.ByCenterPointRadiusAngle(
input_arc.CenterPoint,
radius,
temparc.StartAngle - offsetAngle,
temparc.StartAngle + new_sweepAngle - offsetAngle,
normal_vect
)
return newarc
input_arc = IN[0]
lstOffset = [0] + IN[1]
len_Bar = IN[2]
margin_overlap = 1 # in meter
normal_vect = Vector.ByCoordinates(0,0,1)
out = []
for d in lstOffset:
temp = []
offset_arc = offset_Curve_keepLength(input_arc, d)
print("offset_arc Length", offset_arc.Length)
start_Angle = offset_arc.StartAngle
end_Angle = offset_arc.StartAngle + offset_arc.SweepAngle
#
perimeter = offset_arc.Radius * 2 * math.pi
temp.append(offset_arc)
a, b = 1, -1
k= 0
#
while k < 500:
k += 1
a, b = b, a # swap each loop
marginAngle = (margin_overlap * 360) / (2 * math.pi * offset_arc.Radius)
# compute the arc remainder
restArc = Arc.ByCenterPointRadiusAngle(offset_arc.CenterPoint, offset_arc.Radius, end_Angle - marginAngle, start_Angle + marginAngle, normal_vect)
if math.ceil(restArc.Length) < len_Bar:
restArc = restArc.Translate(0,0, a * -0.1)
temp.append(restArc)
# remove small curves
temp = [c for c in temp if c.Length > margin_overlap]
out.append(temp)
break
#
# rotate the new arc
offset_arc = offset_arc.Rotate(offset_arc.CenterPoint, Vector.ByCoordinates(0,0,1), offset_arc.SweepAngle - marginAngle)
# add a small vertical offset
offset_arc = offset_arc.Translate(0,0, a * 0.1)
# update end angle
end_Angle = offset_arc.StartAngle + offset_arc.SweepAngle
temp.append(offset_arc)
#
OUT = out
offset curve keep length_v5.dyn (22.9 KB)
Can you please make changes to your last script based on my real input below to get curves offset and overlap? (I dont know how to enter necessary codes in the python node).
Pls check below my script and Revit model
cyril.dyn (32 KB)
slab.rvt (3.3 MB)
Thanks.
Hello, to answer your question in pm, I prefer to answer in public so that it can help in case or on the general forum,
for some spokes the penultimate bar is reduced because it is insufficient in length to cover the upper bar at 360° (the 1st in the series) therefore reduction of the penultimate bar (and same overlap on both sides), I don’t 've managed to manage that way (I fried a lot of neurons lol)
Cordially
christian.stan
Thank you @c.poupin for doing most of the job for me
I would have preferred too but I’m a new Dynamo user and I never worked with python and at the same time I would appriciate it if you gave me some links or examples where I can learn to use it.
I tried your script…it working perfectly but there is a mistake in position of the first rebar at right side (cover at right side=0 and should be =0.108m as in the left side).
I’ll ask you for one more thing…I want to enter the correct overlap length which is equal to lr= 50 * d (d is the barre diameter)
Thanks.
I discovered the error for the cover and I solved it (you have put for spacing : lstOffset = [0] + IN[1] and it should equal to: lstOffset = IN[1]
Please help me to enter my correct overlap length as I indicate above.
Thanks.
Please read the forum rules (How to get help on the Dynamo forums ) and the community guidelines (https://forum.dynamobim.com/faq )
you can try to replace the value 1 (in red below) with your calculated value.
you will need to add an input to the python script
precisely I’ve change this value to 0 because there was an offset in the vertical direction between the curves then between my rebars (I think there is an error in vector direction)
Thanks for your guideline how to enter the calculated overlap length in the python script (just for correction the calculated value should be entered in margin-overlap= IN[3])
Thanks.
In a rush I made the wrong line, see my previous post modified