Adding new options or OptionsProviders?
-
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!
-
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.keysprojectName = 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!
-
@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 fixedYour 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.
-
If you want this 'list' to be 'universal' and accessible to every SKP opened on that PC then use
Sketchup.write_default()
andSketchup.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... -
@dan rathbun said:
[size=120]The NamedOptions Provider is bugged.
Please do not use it until it is fixedOh, 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"?
-
@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 -
@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_attributeThis sounds perfect! Thanks Thom!!
-
@niccah said:
@thomthom said:
Then attach an attribute to the model.
https://developers.google.com/sketchup/docs/ourdoc/entity#set_attributeThis 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:
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
-
@dan rathbun said:
@niccah said:
@thomthom said:
Then attach an attribute to the model.
https://developers.google.com/sketchup/docs/ourdoc/entity#set_attributeThis 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! ...
-
Ditto - didn't notice it either.
-
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... -
@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?
Advertisement