-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLASU4.py
64 lines (47 loc) · 1.99 KB
/
CLASU4.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
import rhinoscriptsyntax as rs
import scriptcontext
import Rhino.Geometry as rg
def get_start_and_end_points():
# Ask the user for the starting point
start_point = rs.GetPoint("Select the starting point of the curve")
# Check that the user did not cancel the operation
if start_point is None:
return None, None
# Ask the user for the end point
end_point = rs.GetPoint("Select the end point of the curve")
# Check that the user did not cancel the operation
if end_point is None:
return None, None
return start_point, end_point
def main():
# Get the start and end points from the user
start_point, end_point = get_start_and_end_points()
if start_point is None or end_point is None:
return
desired_length = None
# Ask the user to input the desired length as a valid number
while desired_length is None:
try:
desired_length = rs.GetReal("Enter the desired length of the curve")
except ValueError:
print("Invalid input. Please enter a valid number.")
# Create a NURBS curve based on a straight line
curve = rg.LineCurve(end_point, start_point)
# Calculate the original curve length
curve_length = curve.GetLength()
# Calculate how much length is missing to reach the desired length
extension_length = desired_length - curve_length
# Extend the curve by the desired length
extended_curve = curve.Extend(rg.CurveEnd.Start, extension_length, rg.CurveExtensionStyle.Smooth)
# Check if the curve extension was successful
if extended_curve:
# Save the curve GUID
extended_curve_guid = scriptcontext.doc.Objects.AddCurve(extended_curve)
# Update the view
scriptcontext.doc.Views.Redraw()
# Inform the user
print("Curve extended successfully to the desired length")
else:
print("Failed to extend the curve.")
if __name__ == "__main__":
main()