How can I force a solution to recompute if a new file is opened in Rhino… (3D, DXF, DWG… anything really)? I need it because of the Human Plug-in.
private void RunScript(object x, object y, ref object A)
{
RhinoDoc.BeginOpenDocument -= BeginOpenDocumentHandler;
RhinoDoc.BeginOpenDocument += BeginOpenDocumentHandler;
Print(counter.ToString());
}
// <Custom additional code>
int counter;
public void BeginOpenDocumentHandler(object sender, Rhino.DocumentOpenEventArgs e)
{
// Do something
counter++;
// Prepare a new solution
GrasshopperDocument.ScheduleSolution(1, d => {
//Expire this component if you need it (to update the out output in this case)
this.Component.ExpireSolution(false);
});
}
I can´t make it work… What am I missing? I copy pasted the code in C, but when I open a new document it does not recompute.
It worked for me.
How do you expect me to know?
In a C# scripting component?
Did you paste it properly?
Did you press Run (the green play button)?
No errors when computing?
Are you using Rhino6?
Rhino 6.
No errors.
What grean play button?
Ah this. yes.
Trouble is it just doesn´t recompute the Grasshopper file
GrasshopperDocument.ScheduleSolution() does. If not, the scripting component could not change, and when you open a new document in RH, the counter changes, as you can see in the out output. Another thing is that you want to recompute a component that has already been resolved in the previous solution, in that case you have to expire it (or expire them all). Each new GH solution only recomputs the expired components, which is a way of saying to GH, please update this component the next time you solve it. Because if your source parameters haven’t been changed, its status wasn’t going to change, so it’s not worth recomputing them all the time.
Your lack of detail has already wasted me enough time, It’s insulting that I spend more time answering than you asking. Try calling GrasshopperDocument.ExpireSolution(). Good luck.
I am sorry my friend. Believe me I am not here to insult anybody, but to learn. Trouble is coding is not my water at all, so I am struggling to understand every single step.
Here is what I am trying to do. I have this C component which I want to force to re-calculate every time a new file is loaded. The component must return the path to the given file. That´s all. So far it works but I can not make it update.
I have tried your suggestions, however by pure trial and error…
private void RunScript(object x, ref object Path)
{
// Getting Command History text
string text = Rhino.RhinoApp.CommandHistoryWindowText;
// Splitting into array of lists
string results = text.Split(new { ‘\r’, ‘\n’ });
string path = null;
foreach(string s in results){
// Checking if the current command-line is the opening of a dxf file
if((s.StartsWith(“Successfully read file “”) || s.StartsWith(“Se ha leído correctamente el archivo “”)) && s.EndsWith(”.dxf”") || (s.EndsWith(".dwg""))){
path = s;
// Removing first characters
path = path.Remove(0, 24);
// Removing last character
path = path.Remove(path.Length - 1, 1);
}
}
Path = path;
}
FilePath.gh (1.4 KB)
And yes you were totally right… It worked with this at the end indeed.
GrasshopperDocument.ScheduleSolution(1, d => {
//Expire this component if you need it (to update the out output in this case)
this.Component.ExpireSolution(false);
});
Thank you very much!