sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    How to attach text to a line

    Scheduled Pinned Locked Moved Developers' Forum
    3 Posts 2 Posters 543 Views 2 Watching
    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
      penpendrum
      last edited by

      I want to attach a text to a line and the text would follow the line even if I move or rotate it.
      I also want the text to become smaller when I zoom out if this is possible. .
      I it also possible for the text not to follow the camera angle?
      I know that this is easy if we will just click the text button and then click on the line.

      but how do I do this with ruby scripts?

      I tried to write this script but this does not seem to give me my desired result:

      here is my ruby script:

      model = Sketchup.active_model
      entities = model.entities
      selection = model.selection

      A = entities[0].end.position

      B = entities[0].start.position

      coordinates = [(A.x+B.x)/2,(A.y+B.y)/2,(A.z+B.z)/2]
      point = Geom::Point3d.new coordinates
      text = entities.add_text "Tae", point,[0,2,5]

           text.display_leader= false
      

      please bare with me I am just a newbie ruby programmer: πŸ˜„

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        (1) Do not use capital letters for variables. A and B become constants which are also class and module names.

        (2) code within your own unique namespace module, and separate your various plugins into sub-modules.

        module Penpendrum
          module TextWizard
        
            # code goes in here
        
          end # sub-module
        end # module
        

        (3) Create an empty group
        grp = entities.add_group

        (4) Add your edge and text into the group's entities
        grp.entities.add_line(start,end)
        Then calc the midpoint coordinates

        (5) use 3Dtext instead of a text callout
        text = grp.entities.add_group text.entities.add_3d_text("Tae",TextAlignCenter,"Arial",true, false, 1.0) text.transform!(coordinates)

        Your object is a group with an edge, and a 3d text sub-group (with the 3D text primitives inside it.)

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • P Offline
          penpendrum
          last edited by

          I'm sorry I have tried that .. but that is not what is in my mind.. I just want the text to follow the line even if I move one point only . . doing this manually is possible.. but not for ruby scripts I think..

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

          Advertisement