speckleworks/SpeckleRhino

Cannot attach Custom User Data to Speckle Objects.

Closed this issue · 4 comments

Step 0:

Expected Behaviour

Creating custom user data, then adding that to a Speckle Object should not give an error.

Actual Behaviour

The Create Custom User Data component is producing an ArchivableDictionary, and the Set User Data Speckle Object is trying to cast it to Dictionary.

Affected Projects

I believe that this is limited to GH.

Reproduction Steps & System Config (win, osx, web, etc.)

image

Proposed Solution (if any)

Perhaps this can be fixed by casting to IDictionary instead of Dictionary here:

var dict = ((GH_ObjectWrapper)dictObject).Value as Dictionary<string,object>;
.

(It appears that this behaviour was changed in 9896f02).

The workaround is to attach data to object before converting them to Speckle Objects.

btw, I am hoping to have a colleague give the GH client some love shortly. I am flagging this here to see if this is a big issue for anyone else.

Thanks @daviddekoning ,

This will be greatly improved in 2.0. In the meantime you can use the normal "Set User Data" component. And please make sure your colleague joins the insider program so we can coordinate re GH client development :)

image

The fundamental issue here is the mismatch between this line:

var props = new ArchivableDictionary();

and this line:

var dict = ((GH_ObjectWrapper)dictObject).Value as Dictionary<string,object>;

There are three possible solutions:

  1. Make CreateUserData output a Dictionary
  2. Make SetUserDataSpeckleObject accept an ArchivableDictionary and convert it to a Dictionary
  3. Update the base SpeckleObject class so that it's properties property is an IDictionary.

1 and 3 touch have a higher chance of a affecting other items.

@psarras any thoughts?

This is fixed in #311.

I followed a slightly modified version of item 2 above. Instead of only accepting an ArchivableDictionary, the component now accepts any class that implements the IDictionary interface, and converts it to a Dictionary.

In addition, if the SpeckleObject to which the data is being attached already has custom user data, the component now adds the new data, instead of throwing out all the old properties and replacing them by the new ones. If a user data key exists in the both the old and the new user data, the new data overrights the old (on a key by key basis).