
Instead of doing homework today I spent most of the day hacking my way through a simple ruby script. Ruby on Rails is the scripting language adopted by Sketchup. There is lots of information available for Ruby, but I stuck to only the sketchup resources - they seemed more relevant.
What I wanted to do with this script was to find all of the entities in the file that had the same attribute. In this case I made the script even less elegant by taking advantage of the entity's definition name. All entities seem to have this parameter so I was able to take advantage of it y using sketchup's gui and then by extracting the name in the script - that is, no need to build my own dialog (maybe my next lesson - there are some interesting examples delivered with sketchup).
Essentially, what the script does is request all entities in the model and then enumerates through each. The entity definition name is compared to the string I want to find, in this case Display Panel and if a match is found increment the counter. When the script is done it returns a count of Display Panels and ignores entities with other definition names.
A second script is included in panel.rb. This is a simple request for the total number of entities in the model. This script is quites simple it simple uses the model.entities.count method to return the total. UI.message prints the result in both cases.
Panel.zip includes the test.skp file, and the ruby script panel.rb.