Block Instance to Model Block Instance in C#

When a block instance in Rhino is referenced in a GH component it results in a Referenced Block Instance, but when this is passed through any of the components treating Rhino Objects it is converted into a Model Block Instance. I’ve tried to access blocks in C#, but I could not find a way to convert a Referenced Block Instance (which points me to the Block definition, not the instance itself) into a Model Block Instance, without going through one of the other components (see picture below). I need to access the Model Block Instance to have also access to its geometries and associated User Text.
Another thing I need this for is to access nested blocks and their associated User Text in C#; of course, if someone already knows a way to do this and is inclined to share I’d be very grateful.

This is only a tentative approach as I could not find a suitable example. Here attached is a basic example to play with.

Block-ModelBlock.3dm (118.0 KB)
Block-ModelBlock.gh (29.4 KB)

Yes, that is a Reference block instance to start with. Then needs to be converted to a Model Object before using all the tools on it.

Geometry and Usertext can be accessed through the Model Object.

So would an example of walking into a Nested block and finding the user text and geometry of the Model object be helpful?

I do not see usertext in the example file. Am I missing it on a certain level?

Outside of C# I use Explode Recursive to find this info:

Maybe I need to work on my wording, but what I would like to know is precisely how to convert a Reference Block into a Model Block in C# in order to access its Geometry and User Text for nested blocks as well (and do all of this in C#). I know how to do this with standard components, but I want to do that in C#.

Yes, in the example Rhino file I attached there was no User Text associated to the block. Here’s an updated version with User Text associated.

Block-ModelBlock.3dm (122.4 KB)

@scottd any news on this front? It’s been 10 days…

Hi @ale2x72,

Something like this should give you access to the Objects inside the instance definition and its user-text.

We are working on adding Model Object as a type hint into scripting components but by now you have to cast explicitly before.

1 Like

Thank you @kike , that should do.

For others interested in this topic: for the script above to work one must include using Grasshopper.Rhinoceros.Model; in the usings region.