Bug in Common? Project curve to plane adds points

Hi guys,
please take a look at this. I am altering curve editpoints and need to make a 2d version of the curve and then locate that versions editpoints, but if I coerce the curve (some curves only!) and project it to a plane and add that curve to the document then the new one has more editpoints. (Straight sections (degree 1) become degree2 as well)

The easiest is just to test this code on this file:
curve project more points.3dm (804.1 KB)

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

curve_id = rs.GetObject("select curve", rs.filter.curve, preselect=True)
if curve_id:
    curve=rs.coercecurve(curve_id)
    plane=rs.WorldXYPlane()
    curve2d = Rhino.Geometry.Curve.ProjectToPlane(curve,plane)
    curve2d_id = sc.doc.Objects.AddCurve(curve2d)
    
    rs.SelectObject(curve2d_id)
    rs.SelectObject(curve_id)
    rs.Command("_EditPtOn")

This is the workaround I made to fix this issue:

    # --- workaround ---
    curveelements = rs.ExplodeCurves(curve_id)
    plane=rs.WorldXYPlane()
    curve2ds = []
    for element in curveelements:
        curve = rs.coercecurve(element)
        curve2ds.append( Rhino.Geometry.Curve.ProjectToPlane(curve,plane))
    curve2d = Rhino.Geometry.Curve.JoinCurves(curve2ds)[0]
    curve2d_id = sc.doc.Objects.AddCurve(curve2d)
    rs.DeleteObjects(curveelements)
    rs.SelectObject(curve2d_id)
    # --- workaround ---

Hi @Holo,

Curve.ProjectToPlane converts in input curve to a NURBS curve before projecting. Otherwise, projecting will fail on some curve types (lines, circles, etc.).

Do you you have better success if you explode your polycurve and project the exploded pieces?

– Dale

Ok.

Yes, that’s what the workaround I posted does.

So the comman projectToCplane does the explode workaround and not the built in rhinocommon version?

Hey @Holo,

The ProjectToCPlane command does not explode the input curve. Rather, it does something like this:

import rhinoscriptsyntax as rs
import Rhino
import scriptcontext as sc

curve_id = rs.GetObject("Select curve to project", rs.filter.curve, preselect=True)
if curve_id:
    curve = rs.coercecurve(curve_id)
    dupe = curve.DuplicateCurve()
    if not dupe.IsDeformable:
        dupe.MakeDeformable()
    
    plane = Rhino.Geometry.Plane.WorldXY
    xform = Rhino.Geometry.Transform.PlanarProjection(plane)

    dupe.Transform(xform)
    dupe.RemoveShortSegments(Rhino.RhinoMath.ZeroTolerance)
    if dupe.IsValid:
        sc.doc.Objects.AddCurve(dupe)
        sc.doc.Views.Redraw()

I’ll tune up Curve.ProjectToPlane to work in this manner.

https://mcneel.myjetbrains.com/youtrack/issue/RH-81921

– Dale

1 Like