I am having problems enabling this command in python.
I don’t understand why my system crashes
Versión 7 SR37 (7.37.24107.15001, 2024-04-16)
thanks in advance
Blockquote
“”“Provides a scripting component.
Inputs:
C: Curbe
x: The x Snap variable
y: The y Snap variable
P: Plan on redraw Curve wwith Snap
Output:
a: The a output variable”“”
Blockquote
author = “Jordi Nebot”
version = “2024.07.20”
import rhinoscriptsyntax as rs
import Rhino.Geometry as rg
print “0”
def generate_stepped_curve(curve, plane, x_step, y_step):
# Convertir la curva de entrada a una curva de Rhino.Geometry
curve = rs.coercecurve(curve)
plane = rs.coerceplane(plane)
print “A”
# Inicializar lista de puntos para la nueva curva escalonada
points =
# Obtener el primer punto de la curva en el plano
current_point = plane.ClosestPoint(curve.PointAtStart)
print "AA"
# adaptamos al snap XY
nX = round(current_point.X / x_step)
nY = round(current_point.Y / y_step)
current_point = rg.Point3d(nX * x_step, nY * y_step, current_point.Z)
print "AAA"
points.append(current_point)
print "B"
fer = True
i = 0
#while fer:
while True:
i=i+1
print i
# Obtener el parámetro actual en la curva basado en el punto actual
success, parameter = curve.ClosestPoint(current_point)
if not success:
fer = False
break
# Punto actual en la curva
point_on_curve = curve.PointAt(parameter)
# Calcular los siguientes puntos en base a los pasos x_step y y_step desde el origen del plano
next_Hpt = rg.Point3d(current_point.X + x_step, current_point.Y, current_point.Z)
befo_Hpt = rg.Point3d(current_point.X - x_step, current_point.Y, current_point.Z)
next_Vpt = rg.Point3d(current_point.X, current_point.Y + y_step, current_point.Z)
befo_Vpt = rg.Point3d(current_point.X, current_point.Y - y_step, current_point.Z)
# Proyectar los puntos al plano
next_Hpt = plane.PointAt(next_Hpt.X, next_Hpt.Y)
befo_Hpt = plane.PointAt(befo_Hpt.X, befo_Hpt.Y)
next_Vpt = plane.PointAt(next_Vpt.X, next_Vpt.Y)
befo_Vpt = plane.PointAt(befo_Vpt.X, befo_Vpt.Y)
# Puntos cercanos a la curva
next_HptCPt = curve.ClosestPoint(next_Hpt)[1]
next_HptCP = curve.PointAt(next_HptCPt)
befo_HptCPt = curve.ClosestPoint(befo_Hpt)[1]
befo_HptCP = curve.PointAt(befo_HptCPt)
next_VptCPt = curve.ClosestPoint(next_Vpt)[1]
next_VptCP = curve.PointAt(next_VptCPt)
befo_VptCPt = curve.ClosestPoint(befo_Vpt)[1]
befo_VptCP = curve.PointAt(befo_VptCPt)
# Determinar cuál de los 4 puntos está más cerca de la curva
distance_to = 1000000
if distance_to > next_HptCP.DistanceTo(next_Hpt) and next_Hpt != current_point:
next_point = next_Hpt
distance_to = next_HptCP.DistanceTo(next_Hpt)
if distance_to > befo_HptCP.DistanceTo(befo_Hpt) and befo_Hpt != current_point:
next_point = befo_Hpt
distance_to = befo_HptCP.DistanceTo(befo_Hpt)
if distance_to > next_VptCP.DistanceTo(next_Vpt) and next_Vpt != current_point:
next_point = next_Vpt
distance_to = next_VptCP.DistanceTo(next_Vpt)
if distance_to > befo_VptCP.DistanceTo(befo_Vpt) and befo_Vpt != current_point:
next_point = befo_Vpt
distance_to = befo_VptCP.DistanceTo(befo_Vpt)
points.append(next_point)
current_point = next_point
# Verificar si hemos llegado al final de la curva
if parameter >= curve.Domain[1]:
fer = False
break
# Crear la polilínea escalonada a partir de los puntos generados
stepped_curve = rg.Polyline(points).ToNurbsCurve()
return stepped_curve
Blockquote# Obtener entradas desde Grasshopper
#curve_A = rs.coercecurve(C)
#plane_P = rs.coerceplane(P)
print “00”
curve_A = C
plane_P = P
x_step = x
y_step = y
print “000”
#Generar la curva escalonada
stepped_curve = generate_stepped_curve(curve_A, plane_P, x_step, y_step)
#Salida para Grasshopper
a = stepped_curve
SnappingCurve.gh (9.1 KB)