Grasshopper

algorithmic modeling for Rhino

I have a Settings component that feeds into my main component, that looks like this:

The output is a List of Strings:

Which my component then reads, through the index of the list, like settings[0], settings[1], etc.

My question is, my component would not work without this Settings component, so what I've tried is, in my SolveInstance(), I would put the following code snippet:

if (!DA.GetDataList(0, settings)) {
    settings.Add("Black");
    settings.Add("White");
    settings.Add("0");
    settings.Add("0");
    settings.Add("");
    settings.Add("true");
    settings.Add("true");
return;
}

What (I think) this does is, if there is no settings component detect, pre-load the following default variables. If it DOES detect the Settings component, it would take the String List inputs instead.

However, this has not worked, and so far I'm also unable to find the default values from RegisterInputParams for List items either, where as you can set default values for GH_ParamAccess.item, like so: 

Appreciate the help.

Views: 1007

Replies to This Discussion

If the parameter is not Optional then it will prevent the component from solving itself entirely if there's no data supplied. Did you make the settings input optional?

--

David Rutten

david@mcneel.com

Then can you post all the code in SolveInstance prior to the code you already posted. Also, 'has not worked' is a big vague. Does the SolveInstance method not run at all? Is there an exception? If so, what does the exception say?

--

David Rutten

david@mcneel.com

Would it perhaps make more sense to validate the settings after calling GetDataList?

List<string> settings = new List<string>();

DA.GetDataList(0, settings);

if (settings.Count == 0)

{

  settings.Add("Black");

  settings.Add("White");

  ....

}

if (settings.Count != 7)

{

  AddRuntimeMessage(Error, "The settings have to be a collection of 7 items");

  return;

}

--

David Rutten

david@mcneel.com

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service