Hi @pascal and @stevebaer
I am working on a script where I make a simplified offset of a 3D curve and I need to adjust the location of the new curve editpoints, but I have not figured out how, so I hack around it.
Here is what I do:
- project 3D curve to xy-plane
- offset the 2D curve
- find closest point of each editpoint of the offset
- move each editpoint to corresponding height of 3D curve
In the workaround I add the offsetcurve to document, turn on editpoints and move them with rs.ObjectGripLocations() and then coerce the result and delete the temporary curve.
But this slows down the process and makes the code more messy, is it possible to do it in Common directly?
Thanks.
### Offset_2.5D_curve by Holo 2024
import rhinoscriptsyntax as rs
import Rhino
import Rhino.Geometry.Curve as curve
import scriptcontext as sc
def offset3dcurve(curve):
plane = rs.WorldXYPlane()
curve2D = Rhino.Geometry.Curve.ProjectToPlane(curve, plane)
distance = 1
tolerance = 0.05
cornerstyle = Rhino.Geometry.CurveOffsetCornerStyle(1)
offset2D = Rhino.Geometry.Curve.Offset(curve2D, plane, distance, tolerance, cornerstyle)
offset_id = sc.doc.Objects.AddCurve(offset2D[0])
rs.SelectObject(offset_id)
rs.Command("_NoEcho _PointsOff _EditPtOn", False)
grips = rs.ObjectGripLocations(offset_id, points=None)
for i in range(len(grips)):
param = curve2D.ClosestPoint(grips[i],0)
closepoint = curve.PointAt(param[1])
point = rs.coerce3dpoint((grips[i].X,grips[i].Y, closepoint.Z))
rs.ObjectGripLocation(offset_id, i, point)
offsetcurve = rs.coercecurve(offset_id)
rs.DeleteObject(offset_id)
return offsetcurve
curve_id = rs.GetObject("curve to offset", rs.filter.curve, preselect=True)
if curve_id:
rs.EnableRedraw(False)
curve = rs.coercecurve(curve_id)
offsetcurve = offset3dcurve(curve)
sc.doc.Objects.AddCurve(offsetcurve)
sc.doc.Views.Redraw()
rs.EnableRedraw(True)
Here you can see why I do this.
Rhino’s offset result to the left, my script to the right:
(PS! Right now I just use w0,0,0 as the offsetdirection to keep the example script as simple as possible)
1 post - 1 participant