New snippets idea

Hi everyone, I created DefinitionLibrary to solve the problem of discoverability and easy re-use of your useful Grasshopper logic, with version history.

I’m looking into adding snippets to this and I’d love your thoughts on two options I have - scroll down to see them below - and any other options you can think of.

Some background first:
When you use it to publish a file or cluster, it stores a copy of the file, plus meta data that you specify in the cloud.
It inserts a link to that inside the file/cluster you’re using locally. If a new version of any published cluster is available, it offers you the ability to update your local copy to that new version - now or at a convenient time for you later (or never).

That meta data is crucial of course because it means that you can easily find, in the cloud library, that very helpful file or cluster you created last year - and you can import it again to re-use or further develop as a new version.

DefinitionLibrary sees files, clusters and Hops definitions as all the same thing:

  • a collection of interconnected GH components; in fact, the plug-in stores them all as .gh files in the cloud

It seems to me that snippets can also be treated this way. Whereas currently you can search for files or clusters, soon you’d be able to search for snippets to import onto your canvas, like this:
(note this screenshot has some SharePoint/OneDrive aspects which aren’t released yet)

Once you select & click import, it’ll be added to the currently-open file.

Now I come to the two options I’ve thought of so far for the actual mechanism for containing/associating the components into snippets: groups and sketch outlines.

Note that I do want to use standard parts of Grasshopper (no custom components) so that your work still functions if you uninstall DefinitionLibrary in the future.

Option 1: Groups - using standard Grasshopper groups as the container for a snippet
Mock-up:

When you go to Library → Publish, it will list ALL groups in the GH file (like it does for clusters/Hops now) and you can choose which one you’d like to publish as a snippet. This would mean you could publish multiple new snippets in one go, although the list of groups could be extremely long indeed.

After publishing, the group would have the standard DefinitionLibrary head-up display (name, version etc) appear above it like it does for clusters & Hops.
You can add components to this group or remove components like you would any other group and it would seem a natural conceptual fit to have groups used for snippets.

Since refactoring inside a group can be fiddly, I thought of an alternative, left-field idea:

Option 2: Sketch outlines - using a standard Grasshopper polyline on the canvas as the outline for a snippet
Mock-up:

Despite this option using polylines, which are added to the GH file using the Sketch tool, I would suggest that you wouldn’t need to draw the actual outlines - the plug-in could draw them for you around selected components through a menu action item.

This mechanism does mean you can only publish new snippets one at a time.

After publishing, the plug-in will draw the dashed line (which becomes part of the local file) and display the name & version head up display above the snippet outline.

Adding new components to this snippet would be as easy as positioning it inside the outline; DefinitionLibrary will recognise that as a change to the snippet - no need to explicitly add it to the snippet.

However, if there’s not enough room for this, I did have an idea in mind to offer new menu items that would have the plug-in automatically redraw the dashed outline to enclose the selected component(s):

What do you think?

It would be great to hear your thoughts, either here or in the DefinitionLibrary discussion forum: https://github.com/nicolaasburgers/definition-library-releases/discussions/37

Cheers - Nic

5 Likes

At least for importing the snippet, I would like to be able to create a group from it on adding to the canvas.

1 Like

Hi @richard.aubin, with option 1, it would naturally be a group anyway, but with option 2, you could create a group as part of the snippet so that when it’s imported, it’s in a group.

I’m quite curious though about why you’d like to create a group from it, and could you share how you imagine you’d use snippets?

I create re-usable snippets that I combine to create parts.

I may not always use the same combination of snippets.

Currently I drag and drop my snippets from the rhino Library panel which are saved as normal grasshopper definitions onto the GH canvas and select the group option.

This conveniently groups any dropped definitions/snippets and allows me to quickly grab and position the groups into place to continue working.

So I imagine being able to use snippets from your plugin in a similar fashion, where I can select multiple snippets, bring them in as groups and quickly position them onto the canvas at will. Ideally they would already be separated for easier identification, which the drag and drop method I show above doesn’t do (it stacks them).

1 Like

Ah yes, so it makes them easier to position in your new GH file if the multiple snippets you import are already groups.

That would be more natural if I implemented snippets using groups, although if the sketch outlines option was implemented, I could see if it’s possible for the plug-in detect movements of the sketch outlines and reposition the components so that they remain inside the outline in its new location.

The video was helpful and actually it reminds me that the Import window in the DefinitionLibrary UI should remain there after you import a cluster, not close immediately (as it does now) so that you can easly add multiple items to your canvas - so I’ll get onto that, thanks @richard.aubin
(This would likely be even more needed when you’re importing snippets.)

What about refactoring though - when you want to alter any of your snippets, how do you go about it?

  • Do you do it with the outer group in place (which means you have to select components one by one and not using the rectangular selection method)?
  • Or do you ungroup, refactor, then re-create the group again?

For refactoring, I would actually refactor the original document, not an imported snippet.

I use snippets when I would possibly change the internal logic to some degree for the current application, where I don’t want those changes to affect the original document. Think of copying and pasting some c# code, without the intention of reusing the new output elsewhere.

Otherwise, I use clusters/hops to ensure the logic remains consistent, in the same way I would create a c# class to be used as an object.

I’m not sure how to apply this to this plugin.

1 Like

I think both options would be an amazing addition to an already amazing solution.
Having the options to have iteration information about component-assemblies that don’t do well in clusters would be a real benefit.

Still i would prefer the group option because it would fit our understanding of best practice grasshopper layouts.

2 Likes

Love the direction this plugin is taking. Was considering developing something similar for internal use at our company but never got around to it.

I’m definitely team Groups.
From implementation perspective, the GH_Group already provides all the methods and user interface for adding and removing components and updating their position on canvas.

Using sketch objects feels like it would require you to inject a lot of functionality into something that was never supposed to be used that way.

Bonus idea:
Store all the DefinitionLibrary metadata about the snippet in the Description property of the GH_Group objects.
As far as I know it is never visible to the user, but it’s persisted per each Group instance on file save.

That way you can use it to store all the data that you would need to implement eg. automatic snippet version upgrades for already placed snippets while making sure that the metadata stays in the file as long as the Group is there. Even if the definition is opened and re-saved by someone who doesn’t have your plugin installed.

@ondrej Funny you mention the Description property: even before writing this, to even consider it an option, I needed to have found a property that isn’t visible to the user and that has a setter - which I found in GH_Group, so yes that is what I’ll use (the sketch object has such a property, too, by the way).
It’ll hold the info the plug-in needs to connect it to a definition in the library, which is what Revision entries do for files, clusters and Hops definitions.

I was actually quite certain that GH_Group objects would serve just fine as the container for snippets but then I thought how often I un-group then re-group components as part of refactoring.

Also, I regularly forget to explicitly add new components to groups, and I only notice this when I move the groups around and find some components are not moving with them - so I could see this being a problem when publishing or updating snippets. For the best usability, DefinitionLibrary would probably need to run a pre-publish check to ensure all components positioned within group boundaries are actually part of the group.

1 Like

As a tangent thought @ondrej: I tried to find such in invisible set-able property in canvas script objects (C# and python) but so far haven’t been able to find one.
I could add require the code in the script itself to hold certain static values but those would seem too easy to accidentally alter.

I’d love to be able to add scripts as peer objects in the library to definitions so feel free to share ideas on this if you have them.

An additional question for everyone: how valuable would you find the ability to nest snippets that are published to a common library?

Is this something you would commonly make use of if it were available, in the same way that you can currently nest published clusters and Hops definitions at the moment using DefinitionLibrary? Or is the nature of snippets such that you can’t imagine you or your team needing that?