Hello, I use a cabinet design software called “Mozaik” to design/draw cabinets. One of it’s features allows me to send the current room/cabinet to Sketchup (it generates all of the models for every cabinet part and groups them by cabinet, it’s actually kinda cool). I’m using Sketchup 8.0.1, which is installed by Mozaik. What I’m asking seems like it would be pretty simple. I want a piece of ruby code that I can run in the console, or stick in a plugin under a menu item that will simply print the current view X times in landscape orientation. I don’t even care if X is hard-coded for now. I want to skip all of the print dialogs and just print in landscape without any user interaction. I’ve scoured the web and I can’t seem to find anything.
I have experience in Python, C, JavaScript, and a few other languages. Ruby is not one of them. Even if I have to export the view as an Image, and then somehow print that image from ruby, that would be great. In the future, I would add headers for each page (like a different title for each copy). I know that’s possible, but it’s useless without the automated printing.
Anyone have any ideas?
I’ve included one of my project files, in case anyone was wondering. I just want to print whatever is on the screen (in Sketchup) when I run the code.
Please verify, you are using SketchUp 8 M2 (ver 8.0.11752) or is it SketchUp 2018 (ver 18.0.16975) ?
As an aside, Mozaik should not be distributing copyrighted software without permission from the copyright holder.
The SketchUp API does not expose functions of the Print dialogs. However, on Windows you can use the WIN32OLE class to leverage the Windows Scripting Host’s SendKeys method. Then perhaps send keys to set the paper orientation and number of copies.
Thank you for the PNG function. I guess if I have an image saved to the hard-drive, I could write the “auto printer” in just about anything (and have ruby call it somehow), but I may do the SendKeys thing that you linked to. It seems like it might be less code to write. Thanks again for that.
Ruby has %x strings (choose whatever delimiter you like,) which are passed to the Kernel backquote method. (Beware the SketchUp releases often break the return value from commands run in subshell methods. So we usually have to pipe output into a text file and then read the textfile.)
Also again with the WIN32OLE class, you can leverage the Windows Scripting Host’s Shell object methods that can start external processes.
Ex:
# at top of module ...
require "win32ole"
# Elsewhere ...
def run_minimized(command)
shell = WIN32OLE.new("WScript.Shell")
shell.Run(command,7,false)
end
Okay, then that version did not come with a Ruby Standard Library. (It was SU2014 that first shipped with Ruby’s Standard Library and Ruby 2.0.)
So for SketchUp 8 and 2013, you’ll need to go get the Ruby 1.8.6 Standard Library.
Never fear, I’ve already packaged it up as a SketchUp extension RBZ archive.
Download it, and use the “Install Extension…” button at the bottom of the Extensions panel, of the Preferences dialog in SU8. Navigate to where you downloaded the RBZ archive and select it, choose OK. (Then I always suggest restarting SketchUp after installing extensions.)
With the Ruby Standard Library, you’ll now have access to the WIN32OLE and the Win32API script that you might use to make Windows C SDK calls (if so inclined.)
Thanks. Just thinking out loud … you may need quotes around the print utility path (within autoprint method command argument to run_minimized method call,) if there are any spaces in directory names (which there likely are.)