It used to work, but quit
I wrote a simple list routine back in 1995 that was supposed to put an integer in a box (or circle) and increment the value the next time you picked a new point.I have a block called memnum that is a rectangle with some text inside and another block that is a circle with some text inside called jn.When I load the lisp it asks me my start number and a scale factor as it should, but the mem code just has "XXXX" inside the box and does not increment the value.It hasbeen years since I have run this code and I don't see why it quit working.Can some of you smart LISP folks see why it is not incrementing my value?The MEM code puts a number in the box and the JOI code puts a number in a circle.
;; This lisp routine was written by George T. Watson on 5-10-95;; This routine will insert an incremented number in a box(defun c:mem (/ pt1 val scale )(setq val (getint "\nEnter member number to start with "))(setq scale (getint "\nEnter scale factor "))(while val(setq pt1 (getpoint "\nPick next Point")) (command "insert" "memnum" pt1scale "" "" val) (setq val (1+ val))); end of while loop); end of defun;; This routine will insert an incremented number in a circle(defun c:joi (/ pt1 val scale )(setq val (getint "\nEnter Joint number to start with "))(setq scale (getint "\nEnter scale factor "))(while val(setq pt1 (getpoint "\nPick next Point")) (command "insert" "jn" pt1scale "" "" val) (setq val (1+ val))) ; end of while loop) ; end of defun Hi George,
Give this a shot mate:
(defun c:mem ( / *error* block old pt scale val var ) (setq block "memnum");; Block to be Inserted (defun *error* ( msg ) (if old (mapcar 'setvar var old)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq var '("CMDECHO" "ATTREQ") old (mapcar 'getvar var)) (mapcar 'setvar var '(0 1)) (if (or (tblsearch "BLOCK" block) (findfile (strcat block ".dwg")) ) (if (and (setq val (getint "\nEnter member number to start with: ")) (progn (initget 6) (setq scale (getint "\nEnter scale factor: ")) ) ) (while (setq pt (getpoint "\nPick next Point: ")) (command "_.-insert" block "_S" scale "_non" pt "" (itoa val)) (setq val (1+ val)) ) ) (princ (strcat "\n--> " block ".dwg not Found.")) ) (mapcar 'setvar var old) (princ))
I've added some error trapping to your routine to check for valid input and existence of the block to be inserted. Set your attreq system variable to 1. I'm no lisp guru, but on my system it gives an error related to not being able to find "memnum.dwg".If you have that block stored somewhere, you need to either add its location to the search path or move the drawing to one of them in your search path list. Actually this would probably be better to combine the two routines:
(defun c:mem nil (InsertBlock "memnum" "\nEnter Member Number to start with: "))(defun c:joi nil (InsertBlock "jn" "\nEnter Joint Number to start with: "))(defun InsertBlock ( block msg / *error* old pt scale val var ) (defun *error* ( msg ) (if old (mapcar 'setvar var old)) (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*") (princ (strcat "\n** Error: " msg " **"))) (princ) ) (setq var '("CMDECHO" "ATTREQ") old (mapcar 'getvar var)) (mapcar 'setvar var '(0 1)) (if (or (tblsearch "BLOCK" block) (findfile (strcat block ".dwg")) ) (if (and (setq val (getint msg)) (progn (initget 6) (setq scale (getint "\nEnter scale factor: ")) ) ) (while (setq pt (getpoint "\nPick next Point: ")) (command "_.-insert" block "_S" scale "_non" pt "" (itoa val)) (setq val (1+ val)) ) ) (princ (strcat "\n--> " block ".dwg not Found.")) ) (mapcar 'setvar var old) (princ)) Lee Mac;
Thanks, that worked.
Alanjt;
Setting the system variable attreq to 1 (it was 0) worked with my original code.
Jack;
Yes, the little drawing memnum is just a rectangle with the text inside and it is my search path.
Thanks all for the help.Back in 1995, I knew what I was attempting to do, but the years in between then and now have blurred the memory.
Lee and some of these other folks have forgotten more than I ever knew about writing lisp.I used to could take one that was close to what I wanted to do and massage it till it did what I wanted but lately haven't even had that much success.
You wanna draw something, I can be all up in that.You wanna write a program to draw something, I'll be standing over on the side going "ooooo....pretty!"
Good to hear g****son
(lol at your name being censored) t.wat are you talking about? Yeah, I figured as much. Nothing wrong with what Lee gave you, but you should understand what was actually going wrong.
页:
[1]
2