# Copyright 2005, @Last Software, Inc. # This software is provided as an example of using the Ruby interface # to SketchUp. # Permission to use, copy, modify, and distribute this software for # any purpose and without fee is hereby granted, provided that the above # copyright notice appear in all copies. # THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. #----------------------------------------------------------------------------- require 'sketchup.rb' # Th PickHelper class has methods that are generally used within the context of a Tool # that you create by implementing the Tool interface. Basically, you need screen # coordinates when doing a pick and those are passed to the various Tool methods, such # onLButtonDown. class InputPointToolTests # Called when you select the tool def activate puts "activate called" @status = 0 depth = 100 width = 100 model = Sketchup.active_model entities = model.active_entities pts = [] pts[0] = [0, 0, 0] pts[1] = [width, 0, 0] pts[2] = [width, depth, 0] pts[3] = [0, depth, 0] # Add the face to the entities in the model face = entities.add_face pts face.pushpull 100 end # Called when I select another tool or quit SketchUp def deactivate(view) puts "deactivate called" end def onLButtonDown(flags, x, y, view) case @status # First left click we test ==. Click # on one of the corners of the box and you will get 6 or 7 items # picked. when 0 ip1 = Sketchup::InputPoint.new ip2 = view.inputpoint x,y # Copy the contents of inputpoint2 into inputpoint1 ip1.copy! ip2 # Returns true status = ip1 == ip2 if (status) UI.messagebox status else UI.messagebox "Failure" end @status +=1 when 1 ip1 = view.inputpoint x,y # Returns true ip = ip1.clear if (ip) UI.messagebox ip else UI.messagebox "Failure" end @status +=1 when 2 ip1 = Sketchup::InputPoint.new ip2 = view.inputpoint x,y # Copy the contents of inputpoint2 into inputpoint1 ip = ip1.copy! ip2 if (ip) UI.messagebox ip else UI.messagebox "Failure" end @status +=1 when 3 ip1 = view.inputpoint x,y dof = ip1.degrees_of_freedom if (dof) UI.messagebox dof else UI.messagebox "Failure" end @status +=1 when 4 ip1 = view.inputpoint x,y d = ip1.depth if (d) UI.messagebox d else UI.messagebox "Failure" end @status +=1 when 5 ip1 = view.inputpoint x,y status = ip1.display? # Returning true if (status) UI.messagebox status else UI.messagebox "Failure" end @status +=1 when 6 ip1 = view.inputpoint x,y ip = ip1.draw view if (ip) UI.messagebox ip else UI.messagebox "Failure" end @status +=1 when 7 ip1 = view.inputpoint x,y e = ip1.edge if (e) UI.messagebox e else UI.messagebox "Failure" end @status +=1 when 8 ip1 = view.inputpoint x,y f = ip1.face if (f) UI.messagebox f else UI.messagebox "Failure" end @status +=1 when 9 ip1 = view.inputpoint x,y # Why is this failing? s = ip1.pick view, x, y if (s) UI.messagebox s else UI.messagebox "Failure" end @status +=1 when 10 ip1 = view.inputpoint x,y point = ip1.position if (point) UI.messagebox point else UI.messagebox "Failure" end @status +=1 when 11 ip1 = view.inputpoint x,y # Click on a face and you get On Face tip = ip1.tooltip if (tip) UI.messagebox tip else UI.messagebox "Failure" end @status +=1 when 12 ip1 = view.inputpoint x,y # In this case, returning the identity transformation tform = ip1.transformation if (tform) UI.messagebox tform else UI.messagebox "Failure" end @status +=1 when 13 ip1 = view.inputpoint x,y status = ip1.valid? if (status) UI.messagebox status else UI.messagebox "Failure" end @status +=1 when 14 ip1 = view.inputpoint x,y vertex = ip1.vertex if (vertex) UI.messagebox vertex else UI.messagebox "Failure" end @status +=1 end end end # end of class InputPointToolTests # Add a menu choice for viewtooltests if( not file_loaded?("intputpointtooltests.rb") ) plugins_menu = UI.menu("Plugins") plugins_menu.add_item("InputPointToolTests") { Sketchup.active_model.select_tool InputPointToolTests.new } end