Text - Offset new Text from Existing

Text - Offset new Text from Existing

JGranata_GdB
Enthusiast Enthusiast
1,432 Views
3 Replies
Message 1 of 4

Text - Offset new Text from Existing

JGranata_GdB
Enthusiast
Enthusiast

Hello all. 

 

I am looking for a way so that the user selects text (Mtext or dtext), Enters in new text and then the text is inserted below the selected text insertion point, with the same rotation(orientation). 

 

I know the basics about AutoLISP, but i have not spent alot of time looking into it. 

 

Is there a way to change the initial selected text to Bottom Right Justification? 

How can I grab the values of text height, rotation, layer, text style and insertion point from the selected text? 

How do I assign the values for rotation, layer, style height, for the new text? 

 

I can work out the new insertion point based off the grabbed values from the selected text insertion point, rotation and height. (Yah, High School Trig! ) 

I am confident in my ability to use the getstring to grab the input for text and combine it with a predefined prefix and using the insertion value and string vale to populate the text. 

 

IE. 
(old Text)                  5004.9' 

(New Text)    Map = 5005.0'

 

 

 

 

 

0 Likes
1,433 Views
3 Replies
Replies (3)
Message 2 of 4

Kent1Cooper
Consultant
Consultant

You can use MakeMore.lsp with its MM command, available here, for most of that.  In the case of Text, it extracts the Layer, Style, Justification, Height, Rotation -- all of that, and even Width factor -- from the selected Text object, and offers you a choice between making more anywhere you choose [the New-insertion-point option] or doing another below just as you describe [the Continuation option].  From those elements, you should be able to take what you need -- just look at the area beginning with the line:

    ((= typ "TEXT")

 

It doesn't change the justification, but there are other routines that will do so without repositioning it [this is one, though I haven't tried it].  Maybe you can combine something like that in with MM functionality if necessary, along with editing to build your new text content instead of having to type it in.

 

In the case of Mtext, do you need to make another Mtext object?  Can you just go to the end [manually, with Ctrl+End], hit Enter to move down a line, and just continue?  A routine could certainly be made to add a constructed line in the automated equivalent of that, without starting another Mtext.

Kent Cooper, AIA
0 Likes
Message 3 of 4

JGranata_GdB
Enthusiast
Enthusiast

Thank you for the tip Mr. Cooper. I will take a look at the MM command tomorrow, as I do not have the time to look at it today.

 

Yes i would like a new dtext or Mtext to be placed down. I should have been clearer in my initial post.

The work environment calls for this to be done on a case by case basis, and this will probably be placed as a button on a toolbar or the command entered for one text at a time.

 

I would like the user to select the existing text (regardless if it's Dtext or Mtext), and enter a string input (such as "Enter value read from description").

I would like the LISP, from the selected text and entered string, to create a new text object (either Mtext or Dtext, the type of which does not matter) with the same rotation, height, and bottom right justification placed at a newly calculated point based off the selected texts insertion point, height and rotation, with a predefined prefix and the user inputted text. 

 

Like I initially mentioned, I am confident in my ability to calculate the new insertion point. I also am confident in my ability to use the "-text" to input the text with bottom right justification, new location, rotation, and height. (I know this probably isn't the best way to place down text, as it doesn't copy the style, layer and other properties). What I am unsure of is:

1) How to change the original text to be bottom right justified. I was thinking using the JustifyText command, but I am unsure of how to include this into the program so that the user only has 1 mouse click and 1 input for the routine. 

 

2) How to grab the values I need from the initially selected text. These values specifically being rotation, text height and insertion location. 

 

Ideally, matching the layer and style would be a bonus, but just placing the text at the correct location, and the correction rotation would be sufficient. 

 

I have added a screenshot of an example (better than my attempt to do it in just the text window from above). What is above the line is the initial text that exists in the drawing, what is below the line is what i want the lisp to be able to place down. 

 

0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

Didn't read whole your story... try this routine. I'm not using this much, but i may help you. I was just a quick foo, didn't bother with MTEXT at the time, because their angle definition is screwed up.

 

 

Spoiler
(defun c:AL ( / *error* oldOSMODE pnt) ;ADD LINE 

  (defun *error* (errmsg)
      (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break"))
	(princ (strcat "\nError: " errmsg)))
      (setvar 'OSMODE oldOSMODE)
      (princ)
    ); end defun - *error*

  (setq oldOSMODE (getvar 'OSMODE))
  (setvar 'OSMODE 0)
  
  (if (setq ss (ssget "_+.:E:S" '((0 . "TEXT,ATTDEF"))))
    (progn
      (setq pnt (polar '(0 0 0)
		       (+ (cdr (assoc 50 (entget (ssname ss 0)))) 	;angle of selected text
			  (* 1.5 pi) 					;turn -90°
			  (* -1 (angle '(0 0 0) (getvar 'UCSXDIR))))	;count UCS
		       (* 1.5						;new line 1.5x
			  (cdr (assoc 40 (entget (ssname ss 0)))))))	;texthigt
      (command "_.copy" ss "" '(0 0 0) pnt)
      (setvar 'OSMODE oldOSMODE)
      (command "_textedit" (entlast))))
    
  (princ)
)
0 Likes