Grasshopper Model Block Instance not listing all instances

Hello!
I apologize if I’m missing something obvious (I really hope so) but I’ve been trying to figure out if how to use the new Grasshopper Block components to access the block instances in a model that use a particular block definition.

I know I can use the Query Model Objects to select block instances in a model by Name, Layer, etc., but it doesn’t take a Block Definition input. I would like to feed in a block definition, and get all the block instances (including nested block instances) that reference that block definition.

I tried the Model Block Instance component, but of course that wants to create new block instances rather than query the existing.

Elefront’s Reference Block by Name can’t find nested blocks.


Does anyone know of a good way to do this?

Edit: I tried the Query Model Object component and found a way to filter the result by Block Definition from this post, but that also doesn’t seem to be finding the nested blocks.

Block Instance count.3dm (331.4 KB)
Block Instance count.gh (17.4 KB)

Plugging a second Model Block Definition component into the one you already have in your file shows the nested instances. The result is the same as when you use the Explode component.

1 Like

Thanks, Martin! I will try that as soon as I get a chance. If I’m understanding how this works its not recursive, so I will need to plug in a Model Block Definition component for each nested layer (if I have nested blocks within nested blocks).

You can use the Filter Content to filter block instances by block definition name. As you said, this only works for top-level names, so you do have to do some tricks to drill down into nested blocks. But something like this should work I think.


FilterBlockInstances.gh (16.5 KB)

1 Like

Thank you! I can certainly make that work. Something like this seems to give me what I am looking for.

Another question, is there a way to to tell if a block instance has been mirrored or scaled?


It looks like attaching a plane to the block instance component gives me translation and rotation.

The Block Instance component will return a transform which will tell you everything you need to know about it’s scaling, translation, rotation, etc. Let’s look at an example (see below).

As a precursor, you might want to review some information about matrices and how they work.

Looking at the 4x4 matrix of values from the Original block, you can see that there are a series of values (1.0) starting in column 0, row 0 and working diagonally down to the bottom right of the matrix. All other values are set to 0.0. This is called an Identity Matrix and essentially means that it does nothing. There’s no scaling, rotation, or translation being applied to this block.

Now, let’s look at the Rotated block matrix. The last column has some large numbers (ie. 1525.84, -3164,74, etc.). The first three values in this column represent the translation values in X, Y, and Z. So, we know that this block has been moved 1525.84 units in the X-axis and -3164.74 in the Y-axis. Now, I know that I happened to have rotated this block 90 degrees counter clockwise about the z-axis. For rotation about the Z-axis, the matrix values that we care about look like this:

┌                                 ┐ 
|  cos(⍺) -sin(⍺)    0       0    |
|  sin(⍺)  cos(⍺)    0       0    |
|    0       0       1       0    |
|    0       0       0       1    |
└                                 ┘

The cos(90) = 0.0 and the sin(90) = 1.0… so you can see that this fits for that pattern in the upper left hand corner of values for this matrix. Everything else remains the same as the identity matrix which means nothing else has changed. So, by reading this matrix, we can tell it’s been translated in the X and Y axis and rotated 90 degrees counter clockwise.

Now, let’s look at the Mirrored block instance matrix. Again, looking at the last column tells us that this block has also been translated along the X and Y axis. Now, I happen to know that I mirrored this block against the XZ plane. A reflection matrix that represents this would look like this:

┌                                 ┐ 
|    1       0       0       0    |
|    0      -1       0       0    |
|    0       0       1       0    |
|    0       0       0       1    |
└                                 ┘

In other words, The X and Z values stay the same but the Y values are mirrored (ie. -1). Looking at our matrix, you can see that it follows this exact pattern. If we had mirrored the block about the XY axis, then the third value in the third row and column would be -1 and the second value in the second row and column would go back to +1.

Anyway, learning how to read/manipulate matrices can be very useful. There are lots of online documents about how these can be composed/applied to transform geometry. I’ve really only scratched the surface.

2 Likes

Wow, thank you! Sounds like I’ve got some reading to do.