-
Notifications
You must be signed in to change notification settings - Fork 0
/
GradeCurve.py
110 lines (87 loc) · 3.19 KB
/
GradeCurve.py
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
Copyright <2021> <Thomas Chapman>
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
# GRADE CURVE
import rhinoscriptsyntax as rs
def GradeCurve():
# try:
# Set Variables
crv = rs.GetObject(
message="Get object to grade",
filter=4,
preselect=True,
select=False,
custom_filter=None,
subobjects=False,
)
if not crv:
print ("No curve selected")
return False
grade = rs.GetReal(
message="Enter grade ratio number, or ENTER for height",
minimum=0.001,
maximum=None,
)
if not grade:
height = rs.GetReal(
message="Enter Height:",
minimum=0.001,
maximum=None,
)
if not height:
print("No user input")
return False
rs.EnableRedraw(False)
# FIND LENGTH OF CURVE AT EACH GRIP POINT
rs.EnableObjectGrips(crv)
ctrlPts = rs.ObjectGripLocations(crv)
crvLengths = []
startParam = rs.CurveClosestPoint(crv, ctrlPts[0])
if grade:
for i in ctrlPts:
paramNum = rs.CurveClosestPoint(crv, i)
CL = rs.CurveLength(crv, sub_domain=[startParam, paramNum])
crvLengths.append(CL)
# FIND GRADED Z HEIGHT OF GRIP POINT
gripHeights = []
for i in crvLengths:
rise = i / grade
gripHeights.append(rise)
# EDIT GRIP POINTS WITH NEW Z VALUE
newGrips = []
gripIndex = 0
for i in ctrlPts:
newPt = (i.X, i.Y, (i.Z + gripHeights[gripIndex]))
newGrips.append(newPt)
gripIndex = gripIndex + 1
# MODIFY CURVE TO ENTERED GRADE
rs.CopyObject(crv)
rs.ObjectGripLocations(crv, newGrips)
rs.EnableObjectGrips(crv, enable=False)
if height:
gripHeights = []
for i in ctrlPts:
paramNum = rs.CurveClosestPoint(crv, i)
normParam = (rs.CurveNormalizedParameter(crv, paramNum)) * 100
gripHeights.append((height / 100) * normParam)
newGrips = []
gripIndex = 0
for i in ctrlPts:
newPt = (i.X, i.Y, (i.Z + gripHeights[gripIndex]))
newGrips.append(newPt)
gripIndex += 1
rs.CopyObject(crv)
rs.ObjectGripLocations(crv, newGrips)
rs.EnableObjectGrips(crv, enable=False)
rs.EnableRedraw(True)
# except:
# print("Failed to execute")
# rs.EnableRedraw(True)
# return
# Run Script
if __name__ == "__main__":
GradeCurve()