Jump to content

Find & Replace Automation -- Need Lisp


jamathi

Recommended Posts

Hi all,

 

I do drawings with series of various parts that increse increnmentally. I manually place them and number them with tags like 1-1-K001 and the next one would be 1-1-K002. The problem is sometimes one part gets inserted and all of the subsequent parts need to be bumped up by the increment of one. I was searching for a Lisp but was not able to find one that does that. It would be nice to have a Lisp that would do the find and replace and bump up the number 1 digit higher on all 50 some parts all at once or that can refernce an excel file that has a list of in a FIND values column with a subsequent column for REPLACE values.

 

Any help will be greatly appreciated.

 

 

Here was a similar post:

http://www.cadtutor.net/forum/showthread.php?t=43306&highlight=INCREMENT

Link to comment
Share on other sites

Try this (on copies of drawings of course):

 

(defun c:BumpUp (/ ELST ENT I NUM SEARCH SS STR)

 (setq search "1-1-K*")

 (if (setq i -1 ss (ssget "_X" '((0 . "TEXT,MTEXT"))))
   (while (setq ent (ssname ss (setq i (1+ i))))
     (if (wcmatch
           (strcase
             (setq str
               (cdr (assoc 1 (setq eLst (entget ent))))))

           (strcase search))
       
       (progn

         (if (setq num (atoi (substr str 6)))
           (progn
             (setq num (itoa (1+ num)))

             (while (< (strlen num) 3)
               (setq num (strcat "0" num)))

             (entmod
               (subst
                 (cons 1 (strcat (substr str 1 (- (strlen str) 3)) num))
                   (assoc 1 eLst) eLst))))))))
 (princ))
              

Link to comment
Share on other sites

Thank you.

 

The Lisp you posted works flawlessly in bumping up the numbers for the entire drawing. How would I be able to do it if I need to do it selectively. For example Part is being inserted at 1-1-K035 and I only need to bumup the ones from 1-1-K035 and above. Also the numbers are part of an enhanced attribute. The above lisp seems to only work on Text.

 

Thanks

Link to comment
Share on other sites

Try this:

 

(defun c:BumpUp (/ ELST ENT I NUM SEARCH SS STR)

 (setq search "1-1-K*")

 (if (setq i -1 ss (ssget "_:L" '((-4 . "<OR")
                                    (0 . "TEXT,MTEXT")
                                    (-4 . "<AND")
                                      (0 . "INSERT")
                                      (66 . 1)
                                    (-4 . "AND>")
                                  (-4 . "OR>"))))
   
   (while (setq ent (ssname ss (setq i (1+ i))))

     (cond (  (eq "INSERT" (cdr (assoc 0 (entget ent))))

              (while (not (eq "SEQEND"
                              (cdr (assoc 0 (entget
                                              (setq ent
                                                (entnext ent)))))))
                (if (wcmatch
                      (strcase
                        (setq str
                          (cdr (assoc 1 (setq eLst (entget ent))))))
                      
                      (strcase search))

                  (if (setq num (atoi (substr str 6)))
                    (progn
                      (setq num (itoa (1+ num)))

                      (while (< (strlen num) 3)
                        (setq num (strcat "0" num)))

                      (entupd
                        (cdr (assoc -1
                               (entmod
                                 (subst
                                   (cons 1 (strcat
                                             (substr str 1
                                                     (- (strlen str) 3)) num))
                                   
                                     (assoc 1 eLst) eLst))))))))))

           (t (if (wcmatch
                    (strcase
                      (setq str
                             (cdr (assoc 1 (setq eLst (entget ent))))))
                    
                    (strcase search))

                (if (setq num (atoi (substr str 6)))
                  (progn
                    (setq num (itoa (1+ num)))
                    
                    (while (< (strlen num) 3)
                      (setq num (strcat "0" num)))

                    (entupd
                      (cdr (assoc -1
                             (entmod
                               (subst
                                 (cons 1 (strcat (substr str 1 (- (strlen str) 3)) num))
                                   (assoc 1 eLst) eLst))))))))))))
 (princ))

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