Announcements

We are currently experiencing an issue impacting some Autodesk Products and Services - please refer to the Autodesk Health Dashboard for updates.

Move or offset text off of a line

Move or offset text off of a line

Anonymous
Not applicable
6,697 Views
8 Replies
Message 1 of 9

Move or offset text off of a line

Anonymous
Not applicable

I am drafting in AutoCad. The .dwg we get is from MicroSurvey, a specialized Cad program specific for surveying. One of the main things I am doing is resizing and formating text from Microsurvey. I change the Syle and hieght. The text is all on the line. 

 

The text is not annotative at all. It is not linked to the line at all. It is rotated and centered on the the line however. 

 

Right now I am just grabbing the grips and moving the text off the line. It is very tedius and the distance is not the same everytime. 

 

Is there a simple way to select the text and have it automatically move (perpindicular to the line) a set amount? 

 

I am not sure in DIMSCALE will help as they are not demensions so to speak. 


Any help woul be greatly appreciated. 

 

Cheers.

 

0 Likes
Accepted solutions (1)
6,698 Views
8 Replies
Replies (8)
Message 2 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... The text is all on the line. 

.... It is rotated and centered on the the line .... 

.... 

Is there a simple way to select the text and have it automatically move (perpindicular to the line) a set amount? 

.....


How 'bout this?

 

(defun C:MTOL (); = Move Text Off Line
  (setq ss (ssget ":L" '((0 . "TEXT")))); User selection
  (repeat (setq n (sslength ss))
    (setq txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
    (vla-put-TextAlignmentPoint txtobj
      (vlax-3d-point
        (polar
          (vlax-get txtobj 'TextAlignmentPoint); initial insertion point
          (+ (vla-get-Rotation txtobj) (/ pi 2)); perpendicular upward in relation to Text rotation
          (vla-get-Height txtobj)
        ); polar
      ); vlax-3d-point
    ); vla-put...
  ); repeat
); defun

 

It moves it by its own height, which seemed to me a reasonable amount, assuming that you mean it's "centered on the Line" in both directions [Middle or Middle Center justification].  If it's really just Centered [base sitting on the Line], try using

          (/ (vla-get-Height txtobj) 2)

for the amount to move it.  Experiment with multipliers/dividers on that height to fine-tune how far it moves them.

 

That also assumes just Text objects, not Mtext, but you can do both with

  (setq ss (ssget ":L" '((0 . "*TEXT"))))

for the selection.

 

None of the usual enhancements yet, but see whether it works.

Kent Cooper, AIA
Message 3 of 9

Anonymous
Not applicable

That seems to work very well. Thank you. 

 

To modify the amount it moves off, say half of its own hieght, how would you add that in? 

 

So the text is a bearing and a distance on a line. The top piece is Center Justification, the bottom piece is Top Center. They are TEXT, not MTEXT.

 

We might be able to change, in Microsuvey what the defualt justifications are, so the Lisp runs more easily. 

 

Thanks for looking into this for me. Greatly appreciated. 

 

 

2015-04-27_10h42_35.png

0 Likes
Message 4 of 9

Anonymous
Not applicable
Oh I figured out how to change the adjust the height. Just needed to re-read your original post. Cheers!
0 Likes
Message 5 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

So the text is a bearing and a distance on a line. The top piece is Center Justification, the bottom piece is Top Center. .... 


I can imagine a way that you could select all of those Text objects at once, and have the bearings all move upward, and the distances all move downwatd, so you wouldn't need to have a separate routine for each.  It would be a matter of looking at their content, and whether it contains a degree symbol.  Would that be worth pursuing, and if so, do they use AutoCAD's typical "%%d" stand-in for the degree symbol?

Kent Cooper, AIA
Message 6 of 9

Anonymous
Not applicable

Yes thats correct. It is the %%D. Sometimes the bearing are on one side of the line and sometimes they are on the other side. 

 

I tried messing around with settings in Microsurvey, but making it readable in Autocad makes it unreadable in microsurvey. So that won't work. The text hieght is really small in MS so you can read the text, as there is often tons of lines and text.

 

Thanks again!

 

Todd 

0 Likes
Message 7 of 9

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

Yes thats correct. It is the %%D. Sometimes the bearing are on one side of the line and sometimes they are on the other side. ....


If they're starting with their insertion points on the Line/Pline, regardless of which of them is on which side, this seems to relocate them with the bearing always on top, in minimal testing:

 

(defun C:MTOL (/ ss txtobj brg); = Move Text Off Line
  (setq ss (ssget ":L" '((0 . "TEXT")))); User selection
  (repeat (setq n (sslength ss))
    (setq
      txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n))))
      brg (wcmatch (strcase (vla-get-TextString txtobj)) "*%%D*")
        ; = T for bearing, nil for distance
    ); setq
    (vla-put-Alignment txtobj (if brg 1 7))
      ; center for bearing, top-center for distance
    (vla-put-TextAlignmentPoint txtobj
      (vlax-3d-point
        (polar
          (vlax-get txtobj 'TextAlignmentPoint); initial insertion point
          ((if brg + -) (vla-get-Rotation txtobj) (/ pi 2))
            ; direction upward for bearing, downward for distance
          (/ (vla-get-Height txtobj) 2)
        ); polar
      ); vlax-3d-point
    ); vla-put...
  ); repeat
); defun

 

MTOL.png

 

If you'd rather keep whichever starts on top there, the determination of which way to go could be based on their Alignment property [which it would leave alone] rather than on their content.

Kent Cooper, AIA
Message 8 of 9

Anonymous
Not applicable

This works very well. There would be some instances where we would want the bearing and distance to remian on the side they originated. It would not always be used however. I am thinking a second routine to swap the text might work. This seems to do the trick http://www.lee-mac.com/copytext.html

 

 

Thanks again for all your help!

0 Likes
Message 9 of 9

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:
.... 

If you'd rather keep whichever starts on top there, the determination of which way to go could be based on their Alignment property [which it would leave alone] rather than on their content.


That takes less code, because it imposes only one new Property on the Text object:

 

(defun C:MTOL (/ ss txtobj); = Move Text Off Line
  (setq ss (ssget ":L" '((0 . "TEXT")))); User selection
  (repeat (setq n (sslength ss))
    (setq txtobj (vlax-ename->vla-object (ssname ss (setq n (1- n)))))
    (vla-put-TextAlignmentPoint txtobj
      (vlax-3d-point
        (polar
          (vlax-get txtobj 'TextAlignmentPoint); initial insertion point
          ((if (= (vla-get-Alignment txtobj) 7) - +) (vla-get-Rotation txtobj) (/ pi 2))
            ; direction downward for top-center, upward otherwise
          (/ (vla-get-Height txtobj) 2)
        ); polar
      ); vlax-3d-point
    ); vla-put...
  ); repeat
); defun

 

That actually "fits" the command name a little better than the earlier one.  If you want both available, give one of them a different command name.

Kent Cooper, AIA