Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone
How can remove from all mtext, for example first line or second line or third line.... N line?
Solved! Go to Solution.
Hi everyone
How can remove from all mtext, for example first line or second line or third line.... N line?
Solved! Go to Solution.
Would the lines of content always and only be separated by Enters/returns [the \P that shows in the Contents in the Properties palette of the few I looked at], and never be the result of word-wrapping based on the Mtext's box width?
Try this, no error checking for wrong objects etc.
; Thanks to lee-mac for function.
; 44 is comma 9 is tab 34 is space 58 is colon 126 is tilde
(defun c:remtext ( / x K _csv->lst126 obj str lst num)
; By AlanH Dec 2023
(defun _csv->lst126 ( str / pos )
(if (setq pos (vl-string-position 126 str))
(cons (substr str 1 pos) (_csv->lst126 (substr str (+ pos 2))))
(list str)
)
)
(setq num (- (getint "\nEnter line number to remove ") 1))
(while (setq ent (car (entsel "Pick mtext ")))
(setq obj (vlax-ename->vla-object ent))
(setq str (vlax-get obj 'Textstring))
(while (vl-string-search "\\P" str)
(setq str (vl-string-subst "~" "\\P" str 1))
)
(setq lst (_csv->lst126 str))
(setq K 0 newstr "")
(If (> num (length lst))
(alert "Number is larger than available ")
(foreach val lst
(if (= K num)
(princ)
(setq newstr (strcat newstr "\\P" val))
)
(setq k (1+ k))
)
)
(vlax-put obj 'Textstring newstr)
)
(princ)
)
Thank you dear kent for reply.
Your answers is yes.
The points you raised are followed in all the mtext.
Hi dear sea-haven
thanks fo reply
Is it possible to use ssget else instead of entsel and delete line?
so that the text of three lines becomes two lines.
Currently, it only deletes the text and the line remains.
So that the text of three lines becomes two lines.
Currently, it only deletes the text and the line remains.
And in re-execution of the program, it does not work to delete another line of mtext.
hey there,
check this one
;*********************************************************************************************************************************
(defun string_to_list (input_string delimiter / delimiter_position output_list)
(while (setq delimiter_position (vl-string-search delimiter input_string 0))
(setq output_list (append output_list (list (substr input_string 1 delimiter_position)))
input_string (substr input_string (+ 3 delimiter_position))
)
)
(append output_list (list input_string))
)
;*********************************************************************************************************************************
(defun c:delete_nth_line (/ mtext_sset mtext_list)
(setq line_default_value 1
line (if (null (setq line_new (vl-catch-all-apply 'getint (list (strcat "\nEnter line number <"
(if line (itoa line) (itoa line_default_value))
">: "
)
)
)))
(if line line line_default_value)
(if (vl-catch-all-error-p line_new) nil (setq line_default_value line_new))
)
mtext_sset (ssget '((0 . "mtext")))
)
(if mtext_sset
(foreach mtext (vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset)))
(setq mtext_list (string_to_list (cdr (assoc 1 (entget mtext))) "\\P"))
(vla-put-textstring (vlax-ename->vla-object mtext)
(apply 'strcat (cdr (apply 'append (mapcar '(lambda (text_line) (list "\\P" text_line))
(vl-remove (nth (1- line) mtext_list) mtext_list)
)
)
)
)
)
)
)
)
;*********************************************************************************************************************************
updated
Of course, this is an example.
In general, the mtext may have more lines and we want to delete some lines and keep the rest of the lines.
sure. check update.
your welcome