Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Urgent Help required : LISP for deleting last line of a MText

26 REPLIES 26
Reply
Message 1 of 27
bireshwar.mallick
1709 Views, 26 Replies

Urgent Help required : LISP for deleting last line of a MText

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))

Bireshwar
26 REPLIES 26
Message 21 of 27
Lee_Mac
in reply to: hmsilva


@hmsilva wrote:

Nice modification! Smiley Happy


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

 

 

 

 

Message 22 of 27
hmsilva
in reply to: Lee_Mac


@Lee_Mac wrote:

@hmsilva wrote:

Nice modification! Smiley Happy


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... Smiley Wink

 

Henrique

EESignature

Message 23 of 27
Lee_Mac
in reply to: hmsilva


@hmsilva wrote:

Nice one! Lee

Stored it in my toolbox... Smiley Wink


 

Thanks Henrique Smiley Happy

A minor update to my earlier post as I forgot to localise the 'tmp' variable Smiley Wink

Message 24 of 27
kevinb
in reply to: bireshwar.mallick

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 

Message 25 of 27
_Tharwat
in reply to: kevinb


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)
)

 

Message 26 of 27
kevinb
in reply to: _Tharwat

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

Message 27 of 27
_Tharwat
in reply to: kevinb

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)
  )

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost