I just had to update this old example because it violated so many best practices.
(And I got tired of waiting for someone else to do it.) What does it do ?
In a Nutshell …
From the file header of the example script:
This code example allows you to have Dynamic Components
that modify themselves based on a Scene Change.They need to have at the top level the following attributes
“scene_change” a boolean value that if true force the DC to react
to scene changes and if false has the DC ignore the scene change
and “scene_trigger” which is the index that is incremented every
time there is a scene change and it is used to change attributes
for the DC.```
Author: Simone Nicolo - 2008 - v 1.0.0
What’s New in v 2.0.0
scenes_v2.rb (7.5 KB) NEW
Updated: Dan Rathbun - 2015 - v 2.0.0
- Module wrapped.
- initialize attaches the observer & records the observer id number.
- Constants are correctly defined in the class, not global!
- grep(Sketchup::ComponentInstance) used instead of typename==‘string’.
- return if’s used to short-circuit and reduce nesting levels.
- next if’s used to increment loop and reduce nesting levels.
- menu toggle added at bottom of View menu.
- pause() & restart() methods added to support toggling.
- MAX constant for changing scene trigger limit.
- simplified scene trigger increment code to Range inclusion test.
:
The old example had been posted here since 2008:
Dynamic Components that react to scene (aka page) changes
For comparison, here is the old version (with only the copyright holder changed to Trimble.)
scenes_v1.rb (3.8 KB) OLD
On the old blog webpage, the comments were not wrapped correctly, nor were the statements indented. So that was cleaned up as well: