Metahopper Find Objects by assemblies, calculation time of each component

Hello everyone and especially @andheum (if I’m not mistaken, I hope)

I’m looking to optimize my code with Metahooper
A very interesting option is to visualize my code on rhino (geometrically) and to define a colour for each component according to the .gha assembly.
Like This :


with this method :

I have several questions :slight_smile:

1 - How can I quickly find out for objects, if the object is native to grasshopper or if it is part of a 3rd assembly?
I tried to break down the assembly of the components for example, but I can’t find my values. And how can I find the type of assembly also for the parameters in this case?

2 - Is there another method to find all the 3rd assemblies present?
This method is not very easy to do automatically when you have a lot of plugins.
The method I use is this one:

PS: I also noticed that metahopper does not detect the butterfly plugin.

3 - How are the clusters treated? Can we know for each cluster what kind of objects are in it and also if there are non-native assemblies?
When I decompose with the “component info” I only find the input and output but not what is inside. is there another method?

4 - I reused the C# of this discussion to find the calculation time of each component, (very useful!) is there a way to enter a list of specific objects? I would like to estimate the computation time for each external plugins. or for a group

I was already using Metahopper a bit, but I’m trying to exploit it as much as possible, and I’m really impressed by the possibilities

Thanks again !

Are you on a mac by chance? I think the assemblies / document info component doesn’t work on mac.

I was about to suggest this that seems to work :

All 3rd party components / All components sorted per 3rd party assembly.

I think most of what you want to do is possible with scripting. It may not be possible without a lot of work with metahopper as it currently exists. Here are some useful examples:

// be sure to add `using System.Linq;` to the using region at the top. 
// Get all assemblies for all active objects in the document
A = GrasshopperDocument.ActiveObjects().Select(o => o.GetType().Assembly);

Here’s the code in metahopper which finds only third party assemblies:

using System.Linq;
using System.Reflection;
using System.IO;
...
private void Runscript() {
Assembly ghAssembly = Assembly.GetAssembly(typeof(GH_Component));
var GrasshopperAssemblyPath = Path.GetDirectoryName(new Uri(ghAssembly.Location).LocalPath) + @"\Components\";

if(!Directory.Exists(GrasshopperAssemblyPath)) { // on mac they won't be in the components folder, they'll just be direct in the .rhp
    GrasshopperAssemblyPath = Path.GetDirectoryName(new Uri(ghAssembly.Location).LocalPath);
}

var nativeGHAs = Directory.EnumerateFiles(GrasshopperAssemblyPath, "*.GHA");
var nativeAssemblies = nativeGHAs.Select(g => Assembly.ReflectionOnlyLoadFrom(g));
nativeAssemblies = nativeAssemblies.Union(new List<Assembly>() { ghAssembly });
var Assemblies = GrasshopperDocument.ActiveObjects().Select(c => Assembly.GetAssembly(c.GetType())).Distinct().ToList().Where(a => !nativeAssemblies.Select(na => na.FullName).Contains(a.FullName));
A = Assemblies;
}

I don’t know about the butterfly plug-in. it’s probably made of user objects / clusters / python scripts or something, rather than being a real GHA. There’s no way to figure out which “plug in” a python script comes from.

It’s possible to inspect the innards of clusters.
If you pass a reference to a cluster to this script as x, you can get at the objects inside:

    var cluster = x as Grasshopper.Kernel.Special.GH_Cluster;
    var clusterDoc = cluster.Document(null); // assuming it's not password protected
    A = clusterDoc.ActiveObjects();

and then process those objects with metahopper thru other means.

Here’s a modified version of the runtime script which lets you pass in metahopper-style object references:
(make sure the input is called “objects” and is a list):

   var activeObjects = objects.OfType<IGH_ActiveObject>();
    Seconds = activeObjects.Select(o => o.ProcessorTime.Ticks / 10000000.0);
    Components = activeObjects;

Examples using those scripts here:
examples.gh (10.0 KB)

2 Likes

Thank you very much @magicteddy and @andheum for your replies

@andheum i’m on Windows not Mac :slight_smile:

Very useful little programs

I confirm for the Butterfly objects subject, that they are recognized as GhPython object.

But surprisingly not all Metahooper objects are recognized via the DocInfo box.
See below and attached a test :

The grey boxes represent the objects found by DocInfo, we see that several Metahopper boxes are not recognised. And on the one that is well recognised, the assamblies is not indicated as 3rd parties

Regarding the recognition of 3rd parties, your box works very well, it finds Metahooper :

If I try the Components runtime box, I also find the Metahopper components (the box is red because I guess I have parameters too and not only components) :



You can see that all the boxes are greyed out and therefore recognized, including the Metahopper box

Problem solved, although I don’t understand why I can’t find all the boxes with DocInfo

Thanks for the computation time boxes, it works very well.

I think that knowing the calculation time of each box or each group, we would not be far from being able to make a progress bar of the calculation?
(This would only work on a program that has already solved to know the calculation time)
I know it’s a bit of a holy grail on Grasshopper :slight_smile:

I would try to find out the sum of the calculation times of all previous inputs for each box. This would allow to analyse the whole computation process for each element of the canvas :

  • But it might be a little complicated :wink:

Regards
test.gh (31.3 KB)