algorithmic modeling for Rhino
Hi,
I have defined a data type (class) and made an instance of it and passed the instance to another GH component. I copy the class definition to the other component as well but it fails to recognize it as the same type. It refers to a different type definition apparently.
Error:
error: [A]MassPix cannot be cast to [B]MassPix. Type A originates from '7ea7fec0-99c5-49a8-ae80-af752ac2be94, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\pnourian\AppData\Local\Temp\7ea7fec0-99c5-49a8-ae80-af752ac2be94.dll'. Type B originates from 'fd0b2126-e10f-49de-9fc9-5504405d4135, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' in the context 'LoadFrom' at location 'C:\Users\pnourian\AppData\Local\Temp\fd0b2126-e10f-49de-9fc9-5504405d4135.dll'. (line: 82)
This is the case:
in component A:
Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
Dim kjh As New MassPix(2.1, 2.3, 4, 5)
A = kjh
End Sub
'<Custom additional code>
Public Class MassPix
Private x As Double
Private y As Double
Private S As Integer
Private K As Integer
Sub New(xu As Double, yv As Double, SZ As Integer, KL As Integer)
x = Xu
y = yv
s = Sz
k = Kl
End Sub
End Class
'</Custom additional code>
End Class
and in component B:
Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
Dim ABC As MassPix = CType(x, MassPix)
End Sub
'<Custom additional code>
Public Class MassPix
Private x As Double
Private y As Double
Private S As Integer
Private K As Integer
Sub New(xu As Double, yv As Double, SZ As Integer, KL As Integer)
x = Xu
y = yv
s = Sz
k = Kl
End Sub
End Class
'</Custom additional code>
End Class
the file is attached
ANY HELP IS VERY MUCH APPRECIATED!
Tags:
Hi David,
Thanks for your clear response. I have now a GHA built, without errors in Visual Studio, but it gives me the following error in GH: 1. Solution exception:Unable to cast object of type 'Grasshopper.Kernel.Types.GH_ObjectWrapper' to type 'Raster3D.Raster3D'.
My type (class) is called Raster3D
I have tried using a GH_ObjectWrapper and casting its value to a variable of my type and also getting it in as an object. It fails to cast both ways. I have put the class definition as a separate class in my GHA definition and it works fine in VS, as both components have access to it. It just fails in GH. Maybe I am missing something about GH_ObjectWrapper?
I just succeeded in doing it by producing a dll added as a reference for two scripted component; the problem is the same thing fails when I make a GHA and bring the dll with it to the grasshopper components folder.
If you only want to pass the data (some members around), you can use anonymous types in .net, see http://msdn.microsoft.com/en-us/library/bb384767.aspx
In your case:
A = New With {Key.x = 2.1, .y = 2.3, .s = 4, .k = 5}
Here with an example
Thank you very much Arend. I finally solved it by making a dll. But this is indeed a nice solution! :)
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
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by