I’m trying to launch a new instance of Sketchup with another template.
I’ve tried the following
Sketchup.template=“~/Desktop/template.skp”
Sketchup.file_new
But it opens the last template not the one specified.
If I do the following:
/Applications/SketchUp\ 2015/SketchUp.app/Contents/MacOS/SketchUp --args -template ~/Desktop/template.skp
it opens the way I want, but I want to do it on ruby. Thx.
Because Mac is MDI, you have to kill the current running instance and then launch a new one using the command line you gave. @john_drivenupthewall has done this from Ruby (I once had his code but lost it…). Because of the ping above, he will probably chime in with details.
How could I do this only in Ruby? I want it to be multi-platform
I took a second look, and the reason your initial version doesn’t work is that Sketchup.template= requires a full path to the template file. It doesn’t know how to expand your path string starting with the shortcut “~”, so it silently ignores it and continues to use the old template. You can verify this by printing Sketchup.template immediately after the assignment. This failure without warning could be regarded as a bug, and the API docs ought to explain this limitation.
You can use Ruby File library methods to get a full path and then it will work. Due to completely different file system conventions, the path is going to be different on Windows than on Mac, and you will have to take this into account if you want multi-platform.
Sketchup.template = File.expand_path('~/Desktop/template.skp')
should work cross platform
john
2 Likes