Using Clipper Lib in c# component for offsets

Hello everyone! I am trying to use the Clipper Lib. I have read the documentation however I fear my level of knowledge in c# is lacking. What king of input should i give the c# component to create ofssets of polylines? For now I am taking the discontinuity points of polylines and adding them in a list of lists, converting the inputted Point3d to IntPoint type.
Now I need to create a Path/ Paths to use the ClipperOffset.AddPath. But I cannot seem to get a hang of it. I try to start with using Path = List< IntPoint >; | using Paths = List<List< IntPoint >>; which I am seeing in many code examples, but it just throws errors.
Please help :slight_smile:

@arendvw If you could help, I 'd really appreciate it.

Hi Eleni, what errors are you getting?

I would argue the main example from the github:

Below is a simplified version of this component.

The ClipperTools contains a copy of the clipper library by Agnus Johnson, and some glue code to convert from and to integer type points. (Which can be a bit confusing). All relevant code is in geometry.cs and should be trivial to copy/paste for your own needs).

  1. Make sure you reference ClipperTools.dll from the plugin (easiest is to use the .zip file). Or if you use the package manager, it will be installed in C:\Users\[YOURUSERNAME]\AppData\Roaming\McNeel\Rhinoceros\packages\7.0\Clipper\0.3.3\ClipperTools.dll
  2. The following C# script should work:

example-grasshopper.gh (6.3 KB)

  using StudioAvw.Geometry;

  // ....

  private void RunScript(List<Polyline> polylines, double distance, double tolerance, ref object Holes, ref object Contours)
  {
    List<Polyline> outputHoles;
    List<Polyline> outputContours;
    Polyline3D.Offset(polylines, Polyline3D.OpenFilletType.Round, Polyline3D.ClosedFilletType.Round, distance, Plane.WorldXY, tolerance, out outputHoles, out outputContours);

    Holes = outputHoles;
    Contours = outputContours;
  }

Does this help?

Yes, thank you! Do you happen to have a .dll file of StudioAvw?

It’s the ClipperTools.dll mentioned above.

  1. Error (CS0246): The type or namespace name ‘StudioAvw’ could not be found (are you missing a using directive or an assembly reference?) (line 13)

I am trying to create another dll but I don’t know how to solve this:

|Warning||The primary reference clipper_library could not be resolved because it was built against the .NETFramework,Version=v4.8 framework. This is a higher version than the currently targeted framework .NETFramework,Version=v4.7.2.|StudioAvw||||

PS: To be clear the ClipperTools assembly is being used.

Can you send a screenshot of the error? Are you trying to use a C# component in grasshopper, or compile your own library?

For a C# component in grasshopper:
Right click component:
image

In a custom C# project:
You should reference the ClipperTools.dll, or the ClipperTools project in your own project

If this does not resolve it: What are you trying to do? Where do you see this error? I’m currently a bit lost at what you’re trying to do.

So, I have the ClipperTools added as an assembly.
In the gh definition you sent me I get this error:
Error (CS0246): The type or namespace name ‘StudioAvw’ could not be found (are you missing a using directive or an assembly reference?)
I assumed this means that I am missig a library. Therefore if you have the StudioAvw dll file, I would be grateful if you sent it to me.
Otherwise, I am trying to create a dll file from the code of Github, but I am stuck with this error:
|Warning||The primary reference clipper_library could not be resolved because it was built against the .NETFramework,Version=v4.8 framework. This is a higher version than the currently targeted framework .NETFramework,Version=v4.7.2.|StudioAvw||||
I hope I am making myself clear. thank you so much for your time.

The StudioAvw.Geometry namespace is in the ClipperTools.dll library. There is no StudioAvw project or StudioAvw.dll.

Which version of Clipper are you using?

It is just that I don’t know what to do with the namespace (StudioAvw) in github. How do I add it to a C# component? The way I understand this the whole c# component is a namespace. If I just copy-paste it in the afterRunscript section it doesn’t work.
The ClipperTools I am using is from a zip file, cause when I download clipper from FoodFromRhino I get an .rhi file.
The info I can get from the version of the dll file are shown in the photo.

image

This is not ClipperTools.dll, but a dll downloaded from Angus Johnson, am I correct?

The code I have given you will not work directly with the original clipper library; but only with the version of Clipper I have released, which you can download from food4rhino. There is a Zip version available here:

1 Like

Thank you so much for your time. Now it works. It was probably the wrong dll.
Have a nice day!