Grasshopper

algorithmic modeling for Rhino

Input Parameter Exception: "An item with the same key has already been added"

I am designing a GH component in VS 2013.

My component has been running fine, except for when I was working on some of the script today, I got the following error:

"1. Solution exception:An item with the same key has already been added."

My debugger throws the error in GH when I am defining my inputs. From my code:

Protected Overrides Sub RegisterInputParams(pManager As GH_Component.GH_InputParamManager)

With pManager

.AddTextParameter("columnnames", "columnnames", "Name of Columns", GH_ParamAccess.list)
.AddPointParameter("colnode1XYZ", "colnode1XYZ", "colnode1XYZ", GH_ParamAccess.list)
.AddPointParameter("colnode2XYZ", "colnode2XYZ", "colnode2XYZ", GH_ParamAccess.list)
.AddTextParameter("nodenames", "nodenames", "nodenames", GH_ParamAccess.list)
.AddPointParameter("nodeXYZ", "nodeXYZ", "nodeXYZ", GH_ParamAccess.list)

.AddBooleanParameter("activate", "activate", "Run the program (True/False)", GH_ParamAccess.item)

End With

End Sub

'--------------

Protected Overrides Sub SolveInstance(DA As IGH_DataAccess)

Dim activate As Boolean = False

' Defining inputs from GH
Dim columnnames As New List(Of String)
Dim colnode1XYZ As New List(Of Point3d)
Dim colnode2XYZ As New List(Of Point3d)
Dim nodenames As New List(Of String)
Dim nodeXYZ As New List(Of Point3d)

DA.GetData("activate", activate)

If activate Then

' Data input
With DA
.GetDataList("columnnames", columnnames)
.GetDataList("colnode1XYZ", colnode1XYZ)
.GetDataList("colnode2XYZ", colnode2XYZ)
.GetDataList("nodenames", nodenames)
.GetDataList("nodeXYZ", nodeXYZ)
End With

... My definitions have not changed... and the exception occurs at the DA.GetData lines...

I'm not sure why this is happening, and it is starting to drive me crazy!

Does anyone know what may have happened?

Views: 1338

Replies to This Discussion

Not sure what happened, but it is now working okay... (nothing has changed)...

I'm not sure entirely how GH stores the input and output parameters, but I am guessing it doesn't like when there is more than one input variable with the same name...

My best guess is that it wouldn't let go of my variable definitions even after restarting Rhino... Or perhaps another instance using the same component was conflicting...

The "An item with the same key has already been added" exception pertains to dictionaries. Parameters are stored in lists and GH doesn't typically care what you name them. They are accessed by index. If you access them by name, then GH will iterate over the parameters until it finds one with a matching name. If you have multiple parameters with the same name, it'll just retrieve the first one that matches. I always recommend using indices in the GetDataXXXX() methods rather than names, it's a more precise way to access the parameters.

I can't find any dictionaries used in the code for GetDataList, but I may have missed something. Can you upload a GHA which is causing this exception?

--

David Rutten

david@mcneel.com

This is probably the case. I have been using Dictionaries in my code, but the exception was being thrown at the DA.GetDataList definition before any Dictionaries are defined.

Fortunately, this exception is no longer occurring (inexplicably). I will let you know if it happens again...

Thank you for your response, I know better where to aim my troubleshooting if it occurs again.

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