Offset curve with Tolerance, style, direction point, etc. - R7 common

To keep my geometry manageable and performant, I want to offset my curves with a tolerance value (as to not get too many control points per curve). So I found David Rutten’s Offset Curve with Tolerance component on the old forums (Wish: Curve Offset Tolerance in Component - Grasshopper) and managed to rename the component’s inputs (I like components to display full names).

Anyways, looking at the Rhinocommon curve offset documentation, I saw a direction point, angle tolerance, loose and corner- and endstyle options that I would also like to use.
I have no clue how to proceed, could someone help me with this? I’d like to have the full-blown Offset Curve component with all features, incl. a Both Sides option like in Pufferfish (to offset in negative direction by default).

Here’s what I have now, unfortunately, I can’t seem to get the EndStyle working to begin with.
Offset Curve C#.gh (11.6 KB)

E: If Visual Basic works better, that’s also fine by me. I don’t know either language.

Hi,
It should be pretty simple, you can follow this tutorial step by step and slightly adapt it to your use case : https://developer.rhino3d.com/api/rhinocommon/rhino.geometry.curve/offset
Rhino - Your First Component (Windows)

For some reason the component posted above stopped working. It’s symbol changed to ‘old’.
afbeelding
I don’t know how I should get it to work again.

Hi,

This is what I see in Rhino 7.

If you are working in Rhino WIP, the C#/Python/VB.NET scripting component have been changed to a new scripting component, so the old C# script would become old. Still, it should work.

However I do see an error in the last line of the red component, there is a comma that has nothing to do here.

Guess that was due to it being a WIP back then. I removed the comma and commented text, because I couldn’t get the script to work without spending a couple of days on learning C# :frowning:

It’s supposed to be this component now:
Offset Curves Tolerance.ghuser (2.3 KB)

Here is the C# with the EndStyle implemented.

private void RunScript(Curve Curve, Plane Plane, double Distance, int Corners, double Tolerance, double Angle_Tolerance, int Cap_Type, bool Loose, ref object Result)
  {
    if (Curve == null)
      return;

    if (Distance == 0.0)
    {
      Result = Curve;
      return;
    }

    if (!Plane.IsValid)
      if (!Curve.TryGetPlane(out Plane))
        return;

    if (Tolerance <= 0.0)
      throw new ArgumentException("Tolerance must be larger than zero");

    CurveOffsetCornerStyle Cornerstyle = CurveOffsetCornerStyle.Sharp;
    if (Corners == 2) Cornerstyle = CurveOffsetCornerStyle.Round;
    if (Corners == 3) Cornerstyle = CurveOffsetCornerStyle.Smooth;
    if (Corners == 4) Cornerstyle = CurveOffsetCornerStyle.Chamfer;

    Vector3d tang = Vector3d.CrossProduct(Curve.TangentAtStart, Plane.ZAxis);
    tang.Unitize();
    Point3d p = Curve.PointAtStart + tang;

    CurveOffsetEndStyle Endstyle = CurveOffsetEndStyle.None;
    if (Cap_Type == 0) Endstyle = CurveOffsetEndStyle.None;
    if (Cap_Type == 1) Endstyle = CurveOffsetEndStyle.Flat;
    if (Cap_Type == 2) Endstyle = CurveOffsetEndStyle.Round;

    Result = Curve.Offset(p, Plane.ZAxis, Distance, Tolerance, Angle_Tolerance, Loose, Cornerstyle, Endstyle); //Endstyle
  }

Offset Curve C#.gh (15.6 KB)

2 Likes

Thanks a lot @magicteddy it works great!

In the new code editor of R8 (WIP), the component throws an error:

I was looking to get rid of the ‘old’ icon and use the offset icon.
Offset Curve C#.gh (20.2 KB)

Hoi -

We have that request on the list as RH-76151 Grasshopper: Allow removal of OLD label on legacy Python script components
-wim

1 Like

Any idea as to why a formerly valid script fails in the new editor?

Try to add Result = null; at the beginning of the script.
It may be related to the upgrade of C# in WIP.

1 Like

Yes, that seems to fix it.
Considering the input names change when I save ths component as a user component, I think I’ll be looking into making this into a proper component following the guides in the 2nd post.

But before I do that @magicteddy do you happen to be able to add a both sides distance input, so I could offset a centreline in both directions and cap the result? Just like Pufferfish’s offset component? Then I can make it into an offset on steroids component to distribute in this topic :blush:
Thank you for your help this was one of the components I wanted to have for a couple years already.

1 Like

There is no direct BothSides option in any of the Offset signatures, so that would have to be done by hand (probably what Pufferfish does is offset by x then offset back by x+y with the cap options).
I also noticed Loose option doesn’t work with caps, whereas the Rhino command does.
So I think it would be best to also build the caps manually.

I’ll look into that… when I have more time.

Do you need the Loose option ?

And Pufferfish has continuity options for capping, but not a simple half circle.

1 Like

I don’t necessarily need the loose option for my current project. And indeed, Pufferfish does seem to have been customly scripted for the both sides option. What it doesn’t do is always make the second distance input a negative value, so it is actually moved to the other side of the curve.
In other words:
Distance = x
Both Sides = -x (I always have to add an expression to the input for this or a negative before my input)

As for caps, I only really need the end points connected when I offset to both sides, anything else is a nice to have.

Well, let’s call the component Magic Curve Offset or offset curve with tolerance :wink:

Smaaaaart Offseeeet Cuuuurve !

I know this makes it two components, but there is native Connect Curves component that will do that.

Depending on the output, you need to add a list item to connect the first set of curves and the second set of curves. When there are more distances supplied, you’ll need to do sorting. So at least 2 additional components if you have to use connect curve ends (indicated by the arrow). The one up top is connect curves.

A star is born.

magicteddy.gha (76.5 KB)

1 Like

It’s not a star, it’s a unicorn! :unicorn:

Really cool!, I’ll check it out first thing tomorrow, but do already want to leave a thank you message!
Thanks, this will help me build a lot of cool scripts! Also, a good tip, by lowering the tolerance during the conceptual stage, you can easily shave off half of the computation time for the offset. That’s why I wanted it so badly. It’s the difference between live updates and sluggish updates (with very control point bloated splines) :slight_smile:
:+1:

@Intuos See this for removing the Old icon from your components

1 Like