sketchucation logo sketchucation
    • Login
    πŸ€‘ SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

    Adding new options or OptionsProviders?

    Scheduled Pinned Locked Moved Developers' Forum
    14 Posts 6 Posters 409 Views 6 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.
    • M Offline
      mattscar
      last edited by

      Hi,

      By default, the OptionsProvider called NamedOptions is empty, and I'd like to add two options. Is there a way to do this? What is the NamedOptions provider for, anyway?

      Also, is there a way to add a new OptionsProvider to an OptionsManager? I haven't found any 'add' method or anything similar.

      Thanks,

      Matt

      1 Reply Last reply Reply Quote 0
      • J Offline
        Jim
        last edited by

        Matt,

        I'm not entirely sure what purpose the Named Options is for; whether it was meant for use by "public" scripts or maybe internal SketchUp ones.

        That said, you can add an option simply by assignment:

        
        op = Sketchup.active_model.options
        named_options = op["NamedOptions"]
        named_options["MyOption"] = "Hello"
        
        

        Alternatively, you could create your own custom Attribute Dictionary in a similar way.

        Hi

        1 Reply Last reply Reply Quote 0
        • N Offline
          niccah
          last edited by

          I have to refresh this topic again!

          I am able to add new key for the optionsProvider "NamedOptions". The problem is: When I insert a new key and the user close Sketchup, there will be no notice to save the Sketchup file.

          Do you have an idea how I can handle this problem?

          My idea: I have to ask the user to save the file when the WebDialog gets closed

          What do you think?

          Thanks!

          1 Reply Last reply Reply Quote 0
          • N Offline
            niccah
            last edited by

            Okay, I have further problems... Let me explain, what I want to do....

            I would like to do a list of "projects". So, when someone add a project, a new option key will insert. The name of the key: "M2GC_projects_" << projectName

            So, at the end, I have a list of all projects by checking of the optionsProvider.

            ` optionsManager = Sketchup.active_model.options
            optionsProvider = optionsManager["NamedOptions"]
            optionsProviderKeys = optionsProvider.keys

            	projectName = dlg.get_element_value("projectName").delete("^a-zA-Z0-9");
            
            	if (projectName != "" && !optionsProviderKeys.include?("M2GC_projects_" << projectName))
            		optionsProvider["M2GC_projects_" << projectName] = ""
            
            		dlg.execute_script("addToProjectList('" + projectName + "')")
            		dlg.execute_script("document.getElementById('projectName').value=\"\"")
            	else
            		UI.messagebox "Project name already in use"
            	end`
            

            It sounds very strange, but I am able to insert just ONE key each "session". So, I try to insert several keys => no error in the ruby console. Now I save the Sketchup file. Close Sketchup. Open Sketchup again... just the first inserted key is now available. Now, I can insert a second value... by reopen Sketchup, both are now available...

            Guys - whats happening here?! πŸ˜„ I'm totally confused...

            Thanks for your help!

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

              @niccah said:

              I am able to add new key for the OptionsProvider "NamedOptions". The problem is: When I insert a new key and the user close SketchUp, there will be no notice to save the Sketchup file.

              Do you have an idea how I can handle this problem? ... What do you think?

              **The NamedOptions Provider is bugged.
              Please do not use it until it is fixed

              Your key/value pairs will propagate into the next model the user opens!**
              I have filed a bug report on this.


              Please attach an AttributeDictionary to the model (or one of the model's collection objects,) instead.

              I'm not here much anymore.

              1 Reply Last reply Reply Quote 0
              • TIGT Offline
                TIG Moderator
                last edited by

                If you want this 'list' to be 'universal' and accessible to every SKP opened on that PC then use Sketchup.write_default() and Sketchup.read_default() to store a list of project names.
                https://developers.google.com/sketchup/docs/ourdoc/sketchup#write_default
                https://developers.google.com/sketchup/docs/ourdoc/sketchup#read_default
                The 'kinds' of values that you can store is limited, but you could readily devise a way of making a list of names from an array, and reading that back in as an array etc to then add to etc etc...
                This way you avoid all of the issues of using a flaky Options-Provider or even an Attribute-Dictionary attached to a specific SKP which you would then need to replicate on any SKP you opened or newly made. Keeping the list with Sketchup itself means all SKPs can see it with no convolution.
                Alternatively, to make the list accessible to all users on the PC write/update/read a 'projects.dat' file into the [shared] main Plugins folder, that way all users get that list available to them [your script keeps it up to date]...
                To make it available to everyone across a network you can have the 'projects.dat' file somewhere on network that's accessible to all, then read/write it as above...
                You have to ensure that you read it with IO [do it's not unnecessarily left locked on reading it], and when [re]writing the list to the file you use open(...,'w');puts(...);close, on the .dat file so that others can use it immediately afterwards; in the script it's best to use a begin..rescue..end looped test, to try to write the updated data several times, in case someone else is doing the same thing and has 'locked' the file for writing briefly at the same instant you try too...

                TIG

                1 Reply Last reply Reply Quote 0
                • N Offline
                  niccah
                  last edited by

                  @dan rathbun said:

                  [size=120]The NamedOptions Provider is bugged.
                  Please do not use it until it is fixed

                  Oh, I didn't expect, that the answer is so easy! πŸ˜„ Thanks Dan!

                  @dan rathbun said:

                  If you want this 'list' to be 'universal' and accessible to every SKP opened on that PC then use Sketchup.write_default() and Sketchup.read_default() to store a list of project names.

                  Hm, I thought about that, but....

                  the projects are connected to a single Sketchup file... so I don't like to "flood" the registry with lots of project names and their options... What do you think?

                  Can I produce an empty group or something like that and fill its "description"?

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

                    @niccah said:

                    the projects are connected to a single Sketchup file... so I don't like to "flood" the registry with lots of project names and their options... What do you think?

                    Then attach an attribute to the model.
                    https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute

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

                    1 Reply Last reply Reply Quote 0
                    • N Offline
                      niccah
                      last edited by

                      @thomthom said:

                      @niccah said:

                      the projects are connected to a single Sketchup file... so I don't like to "flood" the registry with lots of project names and their options... What do you think?

                      Then attach an attribute to the model.
                      https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute

                      This sounds perfect! πŸ˜„ Thanks Thom!!

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

                        @niccah said:

                        @thomthom said:

                        Then attach an attribute to the model.
                        https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute

                        This sounds perfect! πŸ˜„ Thanks Thom!!

                        punchbug! I said that also ...

                        @dan rathbun said:

                        Please attach an AttributeDictionary to the model (or one of the model's collection objects,) instead.

                        You can also generate reports for attributes in the Pro edition from the menu:
                        File > Generate Report...

                        SketchUpdate blogspot:

                        • Generating reports from your models
                        • Adding custom attributes to your reports

                        There once was a Trimble script that we could modify for our own custom use, but I can no longer find the link. Anyone?

                        There is this script by Ashley Joyce: AttribReporter

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • N Offline
                          niccah
                          last edited by

                          @dan rathbun said:

                          @niccah said:

                          @thomthom said:

                          Then attach an attribute to the model.
                          https://developers.google.com/sketchup/docs/ourdoc/entity#set_attribute

                          This sounds perfect! πŸ˜„ Thanks Thom!!

                          punchbug! I said that also ...

                          I have to say sorry, Dan! At your post, I stopped to read at the horizontal line... I though it is not the topic of the post! ... πŸ˜„

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

                            Ditto - didn't notice it either.

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

                            1 Reply Last reply Reply Quote 0
                            • TIGT Offline
                              TIG Moderator
                              last edited by

                              I had also mentioned it in passing, referring to Dan's remark:
                              @unknownuser said:

                              ...This way you avoid all of the issues of using a flaky Options-Provider or even an Attribute-Dictionary attached to a specific SKP which you would then need to replicate on any SKP you opened or newly made...
                              as I had assumed this 'projects' list was universal rather than one specific SKP...

                              TIG

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

                                @dan rathbun said:

                                There once was a *pre-*Trimble script ( written by one of the SketchUp Development Team members, that generated custom Attribute Dictionary reports ) that we could modify for our own custom use, but I can no longer find the link.

                                Anyone know the link to it?

                                ❓

                                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