Help with acess to registry from observer
-
Sketchup.read_defaultfails to access the registry with the following code, and returns nil although I have verified that there is a value inv_name. Anyone care to discuss?class AtelierModelObserver<Sketchup;;ModelObserver def onSaveModel(model) result=Sketchup.read_default("label","v_name","default") if result==nil #undocumented PC only exit command. Sketchup.send_action 57602 end end end -
result=Sketchup.read_default("label","v_name","default")This gives younil?
You added the string"default"to the optional default value - which means it should return"default"if the value is not set.How are you verifying that you have a value for
v_name? What value is set in the registry? What ruby value type do you use to set the value? -
In the first instance of Sketchup, the plugin writes to the register, and waits at a UI.messagebox midway. At this time, the second instance of sketchup, saves its model, calls the observer, to checks the register, but nil is returned. I use regedit to check the values in the register as I step through the program. In this case nil works for me, but I would like to know whats happening. Maybe one instance locks access to the register from the other? I am in the process of posting the plugin.
-
Plugin posted here.
-
So what is the value you see in the register?
Does the register actually change as you usewrite_default? Or is it delayed until SketchUp closes? -
Regedit shows the
write_defaultchanges the register, but whenread_defaultis placed in the observer, it returns nil. -
I believe I posted the 3rd argument bug for Sketchup.read_default() in the API topic. I have to check the beta bug list on this.
EDIT: YES.. I did report this bug ...
@dan rathbun said:
Any attempt to read a Registry DWORD value returns nil.
The 3rd argument is not returned on failure.The bug was already listed in Google's buglist as number 2435419
-
I bumped the bug report.
-
Good to know. In my case, I assumed that returning nil in that situation was a sign that the second instance of Sketchup was running. Guess I'll add
or v_name==the_varifor when it gets fixed:-) -
There'a a major drawback to using the API "default" methods.
That is they did not give us a "remove_default" method.
This means the Win Registry or Mac plist can become cluttered with old 'orphaned' settings for plugins that are no longer used.Many authors (TIG is one I think,) that instead write out their own settings file in the plugin subfolder. I think he has posted code snippets in other topic threads.
Basically you write out a string report of your settings Hash to a text file, using the inspect method.
To reload it, you read the file into a String object, and then eval() the string inside the context of your module, assigning it to a var, which should become type Hash after evaluation.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement