• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Add a text on a point

Scheduled Pinned Locked Moved Plugins
7 Posts 2 Posters 866 Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    Pauline01
    last edited by 18 Jan 2010, 12:52

    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
    
    
    
    1 Reply Last reply Reply Quote 0
    • T Offline
      thomthom
      last edited by 18 Jan 2010, 12:59

      Entities.add_text
      http://code.google.com/intl/nb/apis/sketchup/docs/ourdoc/entities.html#add_text

      Thomas Thomassen — SketchUp Monkey & Coding addict
      List of my plugins and link to the CookieWare fund

      1 Reply Last reply Reply Quote 0
      • P Offline
        Pauline01
        last edited by 18 Jan 2010, 13:00

        ok thx

        1 Reply Last reply Reply Quote 0
        • T Offline
          thomthom
          last edited by 18 Jan 2010, 13:07

          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)

          Thomas Thomassen — SketchUp Monkey & Coding addict
          List of my plugins and link to the CookieWare fund

          1 Reply Last reply Reply Quote 0
          • P Offline
            Pauline01
            last edited by 18 Jan 2010, 14:20

            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")
             
             
            end
            
            
            

            Second 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
            
            
            
            1 Reply Last reply Reply Quote 0
            • T Offline
              thomthom
              last edited by 18 Jan 2010, 14:28

              
                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
              
              

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • P Offline
                Pauline01
                last edited by 18 Jan 2010, 14:32

                i test, thx

                IT'S, OK. really thx

                1 Reply Last reply Reply Quote 0
                • 1 / 1
                1 / 1
                • First post
                  1/7
                  Last post
                Buy SketchPlus
                Buy SUbD
                Buy WrapR
                Buy eBook
                Buy Modelur
                Buy Vertex Tools
                Buy SketchCuisine
                Buy FormFonts

                Advertisement