Offset hell!

Hi guys!
I’m trying to create a “special version” of the offset command, using RhinoCommon.
I’m trying to use these methods:

  • Curve.Offset(Plane, Double, Double, CurveOffsetCornerStyle)
  • Curve.Offset(Point3d, Vector3d, Double, Double, CurveOffsetCornerStyle)
    I’ve noticed that these methods are less reliable of Rhino “_Offset” command.
    More in detail, I’ve found that, in some cases, those methods simply fail (they return null) while the standard Rhino command succeed… Of course using the same working parameters, where possible.
    More in general, I would like to know what’s the best way to react to a null result or to a multiple curves result.
    Can you help me, please?
    Thanks

Sebastiano

Hi @software_comas,

Can you provide the curve, along with the source code, that isn’t working for you?

Thanks,

– Dale

Of course! In this file you can see the curve I’m trying to offset:

DemoOffsetFail.3dm (69.3 KB)

This is my code:

Plane constructionPlane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane();
Curve offsetCurves = myCurveGeometry.Offset(externalPoint, constructionPlane.Normal, 2.0, 0.01, CurveOffsetCornerStyle.Round);

offsetCurves is null.
externalPoint is any point extern to the curve
Thanks! :slight_smile:

Hi @software_comas,

The curve you’ve posted is bad. Basically one of the segments is shorter than the document tolerance.

To find, explode the curve and then run SelShortCrv.

– Dale

Sorry, @dale, but it seems that you’re wrong: after reading your answer, I cheked the contents of the doc with more attention and this is what I’ve found.
The document contains 2 curves: the visible one and another one that is very short (less than 0.01mm)
Exploding the main curve will result in a set of 11 curves but none of them is shorter than the document tolerance…
S.

Yeah whoops - I saw the short curve go by in the debugger. So I assumed (incorrectly) that was the problem.

This seems to work with your curve:

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc

crv_id = rs.GetObject("Select curve to offset 2 units", rs.filter.curve)
crv = rs.coercecurve(crv_id)

n = sc.doc.Views.ActiveView.ActiveViewport.ConstructionPlane().Normal
pt = Rhino.Geometry.Point3d(0.0, 50.0, 0.0)
tol = sc.doc.ModelAbsoluteTolerance

results = crv.Offset(pt, n, 2.0, tol, Rhino.Geometry.CurveOffsetCornerStyle.None)
if results:
    for rc in results:
        sc.doc.Objects.AddCurve(rc)
    sc.doc.Views.Redraw()

Notice the use of the CurveOffsetCornerStyle.None. If you run the Offset command with the Round corner style, it will fail too.

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

– Dale

Thanks a lot, @dale!