geo999 Posted January 26, 2011 Posted January 26, 2011 Hello everyone, i'm looking for a LISP which can add a user specified number to a group of text. (I know this might be a simple question for some of you guys!!) Example: I have a group of numbering text, let say 3.00 & 5.00, and I want to add 0.5 to all each of them, so the end result will be 3.50 & 5.50 accordingly. I'm a new member to this site, and I appreciated for any help Quote
Tharwat Posted January 26, 2011 Posted January 26, 2011 Check this out .Buddy . (defun c:Test (/ Nstr ss) ; Tharwat 25. 01. 2011 ; Tested withAutoCAD 2010 (if (and (setq Nstr (getstring "\n Enter Text to add :")) (setq ss (ssget '((0 . "TEXT,MTEXT")))) ) ( (lambda (i / ss1 e str GLoc 1st 2nd all) (while (setq ss1 (ssname ss (setq i (1+ i)))) (setq e (entget ss1)) (setq str (cdr (assoc 1 e))) (if (eq nil (setq GLoc (vl-string-search "." str))) (entupd (cdr (assoc -1 (entmod (subst (cons 1 str) (assoc 1 e) e) ) ) )) (progn (setq 1st (substr str 1 GLoc)) (setq 2nd (substr str (+ 2 GLoc))) (setq all (strcat 1st "." Nstr)) (entupd (cdr (assoc -1 (entmod (subst (cons 1 all) (assoc 1 e) e) ) ) ) ) ) ) ) ) -1 ) (princ "\n No texts selected") ) (princ) ) Tharwat Quote
geo999 Posted January 26, 2011 Author Posted January 26, 2011 Tharwat, thanks for the help, the program is getting close to what I need. I input 0.5 for the number to add, then select the group of numbering text (3.00 & 5.00), it give me the result as (3.0.5 & 5.0.5) instead. I'm looking into the program and see if I can find out why. Again I appreciated your input! Quote
BlackBox Posted January 26, 2011 Posted January 26, 2011 Welcome to the forums! (defun c:FOO (/ ss textString oldPat newPat) (vl-load-com) (vla-startundomark (cond (*activeDoc*) ((setq *activeDoc* (vla-get-activedocument (vlax-get-acad-object)))))) ;; Main code (if (setq ss (ssget "_x" '((0 . "TEXT,MTEXT")(1 . "3.00,5.00")))) (progn (vlax-for x (setq ss (vla-get-activeselectionset *activeDoc*)) (cond ((vl-string-search (setq textString (vla-get-textstring x)) (setq oldPat "3.00")) (setq newPat "3.50")) ((vl-string-search textString (setq oldPat "5.00")) (setq newPat "5.50")) (T (setq newPat nil))) (if newPat (vla-put-textstring x (vl-string-subst newPat oldPat textString)))) (vla-delete ss))) (vla-endundomark *activeDoc*) (princ)) Quote
David Bethel Posted January 26, 2011 Posted January 26, 2011 maybe like this: [b][color=BLACK]([/color][/b]defun c:addvtxt [b][color=FUCHSIA]([/color][/b]/ ss en ed ov tv add[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]initget 3[b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]setq add [b][color=NAVY]([/color][/b]getreal [color=#2f4f4f]"\nAmount To Add: "[/color][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]and [b][color=NAVY]([/color][/b]setq ss [b][color=MAROON]([/color][/b]ssget '[b][color=GREEN]([/color][/b][b][color=BLUE]([/color][/b]0 . [color=#2f4f4f]"TEXT"[/color][b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b] [b][color=NAVY]([/color][/b]while [b][color=MAROON]([/color][/b]setq en [b][color=GREEN]([/color][/b]ssname ss 0[b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]setq ed [b][color=GREEN]([/color][/b]entget en[b][color=GREEN])[/color][/b] tv [b][color=GREEN]([/color][/b]cdr [b][color=BLUE]([/color][/b]assoc 1 ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]and [b][color=GREEN]([/color][/b]numberp [b][color=BLUE]([/color][/b]read tv[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]setq ov [b][color=BLUE]([/color][/b]atof tv[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b] [b][color=GREEN]([/color][/b]entmod [b][color=BLUE]([/color][/b]subst [b][color=RED]([/color][/b]cons 1 [b][color=PURPLE]([/color][/b]rtos [b][color=TEAL]([/color][/b]+ ov add[b][color=TEAL])[/color][/b] 2 4[b][color=PURPLE])[/color][/b][b][color=RED])[/color][/b] [b][color=RED]([/color][/b]assoc 1 ed[b][color=RED])[/color][/b] ed[b][color=BLUE])[/color][/b][b][color=GREEN])[/color][/b][b][color=MAROON])[/color][/b] [b][color=MAROON]([/color][/b]ssdel en ss[b][color=MAROON])[/color][/b][b][color=NAVY])[/color][/b][b][color=FUCHSIA])[/color][/b] [b][color=FUCHSIA]([/color][/b]prin1[b][color=FUCHSIA])[/color][/b][b][color=BLACK])[/color][/b] Standard TEXT only no MTEXT -David Quote
geo999 Posted January 26, 2011 Author Posted January 26, 2011 Thanks for helping RenderMan, for some reason, I couldn't get the program running properly. But it seems to me that your program works like replacing the existing text with new text (if i understand it correctly!!??). So, it might not work in my case if there are more different numbers in my group of numbering text other than 3.00 or 5.00. Quote
BlackBox Posted January 26, 2011 Posted January 26, 2011 Thanks for helping RenderMan, for some reason, I couldn't get the program running properly. But it seems to me that your program works like replacing the existing text with new text (if i understand it correctly!!??). So, it might not work in my case if there are more different numbers in my group of numbering text other than 3.00 or 5.00. Having just re-read the OP, I misunderstood your original request. Quote
geo999 Posted January 26, 2011 Author Posted January 26, 2011 David, your program works great!! Exactly what I need!! Awesome, man!! Big Thanks!! Quote
ReMark Posted January 26, 2011 Posted January 26, 2011 You want a lisp routine called TextInc.lsp that will increment the selected text. Works on both DText and MText. Quote
David Bethel Posted January 26, 2011 Posted January 26, 2011 David, your program works great!! Exactly what I need!! Awesome, man!! Big Thanks!! You're welcome DIMZIN will affect the leading and trailing zeros of the number displayed, so you may want to play with the setting and the '4 parameter in the ( rtos ) call in order to have the display to your liking. Have fun -David Quote
Tharwat Posted January 26, 2011 Posted January 26, 2011 Tharwat, thanks for the help, the program is getting close to what I need. I input 0.5 for the number to add, then select the group of numbering text (3.00 & 5.00), it give me the result as (3.0.5 & 5.0.5) instead. I'm looking into the program and see if I can find out why. Again I appreciated your input! Actually you should enter the decimal number only without the point like this : 10 20 30 40 and so on ..... Retry once again. 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.