home *** CD-ROM | disk | FTP | other *** search
/ Freelog 100 / FreelogNo100-NovembreDecembre2010.iso / Graphisme / GoogleSketchUp / GoogleSketchUpWFR.exe / GoogleSketchUp8.msi / SketchUpMeta.cab / sketchup.rb.78D17A5F_0E0A_44D2_877D_2C56D45D16B7 < prev    next >
Encoding:
Text File  |  2010-08-26  |  4.3 KB  |  114 lines

  1. # Copyright 2005-2008, Google, Inc.
  2.  
  3. # This software is provided as an example of using the Ruby interface
  4. # to SketchUp.
  5.  
  6. # Permission to use, copy, modify, and distribute this software for 
  7. # any purpose and without fee is hereby granted, provided that the above
  8. # copyright notice appear in all copies.
  9.  
  10. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
  11. # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  12. # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  13. #-----------------------------------------------------------------------------
  14.  
  15. require 'langhandler.rb'
  16. $suStrings = LanguageHandler.new("gettingstarted.strings")
  17.  
  18. # This file defines a number of useful utilities that are used by other
  19. # Ruby scripts.
  20.  
  21. #-----------------------------------------------------------------------------
  22. # These functions are used to help with adding new menu items from a
  23. # script.  The function file_loaded? is used to tell if the file
  24. # has already been loaded.  If it returns true, then you should not
  25. # add new menu items.  It is useful to allow you to reload a file
  26. # while you are testing it without having to restart SketchUp and without
  27. # Having it add new menu items every time it is loaded.
  28.  
  29. # This array keeps track of loaded files.  It is like the Ruby variable $"
  30. # that is set by require, but it is not set automatically.  You have
  31. # to call file_loaded to add a filename to the array
  32. $loaded_files = [] unless $loaded_files
  33.  
  34. # Call this method to see if a file is already loaded.
  35. def file_loaded?(filename)
  36.     $loaded_files.include? filename.downcase
  37. end
  38.  
  39. # Call this function at the end of a file that you are loading to
  40. # let the system know that you have loaded it.
  41. def file_loaded(filename)
  42.     $loaded_files.push(filename.downcase) if not $loaded_files.include?(filename.downcase)
  43. end
  44.  
  45. #-----------------------------------------------------------------------------
  46. # This function will add a separator to a given menu the first
  47. # time it is called.  It is useful for adding a separator before
  48. # the first plugin that is added to a given menu
  49. $menu_separator_list = []
  50. def add_separator_to_menu(menuname)
  51.     if( not $menu_separator_list.include?(menuname) )
  52.         UI.menu(menuname).add_separator
  53.         $menu_separator_list.push menuname
  54.     end
  55. end
  56.  
  57. # This is a wrapper for UI.inputbox.  You call it exactly the same
  58. # as UI.inputbox.  UI.inputbox will raise an exception if it can't
  59. # convert the string entered for one of the values into the right type.
  60. # This method will trap the exception and display an error dialog and
  61. # then prompt for the values again.
  62. def inputbox(*args)
  63.     results = nil
  64.     begin
  65.         results = UI.inputbox *args
  66.     rescue
  67.         UI.messagebox $!.message
  68.         retry
  69.     end
  70.     results
  71. end
  72.  
  73. #-----------------------------------------------------------------------------
  74. # By default, SketchUp automatically loads (using require) all files with
  75. # the .rb extension in the plugins directory.  This function can be used
  76. # to automatically load all .rb files from a different directory also.  to
  77. # use this add a call like the following to a file in the plugins directory
  78. # require_all "MyRubyScripts"
  79. def require_all(dirname)
  80.     begin
  81.         rbfiles = Dir[File.join(dirname, "*.{rb,rbs}")]
  82.         $:.push dirname
  83.         rbfiles.each {|f| Sketchup::require f}
  84.     rescue
  85.         puts "could not load files from #{dirname}"
  86.     end
  87. end
  88.  
  89. #-----------------------------------------------------------------------------
  90. # This global method is called by the Ruby Console menu item. We call this
  91. # instead of directly calling Sketchup.send_action("showRubyPanel:") so that
  92. # other Ruby Console implementations can hijack this method.
  93. def show_ruby_panel()
  94.   Sketchup.send_action("showRubyPanel:")
  95. end
  96.  
  97. # Add some Ruby specific menu items
  98. if( not file_loaded? "sketchup.rb" )
  99.  
  100.   # Add a choice to the Window menu to display the Ruby console
  101.   add_separator_to_menu("Window")
  102.   UI.menu("Window").add_item($suStrings.GetString("Ruby Console")) do
  103.     show_ruby_panel()
  104.   end
  105.  
  106.   # Add "Ruby Help" to the Help menu
  107.   # help_url = Sketchup.get_i18n_datfile_info('HELP_RUBY', 'http://sketchup.google.com/gsu6/help/ruby.html');
  108.   # UI.menu("Help").add_item($suStrings.GetString("Ruby Help")) {UI.openURL(help_url)}
  109.   # add_separator_to_menu("Help")
  110.  
  111.   file_loaded "sketchup.rb"
  112. end
  113.  
  114.