algorithmic modeling for Rhino
Hi,
I am writing a c# plugin that uses an automatic sampling loop that reads 'job' files from a directory and writes results (collected from custom components) to 'result' files in another directory.
I am currently using a static class that upon initiating the plugin (when one of my components is put inside the canvas) creates (only once) 2 event handlers:
public class Control
{
private static volatile Control _instance = null;
public bool registered;private Control() { registered = false; }
public static Control getInstance(GH_Document document)
{
if (_instance == null)
{
_instance = new Control();
if (!_instance.registered)
{
document.RaiseEvents = true;
document.SolutionStart += _instance.document_SolutionStart;
document.SolutionEnd += _instance.document_SolutionEnd;
}
}
return _instance;
}}
Now the idea is that:
void document_SolutionEnd(object sender, GH_SolutionEventArgs e)
{e.Document.ScheduleSolution(1);
}
Now the problem is that at each iteration not all sliders are adjusted (some stay constant over multiple iterations) I found that only the components downstream of the sliders that were changed during solutionstart are written to the result while the rest just writes empty data. (because I clear all static variable data at solution start)
So I was wondering if there is a way to schedule a solution that solves all objects in the canvas regardless of them being part of a stream that is adjusted in that stream (like saying "Recompute" in the canvas).
Note:
I guess an alternative could be to have a more intelligent 'clearing' of the static variables in step 1, so that for instance a static variable is cleared only if in that solution data was written by the components. However since I am writing with multiple components to the same static variable (which is a list) it becomes quite involved to track which components did and which didn't change during the solution.
Cheers Dion
Tags:
EDIT: I have managed to assure a full solution at each iteration by expiring the solution during the document_solutionstart, before the sliders are set to their new values, if anyone has similar problems a simplified snippet of the solutionstart method:
public void document_SolutionStart(object sender, GH_SolutionEventArgs e)
{// methods performed at every solution event of Grasshopper
// Expire solution (empty components)
e.Document.ExpireSolution();/// Methods performed only if lock is off
/// get job
string job = controlMethods.getJobFromDir(jobdir, filetype);/// process job (set slider values)
TotalJobs = controlMethods.ProcessJob(e.Document, job);
}
Dion
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by