sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    Help with acess to registry from observer

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 3 Posters 412 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • honoluludesktopH Offline
      honoluludesktop
      last edited by

      Sketchup.read_default fails to access the registry with the following code, and returns nil although I have verified that there is a value in v_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
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        result=Sketchup.read_default("label","v_name","default") This gives you nil?
        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?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • honoluludesktopH Offline
          honoluludesktop
          last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • honoluludesktopH Offline
            honoluludesktop
            last edited by

            Plugin posted here.

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              So what is the value you see in the register?
              Does the register actually change as you use write_default ? Or is it delayed until SketchUp closes?

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • honoluludesktopH Offline
                honoluludesktop
                last edited by

                Regedit shows the write_default changes the register, but when read_default is placed in the observer, it returns nil.

                1 Reply Last reply Reply Quote 0
                • Dan RathbunD Offline
                  Dan Rathbun
                  last edited by

                  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'm not here much anymore.

                  1 Reply Last reply Reply Quote 0
                  • Dan RathbunD Offline
                    Dan Rathbun
                    last edited by

                    I bumped the bug report.

                    I'm not here much anymore.

                    1 Reply Last reply Reply Quote 0
                    • honoluludesktopH Offline
                      honoluludesktop
                      last edited by

                      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_vari for when it gets fixed:-)

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        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.

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement