I want to remove all sources (wires) connected to an Inport using the command
… but when & where should I remove while avoiding to expire a solution while its running?
I tried searching on both forums, and GrassHopper SDK documentation doesn’t seem to explain these rather murky areas of GH…
Awards for a solution to this one:
There’s two main situations in which code that modifies the file runs:
- As a response to a UI event, this always happens outside of solutions because while a solution runs the UI is not processing messages.
- As a part of a scheduled solution.
I assume you need #2
Inside your RunScript or SolveInstance or whatever method, get the document that contains your component. In a C# script that’s just
GrasshopperDocument, inside a compiled GH_Component class that’s by calling the
OnPingDocument() method and making sure you didn’t get
null in return. Then you schedule a solution on that document, usually picking a short interval. Something between 5 to 50 milliseconds for example. You also must provide a schedule callback. This callback method will be called whenever the next solution kicks off, even if it is way earlier than your schedule request. Inside the callback you are allowed to make all the changes you want, add objects, delete objects, modify values, add or remove connections etc.
OK, thanks for you reply.
I tried the following code but I don’t get expected response (“Scheduled response”). What am I doing wrong?
private void RunScript(object x, object y, ref object A)
var callbackDelegate = new GH_Document.GH_ScheduleDelegate(this.Callback);
if (callbackDelegate != null)
Print("Yup, seems OK.");
Print("Scheduling Callback returns null!");
// <Custom additional code>
private void Callback(GH_Document doc)
// </Custom additional code>
callback_test.gh (2.4 KB)
Not sure what the mistake is, but you can just use the method name without parenthesis:
Eh, it actually works. Only Print doesn’t work…
ah! That’s the problem.
It’s too early to start printing stuff, the solution isn’t really running yet. Also your component is not automatically expired, so there’s no guarantee it will run at all in this solution.
RhinoApp.WriteLine() if you want to test code like this, that always works.