Grasshopper

algorithmic modeling for Rhino

All,

I have an odd error that I don't know how to overcome with a component that is using variable output param methods.  

Everything is fine up unto the point where data is assigned to the output.  To do this I've used what seemed to be the obvious method - a for loop that is constrained by the Params.Output.Count - as below. To ensure that all of the 'data' was present I decided to test with i.ToString() as my data but unfortunately this doesn't impact on the error.

protected override void SolveInstance(IGH_DataAccess DA)
{

// Methods

for (int i = 0; i < Params.Output.Count; i++)
{

      // Param naming conventions here

      // Param data

      DA.SetData(i, i.ToString());
}

}

The component stops producing the error when commented out. The error being provided is a Grasshopper breakpoint error warning that reads:

"Output parameter Index[0]too high or too low for Component."

(Note: no breakpoint stack information is provided in the window under the warning)

(Note: the error will cycle through as many params exist before ending)

Thanks for all help in advance.

Views: 1597

Replies to This Discussion

Hi Tree,

you should only call SetData or SetDataList once per iteration. If you do it inside a loop it'll go wrong.

If you want to assign a list of strings, then you need to set the access of the output to List inside the RegisterOutputParams method, then place a single call to DA.SetDataList() inside SolveInstance.

David,

Just so that I don't miss anything here I'm going to put this into point form.

1. To confirm this is for a component that is using the IGH_VariableParameterComponent class.

2. From the discussion in this link I think your suggestion to use and access level to list refers to this param.Access setting below.

param.Access = GH_ParamAccess.list;

3. Clearly am still confused and that maybe I didn't explain myself well earlier. : )

Q: How can a variable number of strings be sent to a variable number of params so that the number of strings created will force the number of params in the component to also change (so that they equal the number of strings)?

(I have been able to do everything except find a way to send data out to the canvas through a param without also receiving "Output parameter Index[0]too high or too low for Component." when the number of params increase - removing params doesn't seem to cause the error.)

Oops, my bad. I didn't realise you're assigning the strings to different parameters. In that case your SetData calls are correct. I can't tell from the code you posted what might be wrong. If you upload the entire code for the component I can test it tomorrow once I'm back in the office again.

David,

With some attempt to isolate the problem I think that the IGH_VariableParameterComponent class may have a bug.

1. My code executes fine when DA.SetData(i,variable[i]); is commented out.

2. My code executes fine when I replace the above with DA.SetDataList(i,variable[i]);

To test 1 to see if it was my variable I simply replaced variable[i] with "1" and it still failed - so there is something in DA.SetData that isn't working.

Do you still want my code or will this be sufficient to help you isolate the problem?

Hope all is well - many sincere thanks!

I'll need your code. IGH_VariableParameterComponent is an interface, not a class. Which means it does not have any internal code and thus it cannot have any bugs either. The bugs must either be in your implementation of that interface of in my code handling the interface.

David,

Here is the super minimal version that shows the problem. Please excuse the solution exception error if you uncomment the DA.SetDataList for testing - this stripped down version is very lightweight but hopefully it shows you the problem.

Attachments:

You are adding parameters during SolveInstance. You are not allowed to change the topology of the component during solutions.

The attached component makes the changes to outputs when it's allowed.

Attachments:

David,

A sincere thank you, this is very helpful!

David,

I have a second question. I am trying to have the output param symbol show the "A" icon (typically used by "Text" parameters).

I assumed that it would be possible to do this by returning a String parameter from the creation function ie.

public IGH_Param CreateParameter(GH_ParameterSide side, Int32 index)
{
return new Grasshopper.Kernel.Parameters.Param_String();
}

But the icon remains "Generic".  Am I doing something incorrectly? 

The entire code used is contained in the Class1 file just submitted.

CreateParameter is never called because you always return false in CanInsertParameter. You need to create a Param_String inside the FixOutputParameters() method in my counter-example.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service