Jump to content

Lisp for Find & replace word to incrementing number


soan

Recommended Posts

Hi,

 

I look for a LISP that I can not find anywhere on.

 

1- The first text i will selected, it will find the text "XX" and automatically replace by the number "01"

 

2- The second text i will selected, it will find the text "XX" and automatically replace by the number "02"

 

3- Continue step 1 & 2 (number "03", "04", "05"...) until i stop the LISP

 

4- I don't have to choose which text i want to replace when i open LISP (always the word "XX") and don't choose the first number (always the number "01")

 

I hope you undertand me (i'm a french canadians ;) )

Thanks a lot !!!

Edited by soan
Link to comment
Share on other sites

Hello,

 

Thank you for the quick response!

 

The Tcount command does not select a block at a time and you have to configure the settings each time. It is faster to change each device number to hand that used the Tcount command.

Link to comment
Share on other sites

Its an easy task but I am short of time right now pick text check if "XX" exist using wcmatch then read string up to xx add number.

 

Found some time.

 

; replace XX with a number
; By Alan H jan 2016
(defun c:add01 ( / obj ans x newstr)
(setq x (getint "\nEnter start number press <Cr> to exit "))
(while (/= (setq obj (vlax-ename->vla-object(car (entsel "\nPick text")))) nil) ; no errork check for text

; if less than 10 01-09 10+
(if (< x 10.0) 
   (setq newstr (strcat "0" (rtos x 2 0)))
   (setq newstr (rtos x 2 0))
)

(setq txtstr (vla-get-textstring obj)) ;return string val
(if (> (setq pos (vl-string-search "XX" (strcase txtstr))) 1) ; return the position of XX
 (progn 
 (setq num (strlen txtstr)) ; how many caharcters is string re abcdexxhjkl problem
 (setq ans (Strcat (substr txtstr 1 pos) newstr)) ; combine characters up to xx+01
 )
)

(vla-put-textstring obj ans) ; update text
(setq x (+ x 1)) ; next number
)
(princ)
)

Edited by BIGAL
Link to comment
Share on other sites

Code updated now, only question is if you have abcdXX-52-b it will do abcd08 etc needs a version 2 that checks for end of line characters, Soan if needed have a go the code is there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...