Good morning!! We are requiring a lisp to delete last line of any MText on a click. I have a one that deletes last word of an MText on a click but the issue is that I cannot make the last line to delete instead it deletes the last word. Can you please help me out. I am a regular java programmer and not so expertise in lisp. It will be of a good gesture if you please help me out as it is really required for a project in which last line of a MText can be deleted. I am here by stating the lsp for your reference.
Best Regards,
Bireshwar Mallick
/*Deletes the last word instead of the last line*/
(defun c:33 ( / ss)
(if (setq ss (ssget "_:L" '((0 . "MTEXT"))))
((lambda (i / e ed s)
(while (setq e (ssname ss (setq i (1+ i))))
(setq ed (entget e))
(setq s (assoc 1 ed))
(setq ed (subst (cons 1 (substr (cdr s) 1 (1- (strlen (cdr s))))) s ed))
(entmod ed)))
-1)
(prompt "\n** Nothing selected ** "))
(princ))
@hmsilva wrote:Nice modification!
Thank you Henrique!
For this task it would be useful if vl-string-search had the from-end-p flag that vl-string-position offers, e.g. something like:
;; vl-string-search with 'from-end-p' flag - Lee Mac (defun vl-string-search2 ( pat str pos end / len rtn tmp ) (if (and (setq rtn (vl-string-search pat str pos)) end) (progn (setq len (strlen pat)) (while (setq tmp (vl-string-search pat str pos)) (setq pos (+ tmp len)) ) (- pos len) ) rtn ) )
_$ (vl-string-search2 "\\P" "Line1\\PLine2\\PLine3" nil t) 12
@Lee_Mac wrote:
@hmsilva wrote:
Nice modification!
Thank you Henrique!
For this task it would be useful if vl-string-search had the from-end-p flag that vl-string-position offers, e.g. something like:
;; vl-string-search with 'from-end-p' flag - Lee Mac (defun vl-string-search2 ( pat str pos end / len rtn ) (if (and (setq rtn (vl-string-search pat str pos)) end) (progn (setq len (strlen pat)) (while (setq tmp (vl-string-search pat str pos)) (setq pos (+ tmp len)) ) (- pos len) ) rtn ) )
_$ (vl-string-search2 "\\P" "Line1\\PLine2\\PLine3" nil t) 12
Nice one! Lee
Stored it in my toolbox...
Henrique
hi,
I am not sure who I have sent this to but I was hoping that _Tharwat might be able to tell me what I would have to change in his routine for the deletion of MText lines to allow me to remove the FIRST line and not the last line as in the lisp routine he provided for Bireshware. Could you please send back reply be email below
I tried the routine supplied and it works fine for the last line
Kevin brennan
food service design
kevinb@fsdaustralia.com
kevinb wrote:
hi,
I am not sure who I have sent this to but I was hoping that _Tharwat might be able to tell me what I would have to change in his routine for the deletion of MText lines to allow me to remove the FIRST line and not the last line as in the lisp routine he provided for Bireshware. Could you please send back reply be email below
I tried the routine supplied and it works fine for the last line
Kevin brennan
food service design
kevinb@fsdaustralia.com
Hello Kevin
Try this modified program and let me know how you get on with it .
(defun c:Test (/ s in en st _st r i) ;; --=={ Tharwat 30.1.2015 }==-- ;; (if (setq s (ssget "_:L" '((0 . "MTEXT")))) (repeat (setq in (sslength s)) (setq en (entget (ssname s (setq in (1- in)))) st (cdr (assoc 1 en)) r t ) (while (and r (setq i (vl-string-search "\\P" st))) (setq r nil _st (substr st (+ i 3)) ) ) (if _st (entmod (subst (cons 1 _st) (assoc 1 en) en ) ) ) ) ) (princ) )
Thank you for the reply
The routine works a treat but could I ask if there is a way to keep the first line but with no text in it. We have a routine for incremental numbering that requires an open line to place the prefix and subsequent incremental number in. Your modified routine takes the whole line out and our routine adds the incremental to the front of the top line. I have attached a jpg file showing the grip points of the text before and after running your routine. On the left the FREEZER note on the top is the original already incremented text we need to alter. The text below shows the top line deleted after running your routine. On the right the top text is the existing and the text below is what we require to re-run our routine in - top line still available but with no text
Thanks anyway as if there is no way of changing t the above we will still use yours as it saves on having to select the text and delete it. We can easily add a space into the mtext to re-obtain the space line if we have to , so agin thanks
Kevin Brennan
Try this .
(defun c:Test (/ s in en st _st r i) ;; --=={ Tharwat 02.02.2015 }==-- ;; (if (setq s (ssget "_:L" '((0 . "MTEXT") (1 . "*\\P*")))) (repeat (setq in (sslength s)) (setq en (entget (ssname s (setq in (1- in)))) st (cdr (assoc 1 en)) r t ) (while (and r (setq i (vl-string-search "\\P" st))) (setq r nil _st (substr st (+ i 3)) ) ) (if _st (entmod (subst (cons 1 (strcat "\\P" _st)) (assoc 1 en) en ) ) ) ) ) (princ) )