algorithmic modeling for Rhino
Hi guys,
I am getting the following error with the couple lines of C# below:
`Solution exception: GetData() can only be called on a parameter with access set to GH_ParamAccess.item`
There might be a conflict between the GH_ParamAccess.list argument and the DA.GetData ones. I read this very helpful thread where David explains the GH_ParamAccess Enum:
If you have only one input param and its access is set to item, then SolveInstance() will be called once for each element in the data. If the access is set to list, then SolveInstance() will only be called once for every list of items in the data.
The fact that the Param Access is set to list in this case means that the Solve instance is running once for every item in the list (of strings) but this should not influence the GetData() method which runs once every time. I am not sure what is happening, it might be related to this bug? hope you guys can help.
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("SomeString", "SS", "Send Some String Somwhere", GH_ParamAccess.list); //0
}
protected override void SolveInstance(IGH_DataAccess DA)
{
string SomeString = default(string);
DA.GetData(0, ref SomeString);
if (!DA.GetData(0, ref SomeString)) return;}
Many thanks,
Arthur
Tags:
"The fact that the Param Access is set to list in this case means that the Solve instance is running once for every item in the list (of strings) but this should not influence the GetData() method which runs once every time." - this is wrong, as David says in the section you quoted, for list access solve instance runs once for each list, not for each item in the list.
When you get your data as a list, you have to use DA.GetDataList, and operate on the List object.
Thanks Andrew!
I have added DA.GetDataList:
protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
{
pManager.AddTextParameter("SomeString", "SS", "Send Some String Somwhere", GH_ParamAccess.list); //0
}
protected override void SolveInstance(IGH_DataAccess DA)
{string SomeString = default(string);
DA.GetDataList(0, ref SomeString);if (!DA.GetDataList(0, ref SomeString)) return;
}
I get the following error on the DA.GetDataList line though:
`The type arguments for method 'Grasshopper.Kernel.IGH_DataAccess.GetDataList<T>(int, System.Collections.Generic.List<T>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.`
Sorry, I guess I need to specify a list of string and not a string:
List<string> someStrings = new List<string>();
if(! DA.GetDataList(0, someStrings)) return;
Sorry, bit late on this one but the problem is not the datatype being a string, but that you were using the 'ref' keyword.
For example, the following works fine:
pm.Register_IntegerParam("Some numbers", "I", "Some numeric stuff", GH_ParamAccess.list);
....
List<int> myStuff = new List<int>();
if (!DA.GetDataList<int>(0, myStuff)) { return; }
Probably too late, but might help others.
Hey I tried this with a Data Tree and it doesnt work. I know this post is 3 years old but I am still hoping you could answer. Thank you
When outside of scripting components, you should use GH_Structure instead of DataTrees. As far as I remember, you can set tree for the output parameter, but you have to use GH_Structure with the inputs.
Hey,
I was wondering if you had an example of a GH_Path for GH_structure in visual studio to access items in a tree with Get_DataItem? In the SDK, it is just written that it should be a series of integers but they didn't specify the exact form?
Thank you
Hi,
I am getting this error message and I am not sure what do to - reading thius doesnt make much sense to me so if somebody could explain in simpler terms?
Thanks
Natalie
Are you getting it on a component that you yourself are writing? or is it showing up as an error in an existing grasshopper component (or one from an add-in)?
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