@tiwari1211 wrote:
....Yes, the remaining bottom lines are result of Enter(s). So what i need is to copy only the first line.
Also before doing paste if i have option to enter the text height. this will be great. ....
Here's a fairly quickie approach, lightly tested:
;| CopyMTextLine1.lsp [command name: CMTL1]
To Copy Mtext only up to the first Enter [if any] encountered, with
specification of [new] height, offering current height as default.
Creates new Mtext with [if containing Enter(s)] truncated content,
on same Layer, with same justification, etc., and leaves User in
Move command to specify new location.
If Mtext contains no Enter(s), simply Copies it [with new height if
specified].
NOTE: Width of defining Mtext box is NOT changed, so if height
is increased, word wrapping can occur in result, or if original had
new lines from word wrapping before Enter(s), word wrapping
can change.
Kent Cooper, 9 March 2021
|;
(defun C:CMTL1 ; = Copy MText Line 1 only
(/ mt mtdata mtht ht txt hard soft newtxt)
(if
(and
(setq mt (car (entsel "\nMText object to Copy 1st line of: ")))
(member '(0 . "MTEXT") (setq mtdata (entget mt)))
); and
(progn ; then
(initget 6); no zero, no negative
(setq ht
(cond
( (getdist ; nil on Enter
(strcat
"\nText height <"
(rtos (setq mtht (cdr (assoc 40 mtdata)))); current height default
">: "
); strcat
); getdist
); User-input condition
(mtht); User Enter -- keep current height
); cond
); setq
(if (wcmatch (setq txt (cdr (assoc 1 mtdata))) "*\\P*,*\n*"); contains Enter(s)
(setq ; then
hard (vl-string-search "\\P" txt) ; first "hard" Enter if any
soft (vl-string-search "\n" txt) ; first "soft" Enter [Shift+Enter] if any
newtxt (substr txt 1 (apply 'min (vl-remove nil (list hard soft))))
; from beginning to first type of Enter encountered
); setq
(setq newtxt txt); no Enter(s) -- keep
); if
(entmake
(append
(subst (cons 1 newtxt) (assoc 1 mtdata) mtdata); new content
(list (cons 40 ht)); new height
); append
); entmake
(command "_.move" (entlast) "" "_none" (cdr (assoc 10 mtdata)))
); progn
); if
); defun
Note the NOTE. If it's important to have the remaining first line "look" the same even at a different size, i.e. to also adjust the Mtext defining box width, it could be altered to use a SCALE command, rather than assigning the new height in entity data.
The height is about that of the "outer" Mtext object. Anything like a height override inside the Mtext will remain, though since that is assigned proportionally in the text-string formatting, not as an absolute height, the proportion will remain relative to the new height.
Note also that if there is word wrapping from the width of the MText defining box before an Enter is encountered, all content up to the Enter will remain even though wrapped to more than one line.
Kent Cooper, AIA