jamathi Posted February 18, 2010 Posted February 18, 2010 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 Quote
Lee Mac Posted February 18, 2010 Posted February 18, 2010 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)) Quote
jamathi Posted February 19, 2010 Author Posted February 19, 2010 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 Quote
Lee Mac Posted February 19, 2010 Posted February 19, 2010 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)) Quote
jamathi Posted February 22, 2010 Author Posted February 22, 2010 Dude, this works incredibally well. Thank you so much. I will do what I can to support the site. Quote
Lee Mac Posted February 22, 2010 Posted February 22, 2010 Dude, this works incredibally well. Thank you so much. I will do what I can to support the site. You're welcome Jamathi, thanks Quote
Recommended Posts
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.