home *** CD-ROM | disk | FTP | other *** search
/ Freelog 100 / FreelogNo100-NovembreDecembre2010.iso / Graphisme / GoogleSketchUp / GoogleSketchUpWFR.exe / GoogleSketchUp8.msi / SketchUpMeta.cab / contextmenu.rb.78D17A5F_0E0A_44D2_877D_2C56D45D16B7 < prev    next >
Encoding:
Text File  |  2010-08-26  |  2.1 KB  |  62 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 'sketchup.rb'
  16.  
  17. #-----------------------------------------------------------------------------
  18.  
  19. # This example shows how you can add new menu items to context
  20. # menus from Ruby.  It will add an item to the context menu to create
  21. # a point at the center of an arc or circle when you right click on it.
  22.  
  23. # First we will define a couple of functions to determine if an arc is
  24. # selcted and to do the actual work.
  25.  
  26. # This function checks to see if the selection contains a single arc.  If
  27. # so it returns the arc, otherwise it returns nil
  28. def selected_arc
  29.     ss = Sketchup.active_model.selection
  30.     return nil if not ss.is_curve?
  31.     edge = ss.first
  32.     return nil if not edge.kind_of? Sketchup::Edge
  33.     curve = edge.curve
  34.     return nil if not curve.kind_of? Sketchup::ArcCurve
  35.     curve
  36. end
  37.  
  38. # Create a construction point at the center of a selected arc
  39. def create_point_at_selected_arc_center
  40.     point = nil
  41.     arc = selected_arc
  42.     if( arc )
  43.         point = Sketchup.active_model.active_entities.add_cpoint arc.center
  44.     end
  45.     point
  46. end
  47.  
  48. # Now add a new context menu handler.  You supply UI.add_context_menu_handler
  49. # with a block that takes a menu as its only argument.  The handler can add
  50. # new items to the menu as needed.
  51. # Make sure that we add the handler only once.
  52. if( not file_loaded?("arccontextmenu.rb") )
  53.     UI.add_context_menu_handler do |menu|
  54.         if( selected_arc )
  55.             menu.add_separator
  56.             menu.add_item($exStrings.GetString("Point at Center")) { create_point_at_selected_arc_center }
  57.         end
  58.     end
  59. end
  60.     
  61. file_loaded("arccontextmenu.rb")
  62.