One click solution for internalising all cluster

Hello -

Does anyone know of , or have built something that can loop through a gh script to internalise all nested clusters? Additionally apply password to all of them.

This sounds like something you can sorta do from the top layer, but i think will fall apart when trying to do nested.

Any clues? @piac @ivelin.peychev @AndersDeleuran @andheum @DavidRutten

some clues from grasshopper3d:

Dim newID As Guid = Guid.NewGuid()
Dim record As New GH_UndoRecord(“Cluster Frabbing”)
For Each cluster As GH_Cluster In ClusterFamily()
record.AddAction(New GH_ClusterReferenceAction(cluster))
record.AddAction(New GH_ClusterDocumentIdAction(cluster))
cluster.DocumentId = newID
cluster.m_file.Path = Nothing
cluster.m_file.UpdateToCurrentFile()
Next
RecordUndoEvent(record)
Instances.InvalidateCanvas()

probably the only discussion available online here how to invoke "update" and "internalise" of a referenced cluster? - Grasshopper

ClusterFamily() returns all cluster? or just the top document ones?

Is it not enough to apply this to all (including nested) clusters?

Currently testing.

ClusterFamily are all the instances of the same cluster. So you should only need to internalize one. As far as nested clusters, this should be doable too — you can get the Document from a GH_Cluster and loop over its objects in the same way as the top level document.

Very interesting - and thank you for the advice. I am diving into these clusters today, lets see how it goes

@andheum @piac
Just wondering if you know the c# equivalent to:

cluster.m_file.Path = Nothing
cluster.m_file.UpdateToCurrentFile()

m_file is a private property, you’re not allowed to access it (except through reflection). What are you attempting to do exactly — internalize the cluster?

Try this, using Reflection: Internalize All Instances of Cluster.gh (10.0 KB)

This won’t do nested clusters, but maybe you can extrapolate from the code. I’m invoking the private method that is called when you select “Internalize” from the component menu.

I am pinging @DavidRutten for an opinion of how maintainable this method would be long-term, or if there are alternatives.

Ah beautiful, I examined all the functions available to GH_Cluster, doesnt seem to have ‘internalise’ , or those m_path functions, but i will reverse engineer this script!

Seems its using reflection in your script. That is black magic to me still. Its freaky code.

I wonder if its against the license agreement to post it here