• Login
sketchucation logo sketchucation
  • Login
🔌 Quick Selection | Try Didier Bur's reworked classic extension that supercharges selections in SketchUp Download

How to attach text to a line

Scheduled Pinned Locked Moved Developers' Forum
3 Posts 2 Posters 520 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 5 Sept 2014, 07:33

    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
    • D Offline
      Dan Rathbun
      last edited by 30 Sept 2014, 03:08

      (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 20 Oct 2014, 14:48

        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