Grasshopper

algorithmic modeling for Rhino

How to address classes functions methods from external dll's

Found the way to make plug-ins with VB.net for Rhino. It refuses incorporated external dll's though with the remark that the Rhino version is not set or somthing like that. But besides that how do I address in the VB component of Grasshopper this plug-in? I guess I have to get it in the imports? E.g. if I follow the example to make MyPlugIn1 it returns "The MyPlugIn1 command is under construction" in the Rhino command-line. How do I get this done in the VB component of Grasshopper?

Views: 1128

Reply to This

Replies to This Discussion

Hi Hans,

only Rhino itself is allowed to run code inside MRhinoCommand classes. Anything you put inside the RunCommand() function is off limits for all external access.

You need to put your algorithms into separate classes and methods, which can be instantiated and called by the code inside a VB component.

The steps required are:

- Add a reference to the VB component. At the moment you can only reference dll files, so be sure to compile your plugin to a dll instead of rhp (I can add other extensions easily if this is called for).

- The namespaces inside that library should now automatically be added the the Imports section of the VB Componentn code editor (this section is collapsed by default, way at the top).

- Now you should be able to access classes and methods in that dll.

Be sure to get the latest Grasshopper beta (0.6.0055, from december 31st), as it fixes a problem with loading remote dlls.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
In the menu of the VB component, click on Referenced Assemblies... and add a dll file to the list.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Hi Hans,

do you want to expire the current Grasshopper solution based on an external event? I mean, if someone presses a button on a Form which is declared inside a DLL you are referencing from within a VB component, do you want Grasshopper to respond to that?

If this is the case, you'll have to handle events that are raised by the remote assembly. I'll post an example project and client ghx file here that does exactly this.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
EventsExampleProject.zip contains a complete VB class library which has exactly one Form defined. This form contains two buttons and a TextBox, and it adds 3 events to the default list:

Button1Pressed
Button2Pressed
TextContentChanged


Then, the ghx file has a VB component which references this dll (you'll have to fix the reference path). Inside the VB code, there is a Shared, class-level variable called m_form which will contain the currently active instance of that window. It is Shared so that it remains alive between different runs of the script.

The code inside the RunScript method does 3 things:

1) If the form has been defined in the past (i.e., it is not Nothing), but it is no longer visible, we assume it has been closed and we detach ourselves from this form.

2) If the form variable is Nothing, we create a new form, we make ourselves aware of the three events and we display the form on the screen.

3) We read the contents of the TextBox and apply that String to the [A] output.

Now, there are three more subroutines in this script, all of which are event handlers. Whenever something happens on the form, these functions will get called. One of these functions displays a message box, another one writes something to the Rhino command line and the third one expires the VB Component, which causes the Grasshopper solution to be recomputed.



This is not exactly trivial stuff. And to get it just right (it still feels pretty clunky) I'd have to invest about two days writing more GUI code.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Attachments:
Hi Hans,

I noticed this too. No idea what the problem is yet. It is me who is supposed to look at the LoaderExceptions I think.

--
David Rutten
david@mcneel.com
Poprad, Slovakia
Sorry to jump in here but:
I can't seem to reference an assembly by the method described by David above.
I'm trying to reference Microsoft.Office.Interop.Excel. The dialogue box does not respond to 'Open' or double-clicking, though it is visible as a *.dll.
.gha's do seem to work.
Am I missing something?
Working with version 060059

Thanks!
Daniel:

I had the same problem. When you open the c:\windows\assembly folder, a shell extension is used to display the assemblies (instead of windows explorer displaying the actual files). This issue, and how to get around it, are addressed here.

I used Option 3 and was then able to locate and referenced the Excel .dll from Grasshopper.

Hope this helps.
Though it said Unable to load one or more of the requested types,the VB component worked very well.
A window with two buttons appeard.
Hi, I keep receiving "Unable to load one or more of the requested types" in the C# GH component, when i try to load a external .dll file in the current built grasshopper.. but the previous old version GH can take the same dll file.. can anyone give a hand for this? many thanks..

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

© 2019   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service