Grasshopper

algorithmic modeling for Rhino

how do I access a user defined VB object in Grasshopper under Rhino5

Sorry if this is redundant but I really did search the news group for the answer...

As per the Grasshopper SDK I have compiled the following code in Visual Studio 2010:

 

Imports Grasshopper.Kernel
Public Class MyFirstComponent
    Inherits GH_Component

    Public Sub New()
        MyBase.New("MyFirst", "MFC", "My first component", "Extra", "Simple")
    End Sub

    Protected Overrides Sub RegisterInputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_InputParamManager)
        pManager.Register_StringParam("String", "S", "String to reverse")
    End Sub

    Protected Overrides Sub RegisterOutputParams(ByVal pManager As Grasshopper.Kernel.GH_Component.GH_OutputParamManager)
        pManager.Register_StringParam("Reverse", "R", "Reversed string")
    End Sub

    Protected Overrides Sub SolveInstance(ByVal DA As Grasshopper.Kernel.IGH_DataAccess)
        'Declare a variable for the input String
        Dim data As String = Nothing

        'Use the DA object to retrieve the data inside the first input parameter.
        'If the retieval fails (for example if there is no data) we need to abort.
        If (Not DA.GetData(0, data)) Then Return

        'If the retrieved data is Nothing, we need to abort.
        'We're also going to abort on a zero-length String.
        If (data Is Nothing) Then Return
        If (data.Length = 0) Then Return

        'Convert the String to a character array.
        Dim chars As Char() = data.ToCharArray()

        'Reverse the array of character.
        Array.Reverse(chars)

        'Use the DA object to assign a new String to the first output parameter.
        DA.SetData(0, New String(chars))
    End Sub

    Public Overrides ReadOnly Property ComponentGuid() As System.Guid
        Get
            'Don't copy this GUID, make a new one
            Return New Guid("09579831-0ac0-45c6-b820-110754887f26")
        End Get
    End Property

End Class

 

 

This has created a .DLL file (..\My Documents\eb\ABB Projects\ClassLibrary3\ClassLibrary3\bin\Debug\ClassLibrary3.dll) and copied it to "C:\Program Files\Rhinoceros 5.0 WIP (64-bit)\Plug-ins\Grasshopper\ClassLibrary3.dll".

I then restarted Rhino.

My question is how do I access this object in Grasshopper under Rhino5?

 

Details:

Rhino5 WIP 1/26/2011

Grasshopper 12/10/2010 Build 0.8.0004 Work in Progress

Visual Studio 2010

Windows XP

 

 

Views: 638

Replies to This Discussion

Hi Eric,

 

first, you'll have to rename it from dll to gha. You can do this by hand or you can add a Post-Build Event in Visual Studio that takes this action.

 

Once you have a GHA, you need to tell Grasshopper to load that file, you can do this in two ways:

 

1) put the gha in the Windows Roaming AppData folder, should be something like this: C:\Users\[[UserName]]\AppData\Roaming\Grasshopper\Libraries. You can reach this folder via the Grasshopper File->Special Folder->Components Folder... menu item.

 

2) add an extra search path to the Grasshopper loading sequence. You can do this with the _GrasshopperDeveloperSettings command.

 

Every GHA file in any of the folders listed in that dialog will be loaded.

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

That did it!

Thanks.

 

ps. I'm using Windows XP and on this computer (with Rhino5 WIP) the path to Windows Roaming AppData folder is: C:\Documents and Settings\[[UserName]]\Application Data\Grasshopper\Libraries

Yeah these folders change with almost every version of Windows. I'm using Windows 7 now. But there are .NET framework methods that allow you to get the correct folder path on any machine you're running on.

 

ps. if you intend to debug this code, there's really only one scenario that makes sense. Which is to add a Post-Build event to your compiler to automatically rename the dll into gha and then point Grasshopper to your build directory. I personally also change the output folders of my plug-in project to be the same for DEBUG and RELEASE. I don't want to have two versions of my plugin on the disk, never knowing quite for sure which one Rhino is loading. 

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Gotcha!

Actually, as I understood it, this set up was supposed to save the DEBUG and RELEASE in the same spot for that very reason.  But it looks like the help was not written for Visual Studio 2010.

I'll get it eventually.

It's a crazy convoluted journey to get to the Build Events window but I did it!!!

 

fyi-turns out the info you gave me was in the help file, I just missed it somehow.

 

Thanks again.

Hey, I'm back on this project again and totally can't find the help file with the info on how to properly configure Visual Studio.  Could you point back in the right direction?

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