Grasshopper

algorithmic modeling for Rhino

transfer custom objects and access them in another VB component

Good morning everyone,
again one little question regarding grasshopper vb scripting.
is it possible to transfer custom Classes to another VB script component input
and access the Methods and functions? do i have to implent it in the rma.opennurbs?
Is it possible to have a custom declaration region for alls vb scripts?

with best regards

Michael Sprinzl

ok i solved the problem....
to build your own custom objects which can be communicating between different VB components:


1. build a classlibary in vb.net like this:

Public Class FEM_element
' Fields
Public Material As Integer
Public Element_nummer As Integer
'Methods
Public Sub New(ByVal i_Material As Integer, ByVal i_Element_nummer As Integer)
Material = i_Material
Element_nummer = i_Element_nummer
End Sub

and save it to the Grasshopperplugin folder!!! as xxx.dll dammm it took me 2 hours to find out.

2. Put 2 VB components on the Grasshopper gui
and attach the xxx.dll with the Referenced Assemblies tool

3. vb component 1:

Dim aa As New FEM_element
aa.Element_nummer = 1122
aa.Material = 12
a = aa
End Sub

vb component 2:

Dim aa As New FEM_element
aa = x
print(aa.Element_nummer)
print (aa.Material)

4. finito bandito .... you now have your own custom type connections ....lol

Views: 940

Replies to This Discussion

Hi Michael,

I have been trying to transfer custom classes between components as well and will try your method. However where is this "Referenced Assemblies tool" in grasshopper? In the vb node, isn't the imports section blocked out?
yes it is blocked out... but by using the assembly linker its somehow importing the new class defined in the *.dll. Within visual basic you can also use:

Imports RMA.OpenNURBS
Imports RMA.Rhino

Imports Grasshopper
Imports Grasshopper.Kernel.Data
Imports Grasshopper.Kernel.Types

Do not ask me about system.reflection David is handling. But it works and thats the good think about it. In this example I use lokale_knoten As List(Of Object) which is actually the FEM_element Class linked from one VB script to another VB script.

Sub RunScript(ByVal lokale_knoten As List(Of Object))

Dim FEM_Elemente As New list (Of FEM_element)
Dim punkte_x As New List (Of Double)
Dim punkte_y As New List (Of Double)
Dim punkte_z As New List (Of Double)
Dim Punkte_roh As New List(Of on3dpoint)
Dim Zaehler As Integer
Dim Zaehler_2 As Integer

For Each ctl As Object In lokale_knoten
'alle FEM elemente in einer Liste
FEM_Elemente.add(ctl)
For Each item As Double In ctl._x
punkte_x.Add(item)
Next item
For Each item As Double In ctl._y
punkte_y.Add(item)
Next item
For Each item As Double In ctl._z
punkte_z.Add(item)
Next item
Next ctl

I think the direct access of the self defined class is not working. Or maybe I do not know how to access parameters and functions within.So i Parse it to an new Object of the class.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service