Dynamically changing CurveEditPoints in viewport to update the shape of the curve using python script.
I know how to change it’s shape using an attracter point. But It changes the curve completely. For minute change I want to drag a CurveEditPoint (using python script), unable to figure it out yet.
to do:
selecting a CurveEditPoint and dragging it to change the shape of the curve ‘n’ times.
Hi,
You can use Rhino.Geometry.ControlPoint(new_point, curve.Points[point_index].Weight) to move the curve control point to your liking.
That’s one possible approach :
import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino
def move_control_point():
# Prompt user to select a curve
curve_id = rs.GetObject("Select a curve", rs.filter.curve)
if curve_id is None:
return
# Get the curve object from the document
curve_obj = sc.doc.Objects.Find(curve_id)
curve = curve_obj.Geometry
# Check if the curve is a NURBS curve
if not isinstance(curve, Rhino.Geometry.NurbsCurve):
print("The selected curve is not a NURBS curve.")
return
# Prompt user to select a control point index
num_points = curve.Points.Count
point_index = rs.GetInteger("Enter the control point index (0-{})".format(num_points - 1), 0, 0, num_points - 1)
if point_index is None:
return
# Get the original control point location
original_point = curve.Points[point_index].Location
# Prompt user to select a new location for the control point
new_point = rs.GetPoint("Select new location for control point", original_point)
if new_point is None:
return
# Move the control point to the new location
curve.Points[point_index] = Rhino.Geometry.ControlPoint(new_point, curve.Points[point_index].Weight)
# Update the curve geometry in the document
sc.doc.Objects.Replace(curve_id, curve)
sc.doc.Views.Redraw()
if __name__ == "__main__":
move_control_point()
You can integrate a nice userinterface yourself and previews using the display conduit.
2 Likes