Ambrosinus
(Luciano Ambrosini)
August 8, 2022, 9:34pm
1
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!
fraguada
(Luis Fraguada)
August 9, 2022, 5:30am
2
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:
Ok, so VB was a typo, VS was meant.
Now I understand the problem. The OnPingDocument method is what you need when developing within Visual Studio. Something along these lines:
private IGH_DocumentObject[] AllCanvasObjects()
{
var doc = OnPingDocument();
if (doc == null)
return new IGH_DocumentObject[0];
return doc.Objects.ToArray();
}
Ambrosinus
(Luciano Ambrosini)
August 9, 2022, 9:41am
3
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.
1 Like
gankeyu
(Keyu Gan)
August 9, 2022, 10:01am
4
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.
Rh-3d-p
(R-d)
August 9, 2022, 7:53pm
6
Also For RhinoDocument? What?
Can we create a Class for reference toRhinoDocument and GrasshopperDocument similar c# component? For fast results in Vs?
gankeyu
(Keyu Gan)
August 10, 2022, 4:54am
7
Yes and no.
For some cases you can, but it won’t be faster. For some cases you shouldn’t.
gankeyu
(Keyu Gan)
August 10, 2022, 4:56am
8
Meanwhile, AddObject in SolveInstance is dangerous. You should, at least, do it in AfterSolveInstance.