Grasshopper

algorithmic modeling for Rhino

Solution Scheduling: schedule a "full" solution solving all instances in the canvas

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:

  1. the method at solutionstart clears all static variables
  2. a new job file is read and sliders are set accordingly
  3. the components produce their solutions and record them in the static variables
  4. the method at solutionend writes all the data stored in the static variables to a result file and schedules a new solution like:

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

Views: 852

Replies to This Discussion

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

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service