Writing a config or temp file in Plugins folder
-
Why does it have to be a file made in the
../Plugins/folder ?
There are many places that a user will have access rights - e.g.C:\Temp?
You can also get the User's very own 'TEMP' folder usingENV["TEMP"]for PC orENV["TMPDIR"]for MAC - e.g.C:\Users\TIG\AppData\Local\Temp
-
The temp folder doesn't work well when you want to store persistent config files.
-
What we need in the API is a method that will return the path to where one can store application data on each OS.
-
On Win7 I see this key:
LOCALAPPDATA - C:\Users\Thomas\AppData\LocalIs there something on OSX?
-
My
ENVexample combined with a simple OS test lets you find the User's own TEMP file...
The PC'sENV["LOCALAPPDATA"]would allow you to then make a specific sub-folder to contain the config file - on a MAC what is it ?BUT you can save config info in other ways...
To save them
If it's entity specific useentity.set_attributes(dict,key,value)
If it's model specific usemodel.set_attributes(dict,key,value)
If it's Sketchup specific useSketchup.write_default(section,variable,value)
[if it's a file-path with '' you'll need to usetr("\\","/")before writing it]To retrieve them use
entity.get_attributes(dict,key,default)
model.get_attributes(dict,key,default)
Sketchup.read_default(section,variable,value)
[if it's a file-path you'll need to usetr("/","\\")after reading it and before using it]

-
@tig said:
[if it's a file-path with '' you'll need to use tr("\","/") before writing it]
Or use
File.expand_path@unknownuser said:
I have to try if once again. If my memory doesn't deceive me I haven't had good results with it in the past.
I use it quite frequently. But beware that it doesn't handle Length objects well - so convert them into floats first. (I made a wrapper to handle conversion of Length and Symbol for write/read_default)
-
@tig said:
Why does it have to be a file made in the
../Plugins/folder ?It doesn't have to be. If I would have just a chance to write a path to the config file then it would be ok...
I have forgotten aboutSketchup.write_default. Thanks Thomas!
I have to try it once again. If my memory doesn't deceive me I haven't had good results with it in the past. -
Note that
read/write_defaultsis best with Strings - convert then from/to Float [or whatever] afterwards...
-
works fine with floats, integers, even arrays in my experience...
-
For windows %appdata% ?
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