How to attach text to a line
-
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.selectionA = 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) Do not use capital letters for variables.
A
andB
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 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..
Advertisement