mechcad Posted December 3, 2005 Share Posted December 3, 2005 I am trying to be able to enter a number and my lisp routine needs to make the number "001" instead of "1". The lisp will eventually start counting up 002, 003, 004........ Yesterday i recieved the below condition statment, but it does not seem to be giving me "001, 002..." that i am looking for. Go easy on me this is my first lisp!!! Thanks for any help! (setq TAGNUMBER (getint "\nEnter Number To Start: ") (setq TAGNUMBER (cond ((< (atoi TAGNUMBER) 10) (strcat "00" TAGNUMBER)) ((< (atoi TAGNUMBER) 100) (strcat "0" TAGNUMBER)) (T TAGNUMBER))) Quote Link to comment Share on other sites More sharing options...
paulmcz Posted December 3, 2005 Share Posted December 3, 2005 Try this one. Same thing can be achieved with "cond" instead of "if". If you want, I can rewrite it for use of "cond", so you can see how it works. Paul. ;;; inserts increasing numbers with prefix 00 or 0 (defun c:nm (/ p n ni oecho m) (if nn (setq nn (fix nn))(setq nn 1)) (princ "\n Increment by < ") (princ nn) (princ " >? : ") (setq ni (getint)) (if (= ni nil)(setq ni nn)(setq nn ni)) (if np () (setq np 1) ) (princ "\n Start or continue with number < ") (princ np) (princ " >? : ") (setq n (getint)) (if (= n nil) (setq n np) (setq np n) ) (setq p (getpoint "\n Number location: ")) (setq oecho (getvar "cmdecho")) (setvar "cmdecho" 0) (while p (setq m (rtos n 2 0)) (if (and (< n 10) (> n -1)) (setq m (strcat "00" m)) ) (if (and (> n 9) (< n 100)) (setq m (strcat "0" m)) ) (if (and (< n 0) (> n -10)) (progn (setq mm (rtos (* n -1) 2 0)) (setq m (strcat "-00" mm)) ) ) (if (and (< n -9) (> n -100)) (progn (setq mm (rtos (* n -1) 2 0)) (setq m (strcat "-0" mm)) ) ) (command "text" "j" "mc" p "" "" m) (setq p (getpoint "\n Next number location: ") n (+ ni n) np n ) ) (setvar "cmdecho" oecho) (princ) ) (princ "\n Type > NM < to insert numbers.") Quote Link to comment Share on other sites More sharing options...
paulmcz Posted December 3, 2005 Share Posted December 3, 2005 Actually, here it is (using "cond"). If you replace entire "while" function with this one, it should work just the same: (while p (setq m (itoa n)) (cond ((> 100 n 9) (setq m (strcat "0" m))) ((> 10 n -1) (setq m (strcat "00" m))) ((> 0 n -10) (setq m (strcat "-00" (itoa (* n -1))))) ((> -9 n -100)(setq m (strcat "-0" (itoa (* n -1))))) (t mm) ) (command "text" "j" "mc" p "" "" m) (setq p (getpoint "\n Next number location: ") n (+ ni n) np n ) ) Have fun, Paul. Quote Link to comment Share on other sites More sharing options...
paulmcz Posted December 3, 2005 Share Posted December 3, 2005 (setq TAGNUMBER (getint "\nEnter Number To Start: ") (setq TAGNUMBER (cond ((< (atoi TAGNUMBER) 10) (strcat "00" TAGNUMBER)) ((< (atoi TAGNUMBER) 100) (strcat "0" TAGNUMBER)) (T TAGNUMBER))) Here, 'tagnumber' is first set as integer (getint). Then there is an atempt to convert it to integer again (atoi TAGNUMBER) Also, you can't feed "strcat" with integer (strcat "00" TAGNUMBER). You have to convert it to the string first with "itoa" or "rtos" Here... (setq TAGNUMBER (getint "\nEnter Number To Start: ") (setq TAGNUMBER (cond ((< TAGNUMBER 10) (strcat "00" (itoa TAGNUMBER))) ((< TAGNUMBER 100) (strcat "0" (itoa TAGNUMBER))) (T TAGNUMBER))) Quote Link to comment Share on other sites More sharing options...
David Bethel Posted December 3, 2005 Share Posted December 3, 2005 (getint) returns a number (atoi) expects a string You need to have your conversions and values match. The only way to get 001 is by using a string. -David Quote Link to comment Share on other sites More sharing options...
ASMI Posted December 4, 2005 Share Posted December 4, 2005 >mechcad Can more universal program will approach. It numbers with a prefix and a suffix. (defun c:num (/ oldPref oldSuf oldStart curStr newNum actDoc actSp oldEcho oldSize *error*) (defun *error* (msg) (setvar "CMDECHO" oldEcho) (princ) ); end *error* (vl-load-com) (if(not num:Size)(setq num:Size(getvar "DIMTXT"))) (if(not num:Pref)(setq num:Pref "")) (if(not num:Suf)(setq num:Suf "")) (if(not num:Num)(setq num:Num 1)) (setq oldPref num:Pref oldSuf num:Suf oldStart num:Num oldSize num:Size actDoc(vla-get-ActiveDocument (vlax-get-acad-object)) oldEcho(getvar "CMDECHO") ); end setq (setvar "CMDECHO" 0) (if(= (vla-get-ActiveSpace actDoc) 1) (setq actSp(vla-get-ModelSpace actDoc)) (setq actSp(vla-get-PaperSpace actDoc)) ); end setq (setq num:Size (getreal (strcat "\nSpecify text size <"(rtos num:Size)">: "))) (if(null num:Size)(setq num:Size oldSize)) (setq num:Pref (getstring T (strcat "\nType prefix: <"num:Pref">: "))) (if(= "" num:Pref)(setq num:Pref oldPref)) (if(= " " num:Pref)(setq num:Pref "")) (setq num:Suf (getstring T (strcat "\nType suffix: <"num:Suf">: "))) (if(= "" num:Suf)(setq num:Suf oldSuf)) (if(= " " num:Suf)(setq num:Suf "")) (setq num:Num (getint (strcat "\nEnter start number <"(itoa num:Num)">: "))) (if(null num:Num)(setq num:Num oldStart)) (while T (setq curStr(strcat num:Pref(itoa num:Num)num:Suf) newNum(vla-AddText actSp curStr (vlax-3d-point '(0.0 0.0 0.0)) num:Size)) (vla-put-Alignment newNum acAlignmentMiddleCenter) (command "_.copybase"(trans '(0.0 0.0 0.0)0 1)(entlast)"") (command "_.erase" (entlast) "") (command "_.pasteclip" pause) (setq num:Num(1+ num:Num)) ); end while (princ) ); end of c:num And this renumbers the existing text. (defun c:renum (/ oldPref oldSuf oldStart curText curStr) (vl-load-com) (if(not rnm:Pref)(setq rnm:Pref "")) (if(not rnm:Suf)(setq rnm:Suf "")) (if(not rnm:Start)(setq rnm:Start 1)) (setq oldPref rnm:Pref oldSuf rnm:Suf oldStart rnm:Start); end setq (setq rnm:Pref (getstring T (strcat "\nType prefix: <"rnm:Pref">: "))) (if(= "" rnm:Pref)(setq rnm:Pref oldPref)) (if(= " " rnm:Pref)(setq rnm:Pref "")) (setq rnm:Suf (getstring T (strcat "\nType suffix: <"rnm:Suf">: "))) (if(= "" rnm:Suf)(setq rnm:Suf oldSuf)) (if(= " " rnm:Suf)(setq rnm:Suf "")) (setq rnm:Start (getint (strcat "\nEnter start number <" (itoa rnm:Start)">: "))) (if(null rnm:Start)(setq rnm:Start oldStart)) (while T (setq curStr(strcat rnm:Pref(itoa rnm:Start)rnm:Suf)) (setq curText (car (nentsel "\nSelect DText/MText/Attribute or Esc to Quit "))) (if (and curText (member(cdr(assoc 0(entget curText))) '("TEXT" "MTEXT" "ATTRIB")) ); end and (progn (vla-put-TextString (vlax-ename->vla-object curText)curStr) (setq rnm:Start(1+ rnm:Start)) ); end progn (princ "\nThis is not DText, MText or Attribute! ") ); end if ); end while (princ) ); end of c:renum Quote Link to comment Share on other sites More sharing options...
fixo Posted December 4, 2005 Share Posted December 4, 2005 Hi ASMI There were nice routines, you are really specialist I think Thank you for a share Oleg Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 15, 2009 Share Posted July 15, 2009 this is error message Command: ; error: An error has occurred inside the *error* functionAutoCAD variable setting rejected: "cmdecho" nil im using AutoCAD2007 Quote Link to comment Share on other sites More sharing options...
VVA Posted July 15, 2009 Share Posted July 15, 2009 Version NUM and Renum with alignment (add 0 before number) NumA and RemunA http://www.cadtutor.net/forum/showthread.php?p=253543#post253543 Quote Link to comment Share on other sites More sharing options...
asos2000 Posted July 15, 2009 Share Posted July 15, 2009 Sorry this lisp working v. good the posting by mistake This error in INCSUF lisp 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.