lisp copy first 6 digits of 1 text to another text

lisp copy first 6 digits of 1 text to another text

Sally_Ward8TWBK
Explorer Explorer
521 Views
7 Replies
Message 1 of 8

lisp copy first 6 digits of 1 text to another text

Sally_Ward8TWBK
Explorer
Explorer

I want a lisp that can copy portion of text (first ?? number of digits) to another text.

I have a downloaded lisp that can copy the entire text to another text. i'm want to know if it can be tweaked to get it to ask how many characters you want changed. eg I only want the first 6 digits, sometimes i need the first 7 or 5 digits. then it would ask to select the first text line (where the text is to be copied from)  and then select a second text (where the text is to be copied too)

 

does anyone have a lisp that can do this? or is it even possible?

0 Likes
Accepted solutions (1)
522 Views
7 Replies
Replies (7)
Message 2 of 8

paullimapa
Mentor
Mentor

Could you share the downloaded lisp that you have now here?

Also for the Text object are you referring to MTEXT or TEXT?


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 3 of 8

Sally_Ward8TWBK
Explorer
Explorer

Hi

thanks for asking.

the lisp I have downloaded is CopySwapTextV1-8.lsp from the Lee Mac Programming website.

the text I am using is a TEXT.

0 Likes
Message 4 of 8

paullimapa
Mentor
Mentor

Since it's a pretty straight forward text string copy, here's a much shorter function I call TxtCpy.lsp that should meet your requirements:

 

; TxtCpy Copy Text line from one to another prompting for # of characters to copy
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-copy-first-6-digits-of-1-text-to-another-text/m-p/13180522#M475423
(defun c:txtcpy (/ get_txt tx1 tx2 txi txl txs)
  ; get_txt select text object and returns text entity selected
  ; Argument:
  ; msg = message prompt
  (defun get_txt (msg / txt)
   (while (not txt)
    (princ msg)
    (if(setq txt (ssget "_+.:E:S" '((0 . "TEXT"))))
      (ssname txt 0)
    )
   )
  ) ; defun
  (setq tx1 (get_txt "\nPick First Text Line to Copy from: ")
        txs (getpropertyvalue tx1 "TextString") ; get text string of first text
        txl (strlen txs) ; get length of first text string
        tx2 (get_txt "\nPick Second Text Line to Copy to: ")
  )
  (while (not txi)
    (if (setq txi (getint (strcat "\nEnter Number of Characters to Copy <" (itoa txl) ">: ")))
      (cond
       ((> txi txl) ; greater than text length
        (setq txi nil)
        (princ (strcat "\nCan Only have up to " (itoa txl) " Characters..."))
       )
       ((< txi 1) ; less than 1
        (setq txi nil)
        (princ "\nMust be greater than 0 Characters...")
       )
      ) ; cond
      (setq txi txl) ; else use text length
    ) ; if
  ) ; while
  (setpropertyvalue tx2 "TextString" (substr txs 1 txi))
  (princ) ; clean exit
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 5 of 8

Sally_Ward8TWBK
Explorer
Explorer

thanks for this. 

it is nearly what I need.  this one takes the specified number of digits from the first text selected and replaces all of the second text. I need it to only replace the same specified number of digits. Is that possible?

0 Likes
Message 6 of 8

paullimapa
Mentor
Mentor
Accepted solution

sure is...here's the revised version:

 

; TxtCpy Copy Text line from one to another prompting for # of characters to copy
; OP:
; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/lisp-copy-first-6-digits-of-1-text-to-another-text/m-p/13180522#M475423
(defun c:txtcpy (/ cmdecho get_txt tx1 tx2 txi txl txn txs txx)
  ; get_txt select text object and returns text entity selected
  ; Argument:
  ; msg = message prompt
  (defun get_txt (msg / txt)
   (while (not txt)
    (princ msg)
    (if(setq txt (ssget "_+.:E:S" '((0 . "TEXT"))))
      (ssname txt 0)
    )
   )
  ) ; defun
  (setq cmdecho (getvar "cmdecho")
        tx1 (get_txt "\nPick First Text Line to Copy from: ")
        txs (getpropertyvalue tx1 "TextString") ; get text string of first text
        txl (strlen txs) ; get length of first text string
        tx2 (get_txt "\nPick Second Text Line to Copy to: ")
        txx (getpropertyvalue tx2 "TextString") ; get text string of second text
        txn (strlen txx) ; get length of second text string
  )
  (setvar "cmdecho" 0)
  (while (not txi)
    (if (setq txi (getint (strcat "\nEnter Number of Characters to Copy <" (itoa txl) ">: ")))
      (cond
       ((> txi txl) ; greater than text length
        (setq txi nil)
        (princ (strcat "\nCan Only have up to " (itoa txl) " Characters..."))
       )
       ((< txi 1) ; less than 1
        (setq txi nil)
        (princ "\nMust be greater than 0 Characters...")
       )
      ) ; cond
      (setq txi txl) ; else use text length
    ) ; if
  ) ; while
  (command "_.Undo" "_BE")
  (if (< txi txn) ; chk if second text has more characters
    (setpropertyvalue tx2 "TextString" (strcat (substr txs 1 txi) (substr txx (1+ txi))))
    (setpropertyvalue tx2 "TextString" (substr txs 1 txi))
  ) ; if
  (command "_.Undo" "_E")
  (setvar "cmdecho" cmdecho)
  (princ) ; clean exit
) ; defun

 


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes
Message 7 of 8

Sally_Ward8TWBK
Explorer
Explorer

you are a legend. thanks so much

0 Likes
Message 8 of 8

paullimapa
Mentor
Mentor

you are welcome...cheers!!!


Paul Li
IT Specialist
@The Office
Apps & Publications | Video Demos
0 Likes