Add a text on a point
-
Re re hello,

I try to add on my group a text.
The text will be contain the string of "adrresult"(see in my code).
I have somes things but...
In my code i want complete after : " #i want to associate the position of my text on a point
#???? position_point_of_my_text = text.point "and
" # text=addresult
#??? textstring = text.text= addresult "thx again...
require 'sketchup.rb' class Vsx @@Obj = nil end def add_etiquette # Get "handles" to our model and the Entities collection it contains. model = Sketchup.active_model entities = model.entities # Create a series of "points", each a 3-item array containing x, y, and z. pt1 = [0, 0, 0] pt2 = [30, 0, 0] pt3 = [30, 0, 17] pt4 = [0, 0, 17] # Call methods on the Entities collection to draw stuff. # new_face = entities.add_face pt1, pt2, pt3, pt4 group = entities.add_group group.entities.add_face(pt1,pt2,pt3,pt4) #i want to associate the position of my text on a point #???? position_point_of_my_text = text.point prompt = ["Zone Name"] val = group.get_attribute("MyDico", "Name_zone") default = [val] result = UI.inputbox prompt, default, "Enter the Zone Name" adrresult = result[0].to_s group.set_attribute("MyDico", "Name_zone", adrresult.to_s) UI.messagebox ("@ ; " + adrresult.to_s + " saved") # text=addresult #??? textstring = text.text= addresult end #Menu if (not file_loaded?("zEtiquette_config.rb")) tool_menu = UI.menu "Tools" tool_menu.add_item("Create zone item") { add_etiquette } $VSX = Vsx.new file_loaded("zEtiquette_config.rb") end -
-
ok thx
-
note that the third argument is optional. so you only need to spesofy the point and text. something like:
group.entities.add_text('myText', position_point_of_my_text) -
ok, now i want can change my text contained in a group.
In my second plugin, i have a menu to change "Name_zone" of the object selected.
I can't change the 2D text of my object, because it contained in a group of entities.
In my second plugin i want do this after "#I wish change my 2D text in the object selected
#??? "It's possible or i delete my object and i create a new?
My code who associate my text in a group of entities.
thx again and again. I'am begining...
First plugin:
def add_etiquette # Get "handles" to our model and the Entities collection it contains. model = Sketchup.active_model entities = model.entities # Create a series of "points", each a 3-item array containing x, y, and z. pt1 = [0, 0, 0] pt2 = [30, 0, 0] pt3 = [30, 0, 17] pt4 = [0, 0, 17] coordinates = [0, 0, 8.5] # Call methods on the Entities collection to draw stuff. # new_face = entities.add_face pt1, pt2, pt3, pt4 group = entities.add_group point = Geom;;Point3d.new coordinates group.entities.add_face(pt1,pt2,pt3,pt4) prompt = ["Zone Name"] val = group.get_attribute("MyDico", "Name_zone") default = [val] result = UI.inputbox prompt, default, "Enter the Zone Name" adrresult = result[0].to_s group.set_attribute("MyDico", "Name_zone", adrresult.to_s) group.entities.add_text adrresult.to_s, point UI.messagebox ("@ ; " + adrresult.to_s + " saved") endSecond plugin:
def zonename prompt = ["Name"] val = Sketchup.active_model.selection[0].get_attribute("MyDico", "Name_zone") default = [val] result = UI.inputbox prompt, default, "Enter the Zone Name" adrresult = result[0].to_s adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "Name_zone", adrresult.to_s) #I wish change my 2D text in the object selected text=adrresult #??? UI.messagebox ("@ ; " + adr.to_s + " saved") end #Menu if (not file_loaded?("zEtiquette_config2.rb")) UI.add_context_menu_handler do |menu| if (Sketchup.active_model.selection.length == 1) menu.add_separator if ((Sketchup.active_model.selection[0].get_attribute("MyDico", "Name_zone")) != nil) menu.add_item("Change Zone Name (@" + Sketchup.active_model.selection[0].get_attribute("MyDico", "Name_zone").to_s + ")") { zonename } end end end $VSX = Vsx.new file_loaded("zEtiquette_config2.rb") end -
adr = Sketchup.active_model.selection[0].set_attribute("MyDico", "Name_zone", adrresult.to_s) #I wish change my 2D text in the object selected text=adrresult #??? # Interate over the content of the selected group and find the first Text object. # Once we have found that we can change it's text. group = Sketchup.active_model.selection[0] myText = nil group.entities.each { |e| if e.is_a?(Sketchup;;Text) myText = e break end } myText.text = adrresult -
i test, thx
IT'S, OK. really thx
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register LoginAdvertisement