Cad64 Posted May 4, 2016 Share Posted May 4, 2016 Hi guys, I am in need of a lisp routine and I'm hoping somebody will be able to help me out. I don't think it's terribly complicated, but it is outside of my skill set. What I need is a way to re-number attributes inisde blocks. The blocks I'm working with contain 4 attributes, but the only attribute that needs to change is the "Valve Number". (See the screenshot below). Sometimes, when laying out large irrigation plans, I may need to go back and place another valve somewhere in the middle of the layout. This means I have to renumber all the other valves which can take quite a bit of time doing it manually. Ideally I would like to have a routine that lets me specify the starting valve number and then lets me click on each block to update the number incrementally as I click on each one. For example, suppose I need to renumber valves A-6 to A-40. I would like to be able to initiate the routine, type in 6 as the starting number and then start clicking on blocks to automatically renumber them. Also, the "Valve Number" in my example is A-1, but the letter won't always be "A". Sometimes it will be "B" or "C" or whatever, so only the number after the dash can change. Thanks for taking a look and let me know if you need more info. I would upload the block but it belongs to my client so I can't. Quote Link to comment Share on other sites More sharing options...
abra-CAD-abra Posted May 4, 2016 Share Posted May 4, 2016 Try this little gem from Gile: https://apps.autodesk.com/ACD/en/Detail/Index?id=8051485828049059617&appLang=en&os=Win32_64 Hope it helps.. Cheers Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 4, 2016 Share Posted May 4, 2016 Hi, Please try this program that I have just wrote and let me know how you get on with it and if you need any further extension of the function; (defun c:IncAtts (/ *error* run st blk e at pre num v) ;; Tharwat. cadtutor ;; ;; Date:04.May.2016 ;; (defun *error* (msg) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) ) (princ (strcat "\nError: " msg)) ) (princ) ) (setq run t) (while (not (setq *starting:number* (cond ((and (setq st (getstring (strcat "\nSpecify starting number after char: eg. [X-1] <" (if *starting:number* *starting:number* (setq *starting:number* "A-1") ) ">: " ) ) ) (eq st "") ) *starting:number* ) ((and (wcmatch st "*-#*") (numberp (+ 2 (vl-string-search "-" st))) ) (setq *starting:number* st) ) (t nil) ) ) ) (princ "\nUncorrect string!. Try again") ) (princ "\nSelect attributed block with Tag name <1>:") (while (and run (setq blk (car (entsel ) ) ) (eq (cdr (assoc 0 (setq e (entget blk)))) "INSERT") (eq (cdr (assoc 66 e)) 1) (if (vl-some '(lambda (x) (and (eq (vla-get-tagstring x) "1") (setq at x) ) ) (vlax-invoke (vlax-ename->vla-object blk) 'getattributes) ) at (progn (princ "\nAttributed Block doesn't have tag name <1> !") (setq run nil) ) ) ) (vla-put-textstring at (setq pre (substr *starting:number* 1 (1+ (vl-string-search "-" *starting:number*)) ) num (substr *starting:number* (+ 2 (vl-string-search "-" *starting:number*)) ) *starting:number* (strcat pre (itoa (1+ (atoi num)))) v (strcat pre num) ) ) ) (princ) )(vl-load-com) Quote Link to comment Share on other sites More sharing options...
Cad64 Posted May 4, 2016 Author Share Posted May 4, 2016 Try this little gem from Gile: Thanks for the link. That looks pretty good but it's really way more than I need. This routine will be used by other people in my clients office and I'm afraid all those options will be confusing and overwhelming for some users. I'm looking for something super simple that can be run from the command line, no dialogs. Just run the command, type in the starting number and go. Quote Link to comment Share on other sites More sharing options...
Cad64 Posted May 4, 2016 Author Share Posted May 4, 2016 Please try this program that I have just wrote and let me know how you get on with it and if you need any further extension of the function; Hi Tharwat, this is exactly what I was looking for and it seems to work perfectly. Thank you for taking the time to write it. This will be very helpful. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted May 4, 2016 Share Posted May 4, 2016 Hi Tharwat, this is exactly what I was looking for and it seems to work perfectly. Thank you for taking the time to write it. This will be very helpful. Excellent, happy to help. Quote Link to comment Share on other sites More sharing options...
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.