Saving the state of an extension


Heyo Devs,

I’m quite new to sketchup extension programming (and ruby as well) so please excuse me, if the answer to my question is obvious… but I think it’s not. The search didn’t help either.

I implemented an extension in oop style. Is there a way to attach my custom objects (and their states) as attributes to the sketchup-model so it gets saved within the .skp file? What possibilities do I have to save anything within the skp? In my case, my objects for example hold lists of faces, so after saving and loading the model, this list should still work. Any ideas before I start hacking a workaround solution?

Thanks in advance + Cheers,



The answer is in your question :slight_smile: Put your data into the model attributes.


Haha I didn’t expect that to work, so I didn’t even try. I supposed only built in classes would work with that… Got to try that :wink:


Well, you can’t attach everything, but almost. Take a look at this :


Hum according to your posted link exacly what I’d need, e.g. a list of entities (faces) is not possible :frowning:


Well, you can attach stuff to the faces themselves.

What is it exactly you’re trying to do?


Only group and component instances can have permanent GUIDs.

If your faces are not grouped, then you must assign some kind of id attribute into a dictionary, and rebuild your lists after the model is re-opened. Actually just the presence of a certain named dictionary is enough for collecting them. (You need to attach a custom Sketchup::AppObserver subclass that then triggers the rebuilding.)

mdl = Sketchup::active_model
ents = mdl.active_entities
all_faces = ents.grep(Sketchup::Face).find_all {|face|
  face.attribute_dictionary("soundglider") != nil

If you need to collect any nested faces, then you iterate the model’s DefinitionList collection, checking each Sketchup::ComponentDefinition instance’s entities collection, but only if the defintion’s instances collection has a size > 0. (Groups are a special kind of defintion, so they are also in the defintion list.)


Thank you very much, now I can imagine how I solve my saving problem. The hint with the AppObserver is very useful!