Creating new colorpickers through C#

Hello,

I have a problem where I want to create new colorpickers based on a number I generate through my definition. I have managed to do this with number sliders in a C# script that I found here on the forum, so I would like a similar approach as in the definition provided.

create_sliders.gh (5.9 KB)

My main problem is that I can’t find the class that I need in the API. In the create_sliders definition the Grasshopper.Kernel.Special.GH_NumberSlider class is used so I thought to look in a similar direction but can’t find the Grasshopper.Kernel.Special namespace in the API.

Any help in the right direction is much appreciated.

Copying your script, this seems to work:

Grasshopper.Kernel.Special.GH_ColourPickerObject colo = new Grasshopper.Kernel.Special.GH_ColourPickerObject();
colo.CreateAttributes();
colo.Attributes.Pivot = ...
GrasshopperDocument.AddObject(colo, false);

That works perfectly thanks, where did you find what the ColourPickerObject class is called?
Also could I find what properties and methods the class has somewhere?

Oh… literally searching by trial and error and by using the auto-completion of the interface:
2021-03-16 14_52_07-Script Editor

You can find a lot of stuff here API , but not everything is listed…

1 Like

Thanks, that helps a lot! I’m new to C# in GH so I didn’t know about the auto-completion.

Yeah I noticed that there is quite a bit missing from the API, but the auto-completion will make it easier to find them!

1 Like

So,Can you give me your final GH file?Thank you

Sure thing, here you go.

CreateSwatches.gh (9.9 KB)