Close Google SketchUp File

The Ruby API for Google SketchUp has a function open_file, but I cannot find the function close_file. Since I have to process many files, I want to close each file before moving on to the next one, otherwise the program will crash due to running out of memory.

How can programmatically close SketchUp files?

I am using Mac OS X and am ready to use AppleScript features to signal that the window is closing.

EDIT

I am considering several approaches that have so far proven fruitless.

  • Using the Ruby Ruby Descriptor as described in this question . The problem here is that I cannot get SketchUp to recognize my installed gems .
  • In the same vein, I'm trying to use osascript (a bash program that runs AppleScripts from a shell) to close a window. That is, I call the shell from the SketchUp Ruby console window using one of the following actions:

    % x [osascript -e "tell SketchUp to close window 1 ']

    % x [osascript -e "tell SketchUp to close window 1 '&]

    % x [osascript -e "tell SketchUp to close each window ']

    % x [osascript -e 'tell SketchUp to close each window' &]

    , , SketchUp . , IRB bash SketchUp, : (, Ruby , ).

  • script, script . Google SketchUp, . , , SketchUp. , drb. , drb SketchUp, :

: LoadError: (eval): 5: in 'require': - drb

2

, Sketchup Google, AppleScript, , . -, , Sketchup. -, script , , .

, Sketchup AppleScript. script Sketchup, , , AppleScript, , osascript . Sketchup AppleScript, Sketchup , script.

3

close_file, script, . AppleScript :

def close_file()
  f = '/temp/mutex.txt' # for finer control, use different mutex for each window you want closed
  File.new(f, 'w').close
  result = UI.messagebox "Click OK when window has closed."
end

ruby ​​ script, AppleScript, "" . AppleScript :

tell application "System Events"
    tell process "SketchUp"
        set frontmost to true
        keystroke return
    end tell
end tell

. " ", EDIT 2, .

+1
4

, Sketchup Google, AppleScript, . (drb, , ).

-, , Sketchup AppleScripting. ( Sketchup ..):

$ defaults write /Applications/Google\ SketchUp\ 8/SketchUp.app/Contents/Info NSAppleScriptEnabled -bool YES

, Sketchup. closer.rb:

#!/usr/bin/ruby

## closer.rb ##

def wait(f)
  while !File::exists?(f)
  end 
  File.delete(f)
end

def signal(f)
  File.new(f, 'w').close
end

while true
  wait('~/temp/mutex.txt')
  msg = %x[osascript -e 'tell application "SketchUp" to close every window'] 
  signal('~/temp/conf.txt')
end

script . , ~/temp/mutex.txt. osascript ( , AppleScript), Sketchup, , , ~/temp/conf.txt.

( Sketchup), script:

def wait(f)
  while !File::exists?(f)
  end 
  File.delete(f)
end

def signal(f)
  File.new(f, 'w').close
end

def close_file
  signal('~/temp/mutex.txt')
  wait('~/temp/conf.txt')
end

close_file script, , . Sketchup.

0

AppleScript SketchUp. SketchUp , script.

, . , WebDialog, . cURL . , , cURL .

AppleScript ( mutex, ) . , script , SketchUp -, AppleScript. , script, AppleScript .

, AppleScript , . , ( , , AppleScript , script).

- mutex() Ruby code. AppleScript , mutex "I'm done", wait() Ruby , . AppleScript SketchUp, SketchUp (, , wait()).

, AppleScript , , .

+2

SketchUp applescript / Automator.

tell application "SketchUp"
activate
tell application "System Events"
    delay 1.0 --close window, adjust delay to suit
    --key code 13 using command down -- Press ⌘W or you can use
    keystroke "w" using command down
end tell

end tell

, , , SU ..

, SU , "Ruby Console" .

, " " , Automator v5, V6, v7 v8 ... 100 , , , , , , ( , ).

"" .

, applescript , , " ", , .

/ 'Script Editor', 'dowithTimeout', .

, , 95%. [ , , .]

, , , .

0

, Ruby Console system("osascript -e 'tell application \"suoff\"' -e 'activate' -e 'end tell'")   script Automator.app ....

    on run
    -- Make sure SU is foremost, don't click on anything else either
    tell application "System Events"
    tell process "SketchUp"
        set frontmost to true
        -- gives a message if you try to select when SU not running
        delay 0.2
        tell application "SketchUp" to quit saving no
        -- no dialog box etc...
        delay 0.1

    end tell
    end tell
    end run

the problem is that SU has an anti-self-destructing ruby ​​that will mine any associated files and interrupt all efforts to close it ... from the inside.

so you need to bury him ...

this combination works on 10.5.8 with SU8.1.

If you look at the SketchUcation [Developer] forum, I left a call for mac / applescript testers ... I have rewritten the application since then, but if you write to me, I will send you an open copy of all the bits that I have.

John

0
source

Source: https://habr.com/ru/post/1791807/


All Articles