Saving all instance variables of an object
-
@abakobo said:
Why must I use @ or $ for my obj2?
[These prefixes are part of the names of variables. They tell Ruby what scope the variables belong to (@ for attributes of objects, $ for globals - there is also @@ for class variables). Variables without one of these leading characters are local to the code scope where they appear.
-
@slbaumgartner said:
They tell Ruby what scope the variables belong to (@ for attributes of objects, $ for globals
And for the record - global variables should be avoided. In Extension Warehouse they are an immediate rejection.
-
@thomthom said:
And for the record - global variables should be avoided. In Extension Warehouse they are an immediate rejection.
And yet.. the global objectspace is still cluttered with global variables created by SketchUp Team extensions!
Many of these are for
LanguageHandler
instances that are no longer needed once the Preferences UI strings have been loaded, or a local extension hash loaded with strings. -
Yea - there's a need for a cleanup for the old SketchUp extensions.
-
I tried to save an object containing an SKUI window object (using marshal) and had a bad type error... I suppose it's not possible to save an SKUI window with marshal due to it's limitations:
*Marshal can't dump following objects:
anonymous Class/Module. objects which related to its system (ex: Dir, File::Stat, IO, File, Socket and so on) an instance of MatchData, Data, Method, UnboundMethod, Proc, Thread, ThreadGroup, Continuation objects which defines singleton methods*
I did it manualy this time but wonder if there's something similar to Marshal with what I would be able to save objects containing SKUI windows for later use.
I remeber i saw somthing with a name looking like "yalm"..
Would Pstore do it?Many Thanks
ako
-
Classes needs to implement support for marshalling. In the case of SKUI the Window class holds on to references to UI::WebDialog - which cannot be serialized. This also is also the case for Sketchup::Entity derived classes.
Btw, why are you trying to marshall a SKUI Window? Are you trying to save the window position?
Or are you trying to save the whole state of it - including HTML content and session? -
I'm trying to save all the .visible? .caption(for lbls) and .value(for inputs) for now.
I would like to create a window where there's a "add item" on the window that add a SKUI_group on the window corresponding to the new item...
My object have only two instance variables for now, the number of items(an int) and the SKUI window.For the non customisable plugin I could save the .visible? .caption and .value by listing them manualy in my Save method but with a customizable window it would probably be painful...
thanks for your answers
AND THANKS A LOT FOR SKUI (sorry for shouting but i really mean it)P.S. I noticed a little bug: I have to initialise myself the .visible of each visible unmodified SKUI items before saving them because it was returning nil with the .visible? method if .visible= was never used.
-
@abakobo said:
P.S. I noticed a little bug: I have to initialise myself the .visible of each visible unmodified SKUI items before saving them because it was returning nil with the .visible? method if .visible= was never used.
Hmm... Could you file this bug in the GitHub repo with a small code snippet?
-
I never did that but will learn how to.
Glad to participate... -
Bug posted in the GitHub Issues field!
Advertisement