A little problem of convert from goo


(Andrealu2012) #1


i have a custom class (which is “customcommand” and it inherits from"robotcmd"),all is witten in c#.
if i use a c# component ,as the picture show, it show a Error:

and i try to add a convert code:
it seems wrong…
so. can anyone help?
Thank you very much


Do you have a wrapper type derived from GH_Goo for your custom class? How do the CastTo / CastFrom methods look like?

(David Rutten) #3

As @dsonntag said, you need to provide CastFrom and CastTo methods rather than implicit convertors.

The SDK documentation I think provides an example of custom data types.

(Andrealu2012) #4

Thankyou @dsonntag @DavidRutten ,i read the document again,and works!
this is code:

(Andrealu2012) #5

@DavidRutten, @dsonntag ,i found another problem…
i make a c# script:(add a gha as DLL)
(CustomCommand is inherit from RobotCmd)

the same error appear again in this situation…so ,who know the reason,thank you!


Have you tried to deactivate the COFF byte arrays option in gh developer settings?

(Andrealu2012) #7

Amazing!Thankyou @dsonntag,why it works??just for curiosity…


I am also not well aware of the details but had the same thing with custom classes a while ago. If you debug it (by encapsulating the casting in a try/catch), it shows that it has to do something with the way the .dlls are loaded. I think one time the .dll is loaded directly from Grasshopper (in the parameter container) and the other time referenced when compiling the C# script. I guess the objects are then not recognized as being of the same type (as they technically come from different .dlls), thus the casting fails.

But I think @DavidRutten should be able to explain this better, I would also be interested :wink: