Change all block geometry to color By Parent

I have a hundred or so block definitions in my file, each block containing somewhere between one and ten curves and points. I just realised that what I really want is to have the display colour of all those curves and points be ‘By Parent’ instead of ‘By Layer’. I can make the change manually by using BlockEdit on each block, selecting the geometry, changing the attributes and saving the block, but that’s a lot of tedious work.

Is there a command or button somewhere that allows me to set these properties en-masse?

1 Like

Hi David, hope this script works. If you already have instances in the file then you may have to re-insert these if I recall correctly. This could also be scripted.

Option Explicit

Sub SetBlockObjectsColorByParent()

  Dim arrBlocks, strBlock, arrObjects

  arrBlocks = Rhino.BlockNames(True)
  
  If IsArray(arrBlocks) Then
    For Each strBlock In arrBlocks
      arrObjects = Rhino.BlockObjects(strBlock)
      If IsArray(arrObjects) Then
        Call Rhino.ObjectColorSource (arrObjects, 3)
      End If
    Next
  End If

End Sub

SetBlockObjectsColorByParent()

Yeah we can program it, but that’s not an option for most users.
Anyway, I also had to move all block definition elements into a separate layer so they wouldn’t get hidden when I change regular layers. So I went with a slightly adapted version of the above script.

Option Explicit

Call SetBlockObjectsColorByParent()
Sub SetBlockObjectsColorByParent()
  Dim blockNames
  blockNames = Rhino.BlockNames(True)
  If (Not IsArray(blockNames)) Then
    Exit Sub
  End If

  Dim blockName
  For Each blockName In blockNames
    Dim blockObjects
    blockObjects = Rhino.BlockObjects(blockName)
    If IsArray(blockObjects) Then
      Call Rhino.ObjectColorSource(blockObjects, 3)
      Call Rhino.ObjectLayer(blockObjects, "Block Elements")
    End If
  Next
End Sub

I don’t think that there is a good “hard-coded” solution for all the properties the users may want to change. Like in your case… also changing the Layer. It is possible to change all properties manually which works for “most users”. If a user has to deal with more blocks than one can handle manually then it is time for a bit of scripting :wink:

Please where do i put this? Is it rhino or python script?

It was Rhino script … SOLVED

I have noticed that running this script and having objects color within block set to by parent drastically reduced FPS.

When everything is set by layer it is fast


After running script and when colors are taken from instances layer color performance drops very much

Why is that?

Hi Ivan -

I suppose there is a bit more overhead since the objects are no longer completely identical.
In a quick test here, with 5760 instances of the same block definition (amounting to 29ᅠ007ᅠ360 quadrilateral polygons and 46ᅠ368ᅠ000 triangular polygons), I get 19.57 FPS when the color of the object in the definition is “By Layer” and 19.33 FPS when it’s “By Parent”.

-wim

please try with my real life examples
test by layer.3dm (1.3 MB)
test by parent.3dm (1.4 MB)

here it is super significant. like 20 and 5 fps.

Hi Ivan -

I get 1.13 FPS with your “test by parent.3dm” file, so, yes, something is going on with that one.
When I start a new document from the “Small Objects - Meters.3dm”, however, and import that file, I get 60.39 FPS.

Also, I can’t reproduce how you got to that state. I opened “test by layer.3dm” and ran that script but am not having issues with the display:

2022-12-16 ByParent-FPS

-wim

this is very strange. but at least we know rhino can handle that but somehow the file itself gets broken causing the slowdown. will you look into that deeper? i think this will ne some silly issue.