[Woodworking] Yet another CutList plugin

Hmm … in my case, the path variable is an absolute path. Then it starts by a / on Mac or C:/ (or other drive letter) on Windows. Then on Mac, the URL is file:////... with 4 /. That why I think it’s strange to put 3 / with my absolute path.

If it works… why worry ?

Haha … because I just want to understand what is the true way and the acceptable way :wink:

having to many is handled, too few will fail, 3 is on the safe side…

path = Sketchup.find_support_file(“Plugins”)
/Users/johns_iMac/Library/Application Support/SketchUp 2017/SketchUp/Plugins
UI.openURL(“file:/#{path}”)
false
UI.openURL(“file://#{path}”)
true
UI.openURL(“file:///////////#{path}”)
true

Read this, maybe it will help:

As @john_drivenupthewall says /// is safe.
If your specific MAC path doesn’t start with a / then it’s added.
So /// always works.

Ok, /// is safe … that’s a good answer :stuck_out_tongue:


Else an other big problem I’ve got for this plugin is to save the WebDialog (or HtmlDialog) size when the user resize it.
Do you know a nice way to do this ? Retriveing dialog size seems to be out of the API :frowning:


And one more question, do you know if it’s possible form an extension to update itself ?

It’s not directly accessible in the API.

Unless your dialog’s code deliberately sets the dialog’s size [max/min]] each time it runs, on a PC its size is remembered and should reopen using the users last choice [rather than the starting size or position], but I think on a MAC it will always default to the starting size/position you specify in your code.

There are js ways of getting the dialog’s window size, e.g.
https://andylangton.co.uk/blog/development/get-viewportwindow-size-width-and-height-javascript
Run a function based on this from the Ruby side after the dialog is opened - at a default size [more about that later…***] - have the function do a callback passing the height|width as a string, with a separator, split and parse it into two integers, from those and the fixed size you can work out the allowance for the frames and title-bar.
Use an on_close block to run a similar [different] function again to get the closing height|width, again do a different callback to get these.
Add on the frame width and height to give a true size as used by the dialog.
***Use Sketchup’s write_default to save those values for later.
When the dialog is about to be next opened you read_default to get the last used size and use that as the size in the dialog creation code. If there’s no default to read use your own default size and write_default that for later…
Thus the newly opened dialog will be sized either as your default or the last size chosen by the user.


You could probably also do something similar re the dialog's screen positioning... https://www.w3schools.com/jsref/prop_win_screenx.asp
Assuming your RBZ is available as a URL you can use Ruby to download it:
require('open-uri')
### later on
File.open(path, "wb"){|f| ### open-uri open
  open(url, "rb"){|r| f.write(r.read) }
}

where ‘url’ is the full URL to the RBZ, and ‘path’ is the RBZ copied in your TEMP folder.
Then use
Module: Sketchup — SketchUp Ruby API Documentation
To load it.

Now the matter of how you check the version…
The installed RBZ will have a loader RB containing the VERSION - you can set this as a Constant inside the loading module.
So you always get it at any time…
Let’s assume you a have a menu-item ‘Check for Update…’
You need code to retrieve the latest version from your website’s URL, you can then open that, run a function to get the version value and add a callback etc to return it to the Ruby side - the dialog can open minimized off-screen and auto-close once the version is received.
Then compare the two versions - if they are the same, message “You have the latest version.”
If there is a newer version, message “There is an update available. Install it ?”
If No skip, if Yes do the above process of downloading the RBZ from the URL and installing it…
Remember that you might need to tell the user after installed that they will need to restart SketchUp to see the updates…

Wow, many thanks for all of this @TIG !

This topic was automatically closed after 91 days. New replies are no longer allowed.