# 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' #----------------------------------------------------------------------------- # Default leadertype is Hidden. Apparently all text has a leader. So, why have this API? # This test just looks up all of the numerical values for leaders and arrows # and returns their string representation in SketchUp. This is not part of the # API, but was created to determine the range of return values for some methods. def numbersToTypeTest model = Sketchup.active_model entities = model.entities entity = entities[5] name = entity.typename UI.messagebox name if name == "Text" type = entity.arrow_type UI.messagebox type leader = entity.leader_type UI.messagebox leader end end # 0=none, 2=dot, 3=closed arrow, 4=open arrow def arrowTypeTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point type = text.arrow_type if (type) UI.messagebox type else UI.messagebox type end end # Seems you can set arrow type on non-leader text. def arrowTypeEqualsTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point type = text.arrow_type UI.messagebox type type = text.arrow_type=0 if (type) UI.messagebox type else UI.messagebox type end end # Default Leader Type is Hidden / false def displayLeaderTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point status = text.display_leader? if (status) UI.messagebox status else UI.messagebox status end end # Default Leader Type is Hidden / false def displayLeaderEqualsTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point leader = text.display_leader=true if (leader) UI.messagebox leader else UI.messagebox leader end end def hasLeaderTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point status = text.has_leader? if (status) UI.messagebox status else UI.messagebox status end end # 2=pushpin, 1=viewbased def leaderTypeTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point leader = text.leader_type if (leader) UI.messagebox leader else UI.messagebox leader end end def leaderTypeEqualsTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point leader = text.leader_type UI.messagebox leader leader = text.leader_type=1 if (leader) UI.messagebox leader else UI.messagebox leader end end def lineWeightTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point weight = text.line_weight if (weight) UI.messagebox weight else UI.messagebox weight end end def lineWeightEqualsTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point weight = text.line_weight UI.messagebox weight newweight = text.line_weight=4 if (newweight) UI.messagebox newweight else UI.messagebox newweight end end # returns a text object. The set_text method also does not record an Undo operation, # so this test will only record one Undo operation for the initial add_text method call. def setTextTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point textstring = text.text if (textstring) UI.messagebox textstring else UI.messagebox textstring end text = text.set_text "This is another text" if (text) UI.messagebox text UI.messagebox text.text else UI.messagebox text.text end end def textTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point textstring = text.text if (textstring) UI.messagebox textstring else UI.messagebox textstring end end # This test will record two Undo operations because Text.text= records an # Undo operation as does th einitial add_text method call. def textEqualsTest coordinates = [10, 10, 10] model = Sketchup.active_model entities = model.entities point = Geom::Point3d.new coordinates text = entities.add_text "This is a Test", point textstring = text.text if (textstring) UI.messagebox textstring else UI.messagebox textstring end textstring = text.text="This is another text" if (textstring) UI.messagebox textstring else UI.messagebox textstring end end if( not file_loaded?("texttests.rb") ) # This will add a separator to the menu, but only once add_separator_to_menu("Plugins") plugins_menu = UI.menu("Plugins") TextTest_menu = plugins_menu.add_submenu("Text Tests") TextTest_menu.add_item("Numbers To Type") { numbersToTypeTest } TextTest_menu.add_item("Text.arrow_type") { arrowTypeTest } TextTest_menu.add_item("Text.arrow_type=") { arrowTypeEqualsTest } TextTest_menu.add_item("Text.has_leader?") { hasLeaderTest } TextTest_menu.add_item("Text.display_leader=") { displayLeaderEqualsTest } TextTest_menu.add_item("Text.display_leader?") { displayLeaderTest } TextTest_menu.add_item("Text.leader_type") { leaderTypeTest } TextTest_menu.add_item("Text.leader_type=") { leaderTypeEqualsTest } TextTest_menu.add_item("Text.line_weight") { lineWeightTest } TextTest_menu.add_item("Text.line_weight=") { lineWeightEqualsTest } TextTest_menu.add_item("Text.set_text") { setTextTest } TextTest_menu.add_item("Text.text") { textTest } TextTest_menu.add_item("Text.text=") { textEqualsTest } end #----------------------------------------------------------------------------- file_loaded("texttests.rb")