GrasshopperDocument.AddObject how to run/code it on VS

Hello Everyone,

after searching on Discourse Forum and on the net, I only found this source about my issue:
http://james-ramsden.com/grasshopperdocument-component-grasshopper-visual-studio/
and this below:
https://discourse.mcneel.com/t/grasshopperdocument-objects-in-vs/63418/2

But it is not clear to me how to integrate the codes above in my VS script.

The problem is this CS0103:

I hope that someone could give me an example/tips to go on my task.
Thank you in advance!

Without seeing more of the code, it seems you have not defined GrasshopperDocument. Both Resources you link to show an example of how to do this:

Thank you, Luis, for your prompt response!

You are right I don’t know why it gave me an error. Anyway, when you code even a healthy sleep it makes you see things differently and you avoid making the same mistake. I will try to update this thread as soon as I can compile everything correctly. Thanks again. :slightly_smiling_face: :ok_hand:

1 Like

GrasshopperDocument is defined in the built-in C# component, referencing the current Grasshopper document.

  • If you are coding a component, you should use OnPingDocument().
  • If you are coding outside a component, and in most cases it is Instances.ActiveCanvas.Document
  • If your plugin works in headless contexts like rhino.compute and you are coding outside a component, it should be enumerating GH_DocumentServer.

Thank you Keyu Gan! :slight_smile:

Also For RhinoDocument? What?
Can we create a Class for reference toRhinoDocument and GrasshopperDocument similar c# component? For fast results in Vs?

Yes and no.

For some cases you can, but it won’t be faster. For some cases you shouldn’t.

Meanwhile, AddObject in SolveInstance is dangerous. You should, at least, do it in AfterSolveInstance.