Bug in FitCurve


#1

Hi Steve,

could you check the code for FitCurve? It somehow does fit the curve, but then unfortunately returns the old input curve.

Thanks,
Andi


#2

Yeah, this does look like a bug…
(original from curve.py)

    curve = rhutil.coercecurve(curve_id, -1, True)
    if distance_tolerance is None or distance_tolerance<0:
        distance_tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    if angle_tolerance is None or angle_tolerance<0:
        angle_tolerance = scriptcontext.doc.ModelAngleToleranceRadians
    nc = curve.Fit(degree, distance_tolerance, angle_tolerance)
    if nc:
        rhobj = rhutil.coercerhinoobject(curve_id)
        rc = None
        if rhobj:
            rc = scriptcontext.doc.Objects.AddCurve(curve, rhobj.Attributes)
        else:
            rc = scriptcontext.doc.Objects.AddCurve(curve)
        if rc==System.Guid.Empty: raise Exception("Unable to add curve to document")
        scriptcontext.doc.Views.Redraw()
        return rc
    return scriptcontext.errorhandler()

I think it should be:

    curve = rhutil.coercecurve(curve_id, -1, True)
    if distance_tolerance is None or distance_tolerance<0:
        distance_tolerance = scriptcontext.doc.ModelAbsoluteTolerance
    if angle_tolerance is None or angle_tolerance<0:
        angle_tolerance = scriptcontext.doc.ModelAngleToleranceRadians
    nc = curve.Fit(degree, distance_tolerance, angle_tolerance)
    if nc:
        rhobj = rhutil.coercerhinoobject(curve_id)
        rc = None
        if rhobj:
             #changed curve to nc
            rc = scriptcontext.doc.Objects.AddCurve(nc, rhobj.Attributes)
        else:
            #changed curve to nc
            rc = scriptcontext.doc.Objects.AddCurve(nc)   
        if rc==System.Guid.Empty: raise Exception("Unable to add curve to document")
        scriptcontext.doc.Views.Redraw()
        return rc
    return scriptcontext.errorhandler()

Don’t guarantee I’m right though…

–Mitch


(Steve Baer) #3

That looks correct Mitch. I’ll make sure this is fixed in SR8. Thanks!