I have been developing a Ruby script since 2017. This script is created dynamically in another program and is passed to the SketchUp executable as an argument. This script works in every version of SketchUp (Pro) from 2015 to 2022. In SketchUp Pro 2023, there is some hang up in the view.write_image call. SketchUp indicates that the width and height values I am passing are not between 1 & 16000. I have explicitly set these to various values that all work with previous versions. If I output view.vpwidth to the console, I get an appropriate value in all versions I have tested except 2023 which returns “0”. The goal of my dynamic script is to draw a building designed in another program then create 8 views and export each view to a transparent .png that is then imported by the original program. Again, this works flawlessly in every version of SketchUp (Pro) from 2015 to 2022. If I don’t export images, the buildings generate appropriately. Also, If I call the original script directly from the Ruby Console, the images export appropriately without an error. Can anyone explain why this happens and/or how I might work around it?
Sketchup.active_model.active_view.vpwidth
=> 1498
Sketchup.active_model.active_view.vpwidth
=> 1890
I get the expected value according how I resized the SU Window. ( SU Version 23.1.340. )
Unless you show your code, or an example of code where we can see the behaviour you described, I just guess that perhaps your code have a mistake or SketchUp wasn’t installed properly.
Also from this view:
this code:
options = {
:filename => File.join(Sketchup.temp_dir, 'example.png'),
:width => 1640,
:height => 1480,
:antialias => false,
:compression => 0.9,
:transparent => true
}
model = Sketchup.active_model
view = model.active_view
view.write_image(options)
generated this png:
I have used nearly the identical code to yours. This works fine from the console. That is not what I’m trying to do. As I said, “This script is created dynamically in another program and is passed to the SketchUp executable as an argument.” Try writing the script then passing to your SketchUp executable as an argument via a shortcut or another program. I call the SketchUp executable with the argument: "-RubyStartup " followed by the path to the starter script. If I do this with a script to simply output the vpwidth to the console, I get “0” in SU2023. Again, this method and my script work in all but SU2023. Please, try running your script via a desktop shortcut.
SU2023 now uses Qt as the GUI framework on Windows. Perhaps the interface is taking longer to initialize, and the code runs before it’s ready?
Try delaying your code a bit … see: UI.start_timer
I have already tried “sleep(30)” just before exporting the images. I will try “UI.start_timer” tomorrow and let you know my results. Thank you both very much for your time and knowledge.
My initial testing indicates that using UI.start_timer will fix my problem! Thanks!
For future reference, I was able to test/reproduce this issue with the following script:
SKETCHUP_CONSOLE.show
puts Sketchup.active_model.active_view.vpwidth
Using a shortcut with target:
"C:\Program Files\SketchUp\SketchUp 2023\SketchUp.exe" -RubyStartup "C:\Users\Dave\OneDrive\Desktop\test_script.rb"
In SU2023, this produced “0” in the Ruby Console but a normal integer (such as “1916”) in other versions of SketchUp.
Modifying the script to:
id = UI.start_timer(10, false) {
SKETCHUP_CONSOLE.show
puts Sketchup.active_model.active_view.vpwidth
}
FIXED the issue.
Thank you both very much!