Hi all, whilst I am learning Python myself at the moment I figured I’d use ChatGPT to write some code for me to create some parametric designs. With the code below I get the following error message on line 64:
SystemError: error return without exception set
Keeping in mind I’ve barely done any debugging before, any tips on what’s going on here? Have also attached a GH file with the curve input internalised.
GPT_fail.gh (1.9 KB)
import Rhino.Geometry as rg
import math
import ghpythonlib.components as ghcomp
def project_curve_to_plane(curve, plane):
# Project the curve onto the plane
projected_curve = rg.Curve.ProjectToPlane(curve, plane)
return projected_curve
def create_star_of_david(center_point, size):
angle = 360 / 6 # 6 points for the Star of David
points = []
for i in range(6):
angle_rad = math.radians(angle * i)
x = center_point.X + size * math.cos(angle_rad)
y = center_point.Y + size * math.sin(angle_rad)
points.append(rg.Point3d(x, y, center_point.Z))
star_of_david = rg.PolylineCurve(points)
return star_of_david
def create_repeating_weaving_pattern(curve, weave_height, x_count):
weaving_pattern = []
# Project the curve onto the XY plane
plane = rg.Plane.WorldXY
projected_curve = project_curve_to_plane(curve, plane)
for i in range(x_count):
# Calculate the parameter 't' value
t_value = i / (x_count - 1)
# Evaluate the projected curve at the current 't' value
eval_point = projected_curve.PointAt(t_value)
# Get the tangent vector at the evaluated point
tangent_vector = projected_curve.TangentAt(t_value)
# Create a Star of David at the evaluated point
star_of_david = create_star_of_david(eval_point, weave_height)
# Offset the Star of David along the tangent direction of the projected curve
translation_vector = tangent_vector * weave_height
star_of_david.Translate(translation_vector)
# Add the Star of David to the weaving pattern
weaving_pattern.append(star_of_david)
# Transform the weaving pattern back to the original curve's coordinate system
transform = rg.Transform.PlaneToPlane(plane, rg.Plane.WorldXY)
weaving_pattern = [rg.Curve.Transform(curve, transform) for curve in weaving_pattern]
return weaving_pattern
# Main script
if __name__ == "__main__":
# Get the Grasshopper document
ghdoc = ghenv.Component.OnPingDocument()
# Input: Curve, weaving height, and number of repetitions along 't'
# Assuming you have a Curve parameter named "InputCurve" connected to your Grasshopper script
input_curve_param = ghenv.Component.Params.Input[0] # Assuming the Curve is the first input parameter
input_curve = input_curve_param.VolatileData.AllData(True)[0] # Access the first curve in the Rhino document
weave_height = 10.0 # You can adjust the weaving height as needed
x_count = 10 # Number of repetitions along 't', adjust as needed
# Generate the repeating weaving pattern for the Curve
weaving_pattern = create_repeating_weaving_pattern(input_curve, weave_height, x_count)
# Output: Display the weaving pattern in the Rhino document
for pattern_curve in weaving_pattern:
ghdoc.Objects.AddCurve(pattern_curve)