[AppleScript] - Sketchup PrintRight
-
(not sure where to post this )
this is an early version of an attempt at making sketchup more user friendly when it comes to printing.
DOWNLOAD HERE:
—that installer will only work on Lion.. see 'new in lion' release notes here:
http://www.macosxautomation.com/lion/automatorservices.htmlhere's an installer .pkg for leopard/snow leopard
(needs a fix)[i'll post some screenshots since this will probably be unfamiliar territory for most.. but hey, it's a lot easier than installing ruby plugins ]
install instructions:
unzip then double-click the file SU PrintRight.workflow... then click install
(for uninstalling, the .workflow file will be located at ~/library/services )
requirements:
since sketchup is in no_way_shape_or_form aware of applescript, i had to use system events for most of this stuff.. so, in order to use this service, you'll need to 'Enable Access for Assistive Devices' via System Preferences -> Universal Access:
(in the future, the script will check this preference and if it's not on, it will ask if you want to turn it on without having to navigate through the sys prefs.. the code is already out there.. i just have to copy/paste and test it.. maybe tomorrow)How to Use:
once installed, SU PrintRight will be available through the SketchUp menu -> Services (no need to relaunch su after install.. it will be available for use immediately)What does it do?
well, not much so far but getting to this point was pretty nuts (read— virgin script writer using applescript for sketchup.. applescript for finder.app = awesome.. applescript for sketchup = "you're and idiot")
anyways..you will be presented with two dialog boxes.. one asking for the Height of your paper and one asking for the Width..
the Sketchup window will then be resized to the aspect ratio of your desired paper.. (actually, and more importantly, the Drawing Space within the window will be sized to your paper.. this is the portion Sketchup uses when determining which area to print.. i've yet to see an app or utility out there that will do this as they always resize the entire window..
so that's step one in making sketchup more print friendly.. from this point, everything else that's needed to get sketchup to print to scale on the desired amount of pages etc is available within sketchup.. it's still super confusing but it's doable.. i plan to add more features to this service which will make it even more easy to print right from sketchup.. i think the hard part is over though..
let me know how it's working so far.
(gonna go buy a late night snack then make another post with some more info)
-
oh.. here's the script for those who can't read the .workflow but want to see how it looks..
the dialogs are via automator which passes the paper size to the applescript..
%(#800000)[on run {input, parameters}
set paph to first item of input
set papw to second item of input
-- get screen resolution
tell application "Finder"
set rez to bounds of window of desktop
set ScreenWidth to item 3 of rez
set ScreenHeight to item 4 of rez
end tell
-- get dock properties.. if the dock is visible along the bottom then use 90 as it's height.. otherwise, don't worry about the dock
tell application "System Events"
tell dock preferences
set DockProp to properties
get autohide of DockProp
get screen edge of DockProp
if autohide is true or screen edge is not bottom then
set DKheight to 0
else
set DKheight to 90
end if
end tell
end tell
--Sketchup
tell application "SketchUp"
activate
tell application "System Events" to tell process "SketchUp"
--identify the drawing window
set drawWin to count of windows
-- see if there's a toolbar up top and if so, get it's size.. do the same for scene tabs
if exists (tool bar 1) of window drawWin then
set tbsz to size of (tool bar 1) of window drawWin
else
set tbsz to {0, 0}
end if
set TBsize to second item of tbsz
if exists (tab group 1) of window drawWin then
set scsz to size of (tab group 1) of window drawWin
else
set scsz to {0, 0}
end if
set SceneSize to second item of scsz
--CALCULATE AND RESIZE DRAWING WINDOW
--paper width = var "papw"
--paper heith = var "paph"
--screen height = var "ScreenHeight"
--screen width = var "ScreenWidth"
-- dock height = "DKHeight"
-- OSX Menu Bar = 22px
-- top of sketchup window = 22px
-- bottom of sketchup window = 30px
--toolbar(if,then) = var "TBsize"
--scene tabs(if,then) = var "SceneSize"
set AspectRatio to (papw / paph)
if AspectRatio is less than 1.5 then
set WinHeight to (ScreenHeight - (22 + DKheight))
set WinWidth to (AspectRatio * (WinHeight - (TBsize + SceneSize + 52)))
else
set WinWidth to (ScreenWidth * 0.87)
set WinHeight to ((WinWidth / AspectRatio) + (52 + DKheight + TBsize + SceneSize))
end if
--resize the drawing window
set position of window drawWin to {80, 22}
set size of window drawWin to {WinWidth, WinHeight}
end tell
end tell
return input
end run][edit- hmm.. left some notes in there that don't need to be.. i'll clean it up some for round 2]
-
what version of mac os are you using? I had problems installing this. besides, can the units be changed to metric?
-
the problem seems to be related to the fact that I am running snow leopard. while installing, there comes a message about an unrecognizable version of the app used to create the applescript. better wait until I upgrade to lion.
-
*** to anyone willing to test
(and actually gets it up and running )some things it should do but may not on other environments?
if the dock is visible on the bottom of the screen then you max height will consider it and leave space for the dock.. if the dock is on the bottom but hidden, the window should extend to the bottom of the screen..
the windows will reach the bottom of the screen until your ratio becomes thinner than 3:2.. at which point, the window will scale to ~85% of your screen width and the bottom edge will start coming up.. you people with the newer 16:9 iMacs may want this to be set a bit wider?
i believe everyone's osx menu bar is 22px tall and doesn't change.. if there's a case when someone has a fatter menu bar than that, let me know about it. (a thinner one shouldn't matter.. a taller one will cause a wrong result..
this service should account for toolbar height (it changes depending on small/large icons, text or no text, hidden/visible).. it should also recognize if you have any scene tabs showing in the window and adjust accordingly.
i believe the bottom bar of a sketchup window is always 30px tall.. let me know if there's ever a case where that size may change.
i think that's it for now.
-
@edson said:
the problem seems to be related to the fact that I am running snow leopard. while installing, there comes a message about an unrecognizable version of the app used to create the applescript. better wait until I upgrade to lion.
added a .pkg if anyone want an easy install on less-than-lion
fwiw, you can also run this from automator.. just open the .workflow in automator (launch automator -> choose 'open existing workflow') ...then click the 'run' button at the top right..
you'll be able to see everything the service consists of.. just make sure you have a sketchup window open (it doesn't have to be the front app.. just a window open though.) -
@edson said:
what version of mac os are you using? I had problems installing this. besides, can the units be changed to metric?
[EDIT] yeah, that type of install only works on lion.. see here:
http://www.macosxautomation.com/lion/automatorservices.htmli'm using lion.. and unfortunately for stuff like this, i have lion on all 3 of my computers..
what are the install problems?
you may have to enable the script via System Prefs->Keyboard->Keyboard Shortcuts->Services
the service should appear at the bottom of the list .. turn it on if it's not already..if it's a problem of it not making it to your service folder then you can place it there manually..
~user/library/services..maybe this easy install/auto_on is a lion thing?
re:the metric thing..
the plan is for you to set up your paper size and and orientation through file->print then that info is fed to the script.. so you won't have to enter your paper size in these dialog boxes.. this service will be able to help with setting custom borders though which is where most people go wrong when trying to print with sketchup.. they basically try to scale at 100% then print to an 8 1/2 x 11 — except, after considering their border settings, the page is actually 8x10 so the print overflows onto four pages etc..i want to make all of that a lot easier to deal with.
-
Jeff, this sounds really cool and useful. I installed the PKG version on my MacBook Pro running OSX 10.6.8. No joy in SU. I don't get the menu entry you show and I can't locate the file to look at it or remove. There is nothing called ~system/library/services. A search of the HD for 'SU PrintRight.workflow' turns up nothing although I did get a message that it had installed successfully. I search the computer for '.workflow' but found only three files with that and none of them are SU PrintRight.workflow.
Suggestions?
-
Sometimes you have to create the folder manually.
On SL, the location is here:-
Macintosh HD:Users:username:Library:Services
Should be the same on Lion too.
On Lion, you will need to use something like LionTweaks (http://ifredrik.com/applications/ it's wonderful, the guy is only 16, if you use it, please consider donating, I have) to make your Library folder visible.
Really nice work Jeff!
-
The file will be installed in the following location:
/Users/Jeff/Library/Services/SU PrintRight.workflow
might be an issue... john -
Found it. Thanks, John.
-
@dave r said:
Jeff, this sounds really cool and useful. I installed the PKG version on my MacBook Pro running OSX 10.6.8. No joy in SU. I don't get the menu entry you show and I can't locate the file to look at it or remove. There is nothing called ~system/library/services. A search of the HD for 'SU PrintRight.workflow' turns up nothing although I did get a message that it had installed successfully. I search the computer for '.workflow' but found only three files with that and none of them are SU PrintRight.workflow.
Suggestions?
if it's not showing up under sketchup services, you'll have to enable it here:
System Prefs->Keyboard->Keyboard Shortcuts->Services
the service should appear at the bottom of the listalso see the bit above about 'enabling assistive devices' in your prefs
[and after seeing the replies so far, i guess this type of 'how do i get it to work' has been going on for a while in the same manner as we see at scf with rubies.. so, Lion includes things to make all of this easier i guess in a similar way as su8M2 tries to do with 'install extensions'.. ]
-
Jeff, I couldn't find it because it installed under ~/Users/Jeff/Library/Services/ as John reported. Not because I couldn't understand how to use it. I followed your instructions and enabled under Assistive Devices as you described.
-
@dave r said:
Jeff, I couldn't find it because it installed under ~/Users/Jeff/Library/Services/ as John reported. Not because I couldn't understand how to use it. I followed your instructions and enabled under Assistive Devices as you described.
lol.. sorry about that.. let me take that pkg down for now.. i obviously used the wrong setting in package maker and had it set up to install in the same exact place as it does on my computers..
just download the lion version and place it manually at:
user/library/servicesdelete the user/jeff folder
-
I've got it basiclly running on 10.5.8, it doesn't appear recognize 'edge' as a dock preference,
so if I comment out**%(#0000FF)[get autohide of]%(#408000)[DockProp] %(#808080)[--get screen edge of DockProp] %(#0000FF)[if autohide is true then] %(#808080)[--or screen edge is not bottom then]**
it all still seems to work...
if dock is hidden it uses the full screen height and if it's showing I get a 90px margin from bottom of model area to top of 'Dock'I'll try and turn it back into a 'Leopard' service next, I pulled out the workflow and have it running from Automater...
for Leopard users
first clean up service menu http://manytricks.com/servicescrubber/
then it'll be easier when this is working...john
john -
@driven said:
I've got it basiclly running on 10.5.8, it doesn't appear recognize 'edge' as a dock preference,
so if I comment out**get autohide ofDockProp
--get screen edge of DockProp%(#0000FF)[if autohide is true then] %(#808080)[--or screen edge is not bottom then]**
it all still seems to work...
if dock is hidden it uses the full screen height and if it's showing I get a 90px margin from bottom of model area to top of 'Dock'hmm.. i think in that case, if the dock is visible but on a screen edge (mine is on the right side for instance), then there will still be space left at the bottom as it thinks there's a dock down there…
put this in AppleScript Editor:
tell application "System Events" tell dock preferences get properties end tell end tell
and it will report which which preferences are recognizable :
(on lion, i get this) -
this is 10.5.8 list,
where I started from as well... {minimize effect:scale, dock size:1.0, location:bottom, magnification:false, class:dock preferences object, magnification size:0.5, animate:true, autohide:true}
or {minimize effect:scale, dock size:1.0, location:left, magnification:true, class:dock preferences object, magnification size:0.517857134342, animate:false, autohide:false}
right being the other location...when NOT hidden, with the commented out version it just pushes it sideways 90px, either left, right or up...
what happens when you leave it out on Lion?
john
-
not sure.. I'm on a phone now.
I'll chage it to where it checks for location or screen edge instead of just screen edge.
i guess at this point, I'm mostly concerned with the aspect ratio showing up properly.an easy way to check is by setting the paper height and width to the same size (square) the using the shift-cmmd-4 screenshot cursor to manually measure the drawing area.
-
been doing exactly that, and it's square... john
-
@driven said:
been doing exactly that, and it's square... john
sweet!
I figured out how to get into the print dialogs so I should be able to get the rest of my ideas implemented.
going to SF tmmr for a week so I might not get an update out super soon.
Advertisement