[AppleScript] - Sketchup PrintRight
-
it works once you grab the right element, I'm surprised it's 2 on yours and 1 here, that could be a hurdle...
BTW. this is the 'soft start' I normally use,
%(#4000FF)[on run
try
tell application "System Events"
if (count (every process whose name is "Sketchup")) = 0 then
activate application "SketchUp"
delay 1
end if
tell application "System Events"
ignoring application responses
tell process "SketchUp"
set frontmost to true
delay 1
try] -
@driven said:
it works once you grab the right element, I'm surprised it's 2 on yours and 1 here, that could be a hurdle...
oh wait, i see what's going on.. phew
i've been doing all the tests with no printer selected.. if you select a printer then a static text item will display underneath the printer popup -displaying the printer name -which makes that static text 1 and the paper size static text 2..
so i can just identify it in the same way i did the sketchup window # (which changes depending on how many plugin toolbars etc you have showing)
-
@driven said:
BTW. this is the 'soft start' I normally use,
%(#4000FF)[on run
try
tell application "System Events"
if (count (every process whose name is "Sketchup")) = 0 then
activate application "SketchUp"
delay 1
end if
tell application "System Events"
ignoring application responses
tell process "SketchUp"
set frontmost to true
delay 1
try]is that something i should be able to paste into applescript editor and run from there?
i think there are some ends or tells or something missing
those are the things that slow me down on this stuff.. getting all of that in the right place.. it'd be a lot easier if i knew what i was doing -
Jeff,
Does this do anything for resolution or anti-aliasing? I find (just testing with print pdf) that exporting 2d graphic or using LO always gives an acceptable print, whereas a straight print out of SU does not. So I wonder if this scripting work of yours can be of use to me?
Another thought. A guy created a printing utility script for my Mac CAD program and it enabled printing of sheets (these are basically layer setups), providing a dialog to select the ones you want. It then ran prints of all those you selected. One was also able to save certain sets of print parameters, such as "save as pdf" and naming the files. Similarly perhaps you can batch print scenes in SU, which seem equivalent as both are a program-specific setup.Peter
-
@pbacot said:
Jeff,
Does this do anything for resolution or anti-aliasing? I find (just testing with print pdf) that exporting 2d graphic or using LO always gives an acceptable print, whereas a straight print out of SU does not. So I wonder if this scripting work of yours can be of use to me?
no, nothing to do with that type of stuff.. it's mainly about getting a to-scale print out of sketchup in a reasonable manner and with the drawing in sketchup looking like the print (like, if you try to print to a vertical 8.5x11 from sketchup and your drawing window is sort of widish like your screen, you'll have a wide view of the sketchup window scaled down to fit within the 8 1/2" width of the paper ... and huge borders at the top and bottom.
@unknownuser said:
Another thought. A guy created a printing utility script for my Mac CAD program and it enabled printing of sheets (these are basically layer setups), providing a dialog to select the ones you want. It then ran prints of all those you selected. One was also able to save certain sets of print parameters, such as "save as pdf" and naming the files. Similarly perhaps you can batch print scenes in SU, which seem equivalent as both are a program-specific setup.
Peter
automator would be really good for that type of stuff and simple to set up.. it has quite a few good print options for making print plugins which are then in turn available through your print dialogs..
but yeah, i'm not really attempting to make a smoother workflow for sketchup, i'm trying to make a script to do something that sketchup can't do.. (well,that part is already done which is sizing the drawing window to the same aspect ratio as the paper.. i guess the rest is just sort of an assistant which will, i hope, take a lot of confusion out of sketchup's printing procedures..)
-
static text 1 seems to stay the same regardless of what I choose in the other items... good?
this is wrapped and still works, the ignoring only works for menu items, so I took it out
on run try tell application "System Events" if (count (every process whose name is "Sketchup")) = 0 then activate application "SketchUp" delay 1 end if tell application "System Events" tell process "SketchUp" set frontmost to true delay 1 set drawwin to count of windows set AppleScript's text item delimiters to {" "} click menu item "page setup..." of menu "file" of menu bar 1 repeat until focused of window drawwin = true try set psz to value of static text 1 of sheet 1 of window drawwin end try end repeat set papw to third text item of psz set paph to first text item of psz display dialog "width = " & papw & " height = " & paph end tell end tell end tell end try end run
-
@driven said:
static text 1 seems to stay the same regardless of what I choose in the other items... good?
yeah.. i'll just have to make sure to click on everything and try different settings in this type of situation to make sure nothing else is popping up..
thanks for trying this stuff out /catching the errors.
-
@unknownuser said:
yeah.. i'll just have to make sure to click on everything and try different settings in this type of situation
you could write an applescript to do that....
-
found a better way to get the dock info.. this will return the actual height etc..
tell application "Finder" set dockOrientation to do shell script "defaults read com.apple.dock orientation" end tell tell application "System Events" to tell process "Dock" set {dockW, dockH} to size in list 1 end tell return {dockOrientation, dockW, dockH}
via:
http://www.snaq.net/software/applescripts.php
that stuff looks way more organized than how i'm doing it.. i'm going to have to make sense of what he's doing there and copy the way he's keeping things neat it if this print script is going to be successful.. it's already starting to get messy -
Hi Jeff,
although your away maybe you can try this test file.
after much searching, I can get Raster images to fit an A4 sheet exactly, [pixel perfect if you drawWin to {WinWidth - 4,]
PrintTestMac.skpnow for step 2, multiple sheets, that line up.... john
-
PrintTestMac_eps.pdf
john -
Hi Jeff,
just realised I hadn't added a needed ingredient, that I'm using for both raster and vector output.
a ruby script.
mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection view = Sketchup.active_model.active_view new_view = view.zoom_extents new_view = view.zoom 1.0525
I saved it as zoomZoomed.rb and run it after Automator has sized the window, it gets rid of the margin. YMMV... john
if you want it on a button for quick testing I'll knock one up, but if you run it from 'RubyCodeEditor' you can tweak the ratio setting.
or did I send this... am I going mad... etc... -
and if you want to save your automator script as an app in plugin subfolder[or anywhere, just fix the path]
you just call that from ruby first.mod = Sketchup.active_model # Open model ent = mod.entities # All entities in model sel = mod.selection # Current selection view = Sketchup.active_model.active_view system('open /Library/Application\ Support/Google\ SketchUp\ 8/SketchUp/plugins/zZoomed_PrintRight/PrintRight.app') new_view = view.zoom_extents new_view = view.zoom 1.0525
needs the full path for system... john
I'm subtracting 4
4, WinHeight} before making the app.you can still change the app in automator, just re-save and overwrite.
-
@driven said:
new_view = view.zoom 1.0525
nice.. in my experiments, i'm actually using a factor of 1.05083 after first setting the FOV to 35.00deg.. (i found the scale factor changes depending on fov so in the script, i preset to 35.00deg)
i almost had this thing up and going then hit yet another wall.. all of my testing so far was using a flat plane as the drawing.. then i tried it on something with a height and everything goes out of whack so it's back to tinkering with available sketchup controls to make it happen..
here's the latest for this part of the script: (copy/paste into applescript editor and run from there -- with a sketchup window open somewhere)
` tell application "SketchUp"
activate
tell application "System Events" to tell process "SketchUp"set drawwin to count of windows set AppleScript's text item delimiters to {" "} --set the camera to perspective by checking if Field Of View is enabled if enabled of menu item "Field of View" of menu 1 of menu bar item "Camera" of menu bar 1 is false then click menu item "Perspective" of menu 1 of menu bar item "Camera" of menu bar 1 end if --set FOV to 35 deg.. in order for the 1.05083 to work out right.. click menu item "Field of View" of menu 1 of menu bar item "Camera" of menu bar 1 keystroke "35" & return click menu item "Zoom Extents" of menu "Camera" of menu bar 1 click menu item "Zoom" of menu "Camera" of menu bar 1 set fv to value of text field 1 of window drawwin set FOV to ((first text item of fv) / 1.05083) as text keystroke FOV & return click menu item "Parallel Projection" of menu "Camera" of menu bar 1 end tell
end tell`
with that, if you had a drawing window set to a paper size of 8.5 x 11 borderless then draw a rectangle of say 11' x 8'-6" in sketchup.. after running the script, the actual extents of the drawing would be properly zoomed then under file->Document Setup, you'll see the scale set as expected (entire paper is printed to with a scale of 1" = 1'..)
i was going to use this as a basis for giving 'suggested scales' to the user that the can pick from then the model would zoom in/out in the drawing window to show exactly how it will look on the final print/pdf..
anyway… i wonder if there's a way to use ruby commands in an applescript?? i might have some better control that way of the actual sketchup drawing.. i've seen a couple of examples of using python inside an applescript so i assume ruby would be possible as well?.. (and i guess the big question would be if SketchUp's ruby could be used inside an applescript which will do sketchup things instead of just using OSX's ruby)..
have you ever messed around with doing anything like that?
thanks -
quick check gave
"System Events got an error: Can’t get text field 1 of window 9 of process "SketchUp". Invalid index."
I need to sleep, so i'll have a look later.
it's easier to get applescript/system to do stuff from SU than the other way round, and even then there's things that don't fly.
it's also easier to get SU to do SU things and to only add missing or fix broken stuff. [eg. change fov is a one liner, print to scale is broken]
SU is the environment your scripts needs to work in so for example if you call system to kill sketchup from inside SU you get an endless loop.
Have a look inside those sumac.app scripts I posted ages ago, that's why I made them Menu Bar apps.
john
-
@driven said:
quick check gave
"System Events got an error: Can’t get text field 1 of window 9 of process "SketchUp". Invalid index."
I need to sleep, so i'll have a look later.
that's probably because you had more than one sketchup window open when you tried it..
the order the sketchup windows appear (entity info etc dialogs first, then the toolbars, finally the drawing window) really make gui scripting sketchup difficult (+, say you have 10 total windows then open a new drawing window.. the new one becomes #10 then the other window becomes #11 and moves to the back ).. i think i have a way to separate the drawing windows from the rest of the stuff then using the frontmost of those so it will work with multiple windows open.. haven't tried to implement it yet.. it's on the cleanup list if i can ever get this to work out..(fwiw- the desired target you're seeing the error for is the measurement box when in a state that user input is possible)
@unknownuser said:
it's easier to get applescript/system to do stuff from SU than the other way round, and even then there's things that don't fly.
it's also easier to get SU to do SU things and to only add missing or fix broken stuff. [eg. change fov is a one liner, print to scale is broken]
SU is the environment your scripts needs to work in so for example if you call system to kill sketchup from inside SU you get an endless loop.
Have a look inside those sumac.app scripts I posted ages ago, that's why I made them Menu Bar apps.
john
i've tried to find the sumac stuff before and i just can't got a link?
also just thought of an easy, though not too elegant way to use su ruby commands via an applescript... the ruby console
it might actually work out ok.. gonna mess around with it in a little while. -
@unknownuser said:
also just thought of an easy, though not too elegant way to use su ruby commands via an applescript... the ruby console
it might actually work out ok.. gonna mess around with it in a little while.ha.. it works pretty good..
and i can move forward now using that code you posted earlier (the
view = view.zoom factor
stuff)..and the zoom factor is way nicer than what i was trying which was with a set FOV then changing the FOV to fit the window.. zoom factor works regardless of the user's fov setting (but there's no way i could figure out how to change the zoom factor within sketchup itself other than with a mouse so that option was out.. using it now via ruby )
[EDIT] oh.. and more importantly.. you can use the zoom factor in parallel projection while you can't change the FOV (which is what i previously needed to do) in parallel projection.. the fov option is greyed out in normal SU if parallel projecting and i actually crashed SU once or twice trying to change it via ruby while viewing parallel projection
-
here's the same thing i was trying above except it now uses ruby for the zoom factor instead of messing around with the camera's FOV.. so i'm now able to work with 3D objects instead of just flat ones..
i think it's just some weird math and a few dialogs to do then this whole idea might actually work` tell application "SketchUp"
activate
tell application "System Events" to tell process "SketchUp"set drawwin to count of windows set AppleScript's text item delimiters to {" "} --set the camera to Parallel Projection by checking if Field Of View is enabled --(FOV will NOT be greyed out if Perspective or 2pt Perspective) if enabled of menu item "Field of View" of menu 1 of menu bar item "Camera" of menu bar 1 is true then click menu item "Parallel Projection" of menu 1 of menu bar item "Camera" of menu bar 1 end if -- Zoom extents then use ruby console to scale zoom by a factor of 1.05405 click menu item "Zoom Extents" of menu "Camera" of menu bar 1 click menu item "Ruby Console" of menu "Window" of menu bar 1 keystroke "view = Sketchup.active_model.active_view view = view.zoom 1.05405" & return -- close ruby console click button 1 of window "Ruby Console" end tell
end tell`
[edit].. hmm.. that's not compiling properly once i copy/paste it from the forum back into applescript editor.. the ruby part should look like this in applescript editor :
maybe if i break it down into separate keystroke entries i'll be able to post it properly here?
here's the .scpt instead:
SU_ZOOMRUBY.zip -
jeff heres a sumac download link, dmg installerhttp://homepage.mac.com/johnboundy/filechute/sumac_dev_2011-03-01-002859.dmg.zip
I need to go back out for an hour or so, I'll have another look at your stuff.
What I see as being really good with what your trying is the idea...
and you've cracked what can't be done from SU ruby.. i.e manipulate the window size and position the window.
ruby can handle all the other bits really easily, without opening dialogs or console at all, it can even send the applescript to system and avoid an external file altogether.
What I find interesting is the possibility of doing other things to other SU windows, so if you click a button, Applescript could get the position and pass that info to a ruby WebDialog that then appears in that spot, hiding the button in the process.
In that WD you could say I want 8 A4 sheets of this drawing, size and zoom the window for accurate printing, and have ruby move camera, save and name image 8 times.more later
john -
Hey Jeff,
lets bump this Applescript stuff and get more people in on the act...
I've been re-reading all the SketchUp Applescript 'google' hits and I think it's time to make it all work.
One of the past problems was no-one seemed to know how to get Applescript to do this sort of thing from INSIDE a ruby script... e.g. »» RUN IN AppleScript Editor
activate application "Sketchup" tell application "System Events" tell process "SketchUp" click menu item "Weld" of menu "Plugins" of menu bar 1 end tell end tell
Although you could get other apps to run from SU using 'osascript' e.g. »» RUN IN Ruby Console
`osascript -e 'activate application "Safari"'`
Previously, as soon as you changed the app to SketchUp you beach-balled...
well, I finally got it working e.g. »» RUN IN RubyrunAppleScript=Thread.new{ `osascript <<EOF activate application "Sketchup" tell application "System Events" tell process "SketchUp" click menu item "Weld" of menu "Plugins" of menu bar 1 end tell end tell EOF ` } runAppleScript.kill
the missing ingredient was a new Thread... and a HEREDOC to simplify the osascript
so where does that all lead us?
if it has a menu item you can activate it from rubyso if you have "Arc: Center and 2 points"
#--# UI;;Toolbar why would you want a custom set of menu items? # def aplscrpt_TB aplscrpt_tb = UI;;Toolbar.new "aplscrpt_TB" # This command when clicked cmd = UI;;Command.new("aplscrpt_TB-Test") { runAppleScript=Thread.new{ `osascript <<EOF activate application "Sketchup" tell application "System Events" tell process "SketchUp" click menu item "Arc; Center and 2 points" of menu "Draw" of menu bar item "Draw" of menu bar 1 end tell end tell EOF ` } runAppleScript.kill } aplscrpt_tb.add_item cmd aplscrpt_tb.show end # aplscrpt_TB # #--#
you can have a button even though it's an encrypted file...
but there's even more we can do with this,
I've worked out how to 'mine' the menu items, and how to 'activate' them from a ruby script, but I'm trying to optimise the parsing to html for use in a 'WebDialog'.
The best way to explain my goal, is a floating 'localised', 'dynamic' menu/toolbar that can be edited (via option boxes) to show only the items you want, and be positioned anywhere, i.e. another monitor.
I use full screen mode alot, and I find getting menu items is a pain. There are only so many shortcut keys I can remember...
Another advantage is it can be 'Stay Open', eg. if you want to check all available camera views in advanced camera tools.
I have made 'html' that looks like a menu, and others that look like toolbar buttons. but I need to full it all together.
and then there's window positioning and sizing, a lot can be gain on using Applescripts strengths from inside ruby...
@ Jeff, if you don't want the highjack, split this to a new thread, but I think it's as good a place as any, mainly cause I like watching RC type itself....
john
Advertisement