This repository was archived by the owner on Jun 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWave-washer.py
More file actions
85 lines (64 loc) · 2 KB
/
Wave-washer.py
File metadata and controls
85 lines (64 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#https://help.alibre.com/articles/#!alibre-help-v28/wave-washer
import math
from math import *
# radius
R = 100.0
# amplitude
A = 10.0
# number of waves (must be a whole number)
B = 4
# width
Width = 10
# thickness
Thickness = 5
Win = Windows()
Options = []
Options.append(['Radius', WindowsInputTypes.Real, R])
Options.append(['Amplitude', WindowsInputTypes.Real, A])
Options.append(['Number of Waves', WindowsInputTypes.Integer, B])
Options.append(['Width', WindowsInputTypes.Real, Width])
Options.append(['Thickness', WindowsInputTypes.Real, Thickness])
Values = Win.OptionsDialog('Wave Washer Generator', Options)
if Values == None:
sys.exit()
R = Values[0]
A = Values[1]
B = Values[2]
Width = Values[3]
Thickness = Values[4]
# path accuracy = lower number = more points calculated
t_step = 0.1
# complete circle = PI x 2
t_max = 3.141592 * 2
# keep track of the total points we have calculated
TotalPoints = 0
# calculate points for 3D sketch
PathPoints = []
t = 0
while True:
X = R * sin(t)
Y = R * cos(t)
Z = A * sin(B * t)
PathPoints.extend([X, Y, Z])
if TotalPoints == 0:
P1 = [X, Y, Z]
elif TotalPoints == 1:
P2 = [X, Y, Z]
t = t + t_step
TotalPoints = TotalPoints + 1
if t >= t_max:
break
# close path
PathPoints.extend([PathPoints[0], PathPoints[1], PathPoints[2]])
# create part and add 3d sketch
P = Part('Wave Washer')
Path = P.Add3DSketch('Path')
Path.AddBspline(PathPoints)
# calculate normal vector for the plane at the start of the path
normal_vector = [P2[0] - P1[0], P2[1] - P1[1], P2[2] - P1[2]]
# create plane at the start of the path
Plane = P.AddPlane('Start Plane', normal_vector, P1)
CrossSection = P.AddSketch('Cross Section', Plane)
Origin = CrossSection.GlobaltoPoint(P1[0], P1[1], P1[2])
CrossSection.AddRectangle(Origin[0] - (Thickness / 2.0), Origin[1] - (Width / 2.0), Origin[0] + (Thickness / 2.0), Origin[1] + (Width / 2.0), False)
P.AddSweepBoss('Washer', CrossSection, Path, False, Part.EndCondition.EntirePath, None, 0, 0, False)