Can one access plug-ins through scripting and use their properties and methods?

Hello,
I would like to use RhinoPolyhedra in my script to create QuickHulls, providing the points directly from the script. Is there any way to do that?

PS: no idea if this is relevant, but when I try to get the plugin’s GUID (Rhino.PlugIns.PlugIn.IdFromPath) I get this: {0}
0. 00000000-0000-0000-0000-000000000000

For native GH components I know it is totally possible, but not quite sure for custom plugins.

If it’s possible you need to add the plugin .gha file as a reference to the C# script, and try to access the class of the component you want to use. The class will give methods to instantiate the components, set inputs and retrieve outputs.

This reference can help: Is it possible to call the functions of a Grasshopper component from inside a (C#/VB.Net/Python) script? - Grasshopper

1 Like

Hi @ucbqeor,

Something like this:

import scriptcontext as sc
import Rhino
import ghpythonlib.components as ghcomp

def test_quickhull():
    filter = Rhino.DocObjects.ObjectType.Point
    rc, objrefs = Rhino.Input.RhinoGet.GetMultipleObjects("Select points", False, filter)
    if rc != Rhino.Commands.Result.Success: 
        return
    
    in_points = []
    for objref in objrefs:
        in_points.append(objref.Point())
    
    out_curves = ghcomp.GhPolyhedra.QuickHull(in_points)
    if out_curves:
        for curve in out_curves:
            sc.doc.Objects.AddCurve(curve)
    
    sc.doc.Views.Redraw()
    
if __name__=="__main__":
    test_quickhull()

– Dale

1 Like

Thank you! Would it be easy to have that in C#?

What I did was go to manage assemblies and Add PolyhedraCommon.dll then I can use PolyhedraCommon.Something.
However I also have a GhPolyhedra.gha file which I added to the components library. However when I try to do GhPolyhedra.Something I can’t.

Not sure if this make sense, but if it does, how do I go about it?

1 Like

Hi @ucbqeor,

Here is an example:

Use plug-in command Api in c#

– Dale

1 Like

Thank you!

1 Like

Is the logic of the quick hull algorithm here the same as the one stated in Quickhull Algorithm for Convex Hull - GeeksforGeeks where
The QuickHull algorithm is a Divide and Conquer algorithm similar to QuickSort. Let a[0…n-1] be the input array of points. Following are the steps for finding the convex hull of these points.

1. Find the point with minimum x-coordinate lets say, min_x and similarly the point with maximum x-coordinate, max_x.
2. Make a line joining these two points, say L . This line will divide the whole set into two parts. Take both the parts one by one and proceed further.
3. For a part, find the point P with maximum distance from the line L. P forms a triangle with the points min_x, max_x. It is clear that the points residing inside this triangle can never be the part of convex hull.
4. The above step divides the problem into two sub-problems (solved recursively). Now the line joining the points P and min_x and the line joining the points P and max_x are new lines and the points residing outside the triangle is the set of points. Repeat point no. 3 till there no point left with the line. Add the end points of this point to the convex hull.
@dale

Hi @ucbqeor,

The article you reference is for performing a “quickhull” calculation on 2d points.

– Dale

1 Like

Oh, sorry about that, I don’t know how I missed it :scream: I’ll read some more and ask again.
Thank you :]