Grasshopper

algorithmic modeling for Rhino

Hello,

I'm currently trying to update some custom components that allow grasshopper to send and receive data from my own plugin to work with version 0.7+.  In order to do this I need to be able to get the running instance of said plugin.

Looking at RhinoCommon, it would seem to have a function to do this: the 'RhinoApp.GetPlugInObject' method.  However, when trying to use this within my grasshopper component by name or GUID it always returns Nothing.

Am I likely doing something silly?  Is this method actually implemented in RC yet?  If so, will it work for older Rhino_DotNET plugins or would I need to rewrite that as well?  Is the object it is supposed to return the PlugIn itself or it's ObjectInterface?

Thanks in advance,

Paul

Views: 2160

Replies to This Discussion

Hi Paul,

It depends exactly what you're doing. You can use reflection to link into another dotNet Plug-in (including loading it into the active process if it's not already). Of you can simply reference the associated dll into your project.

It sounds (not really a surprise) that you're doing something similar to the Geometry Gym plug-ins, in which the Grasshopper components are really just satellite collectors and receivers of data from the main Rhino plug-in. I don't think Rhinocommon is the link you are looking for to connect to other dll's of your own.

Hope you can make sense of it (or maybe others will explain better than me).

Cheers,

Jon
Thanks Jon,

Yeah, reflection is how I did it in the old version, but I always considered that a bit of a hack and as I'm re-writing it to use RhinoCommon I was hoping to improve on it a bit. So I was hoping to be able to do something like:

linkObject = RhinoApp.GetPlugInObject("MyPluginName")

And then use linkObject to exchange data between grasshopper and my plugin. Only, linkObject always comes back Null. Obviously, I don't need RhinoCommon just to reference an assembly!

My real problem is that the RhinoCommon documentation just has "[Missing documentation for "M:Rhino.RhinoApp.GetPlugInObject(System.String)"]" where it should have actual documentation, so I'm not sure whether this is even supposed to work the way I want it to, whether it's not implemented yet or whether I'm just using it wrong.
Hi Paul,

It's still very early in Rhinocommon, so it wouldn't be a surprise if it wasn't implemented yet.

It sounds like it could very well provide the handle to your plug-in and allow access to COM visible commands (this is only an assumption by me) for use in Python etc.

Guess we'll have to wait for a response from someone in the know at McNeel.
Hi guys,
Every function in RhinoCommon should be functional. In other words, there aren't any stubbed out functions with a "todo" comment in them.

I just updated the comments for Rhino.RhinoApp.GetPlugInObject on http://www.rhino3d.com/5/rhinocommon/ You may have to refresh your browser window to see the new contents. This does sound like the function you are looking for. This function loads your plug-in and calls the "GetPlugInObjectInterface" on your Rhino_DotNet plug-in class. The result of GetPlugInObjectInterface is then returned.

I just tested this with a Rhino_DotNet based plug-in and a python script. The Rhino_DotNet plug-in returns a class in GetPlugInObjectInterface that has a "Print" function. Then, in a python script, I wrote

import Rhino
pio = Rhino.RhinoApp.GetPlugInObject("SteveCS_Samples")
pio.Print()

You should also be able to directly access this class in your VB or C# code.
Thanks Steve,

I've now looked into this a bit more and it does actually half-work. By setting a breakpoint in my plugin's GetPlugInObjectInterface() function I can see that it is in fact calling this function, which is returning my 'link' object.

However, for some reason that object never makes it to grasshopper. It's definitely returning an object from GetPlugInObjectInterface but in grasshopper it comes up as Nothing.

I tried just returning a string, and that did manage it. I think the problem is this: my 'link' object is my own custom object which is defined in a .dll which is referenced by both my plug-in and my grasshopper component. However when I use GetPlugInObject, this seems to be passing through something in RhinoCommon which is saying 'I don't know what the hell this is, get rid of it'. That's why this way doesn't work but doing something like (in the old SDK)

Dim SalPlugIn As MRhinoPlugIn = RhUtil.GetPlugInInstance(path)
Dim result As SAL_GrasshopperLink = SalPlugIn.GetPlugInObjectInterface(New System.Guid())

does, because it's accessing the plugin directly and both ends of the equation know what the object is.

So, what is the intended usage of the GetPlugInObject method, if you can't use your own objects? Have I totally misunderstood the intent? Will RhinoCommon include something which will let you access the plugin itself, so you can extract your PlugInObjectInterface yourself?
There shouldn't be any difference. Are you running this in a debugger? If so, put a breakpoint on the line that calls Rhino.RhinoApp.GetPlugInObject. Does the debugger show that the return object is actually "Nothing"?
Yup, that's what I did, so I'm pretty sure that's what is happening.

Don't worry about it too much for my sake, I've now figured out a sneaky way around it Though obviously if it is a bug it might be worth sorting out for the benefit of other people.
It would be nice to figure out what is going wrong since I don't want to make people rely on "sneaky workarounds". I would appreciate it if you could verify that you can
1. break on the line calling GetPlugInObject from your GH component
2. break in your plug-in function that returns an object
3. the return value from GetPlugInObject is Nothing (null)

Make sure that the line calling GetPlugInObject looks like

Dim obj As Object = Rhino.RhinoApp.GetPlugInObject("MyPlugIn")
If obj IsNot Nothing Then
Rhino.RhinoApp.WriteLine("I got something")
End If
Dim result As SAL_GrasshopperLink = obj

In other words, don't perform the cast on the same line that is calling GetPlugInObject. I want to make absolutely sure that the cast isn't the root of the problem.

Thanks.
If you have not done so already, submit this to the Rhino Plug-Ins Newsgroup. If it is not implemented, they can add it to the list.

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