C# - assigning color to points according to distances moved?

i’m trying to assign colors to points moved inside a c# component in grasshopper.
i would like to assign different color depending on the distance each point moved. (inside the same c# component)
i’ve tried using “AddPoint(Point3d, Color)” but it’s giving me "Error (CS0120): An object reference is required for the non-static field, method, or property"
could anyone advise me if “AddPoint(Point3d, Color)” would be the right one to use?
and if so, how i can fix this error?
if not, what would be better options?

Do you want to display points in colours, or do you want to add coloured points to the Rhino 3dm file currently loaded?

it would primarily for the visualisation purposes, so the former, but to be able to do the latter as well would def be an advantage if it’s not too complicated??

It’s not complicated, it just requires entirely different approaches. Or rather, here’s some ways to approach this:

  1. The C# component (or any component) can participate in the Grasshopper preview by drawing additional geometry. This will involve overriding the display methods (the eye icon in the cod editor) and collecting the data during all RunScript() calls. This is easy, but doesn’t provide any way for the user to access or bake the points. It may also conflict with the preview of the output parameter where you send your coordinates, so you have to hide the relevant parameters.
  2. Points can be added to the Rhino document using custom attributes which includes things like name, layer and display colour. The problem here is that you do not get to pick the symbol used, and of course unless you also add code which deletes old points you just keep pumping more and more geometry into the 3dm file each time your script runs.
  3. The hardest but most flexible approach is to create a new type of Goo (GH slang for data type) which knows how to draw itself with a specific colour, and which knows how to convert itself into regular points. This allows you to override the display and still output your points and use them downstream. This approach combines custom display and baking, but is by far the most complicated.

I think it probably makes the most sense to focus on #1 for the time being. Can you upload a file that shows how you modify some existing points?

You could have a look at petras examples here: C# for Grasshopper - petrasvestartas
in display there is this one:

test2d.gh (13.2 KB)

Thank you.
The slider moves points by different distances which I hope to connect to different color data.

test2d.gh (25.8 KB)

Hopefully enough to show the concept.

1 Like

Thank you David [: