I have a simple problem, my lisp is simple, here's what i need it to do: 1. figure out if the limits are E or D size 2. if D, write a whole bunch of text accross the limits at certain points. 3. if E, write a whole different bunch of text accross the limits at certain points. so for this part i use the COND function. but know i also want to add another piece to it. 4. Prompt the user for input " Demolition (D) or Installation (I)" after the user put's in D or I, do this 5. IF D, and if limits are for D-size, insert a certain block 6. IF I, and limits are for D-size, insert a certain block. so the last part is what confuses me, cause i have to have 2 conditions, first if limits equal D-size and second if user input was D or I. Here's what I got: (DEFUN C:IFC (/ CMD OSN LM LMX) (SETQ CMD (GETVAR "CMDECHO")) (SETQ OSN (GETVAR "OSMODE")) (SETVAR "OSMODE" 0) (SETVAR "CMDECHO" 1) (setq LM (GETVAR "LIMMAX") LMX (CADR LM) UI (getstring T "\n Is this a Demolition (D) or Installation (I)?: ")) (setq RS UI) (COMMAND ".layer" "n" "IFC" "C" "249" "IFC" "S" "IFC" "" ".style" "IFC" "ROMANS" "1" "1" "0" "N" "N" "N") ;IF D-SIZE THEN DO THIS (COND ((= LMX 22.0) (COMMAND ".text" "2,17" "45" "bla bla bla" ".LAYER" "LO" "IFC" "" ".LAYER" "S" "0" "")) ;IF E-SIZE THEN DO THIS ((= LMX 34.0) (COMMAND ".text" "1.75,29" "45" "bla bla bla" ".LAYER" "LO" "IFC" "" ".LAYER" "S" "0" ""))) (cond ((= RS D) (= lmx 22.0) (command ".-insert" "Demo-d" "0,0" "1" "" "")) ((= RS I) (= lmx 22.0) (command ".-insert" "Inst-D" "0,0" "1" "" "")) ((= RS D) (= lmx 34.0) (command ".-insert" "Demo-e" "0,0" "1" "" "")) ((= RS I) (= lmx 34.0) (command ".-insert" "Inst-e" "0,0" "1" "" ""))) (command ".draworder" (ssget "x" '((0 . "TEXT")(8 . "IFC"))) "" "b" ".draworder" (ssget "x" '((0 . "IMAGE"))) "" "b") (SETVAR "CMDECHO" CMD) (PRINT "ISSUED FOR CONSTRUCTION"))
How I would do it is: get the paper size get the type like (initget "D I") (setq UI (getkword "\n Type of drawing [<D>emolition, Installation]: ")) (if (not UI) (setq UI "D") ) cond -D size --if (= UI "D") ---do this ---do this -E size --if (= UI "D") ---do this ---do this end Sorry don't have more time right now to write it. Hope it helps. Tim
This is how I might do it. (DEFUN C:IFC (/ CMD OSN LM LMX) (SETQ CMD (GETVAR "CMDECHO")) (SETQ OSN (GETVAR "OSMODE")) (SETVAR "OSMODE" 0) (SETVAR "CMDECHO" 1) (setq LM (GETVAR "LIMMAX") LMX (CADR LM) ) ;make sure that either "D" or "I" is entered (initget "D I") (setq UI (getkword "\n Is this a Demolition (D) or Installation (I)?: ")) ;set the block name to either "Demo" or "Inst" (if (= UI "D") (setq blkname "Demo") ;otherwise (setq blkname "Inst") ) ;(setq RS UI) ;Use layer "m" instead of "n" (COMMAND ".layer" "m" "IFC" "C" "249" "IFC" "") (command ".style" "IFC" "ROMANS" "1" "1" "0" "N" "N" "N") (COND ;IF D-SIZE THEN DO THIS ((= LMX 22.0) (COMMAND ".text" "2,17" "45" "bla bla bla" ) ;add "d" to the block name (setq blkname (strcat blkname "-d")) ) ;IF E-SIZE THEN DO THIS ((= LMX 34.0) (COMMAND ".text" "1.75,29" "45" "bla bla bla" ) ;add "e" to the block name (setq blkname (strcat blkname "-e")) ) ) ;Set layer "0" current and lock "IFC" (command ".layer" "s" "0" "lo" "IFC" "") (command ".-insert" blkname "0,0" "1" "" "") (command ".draworder" (ssget "x" '((0 . "TEXT")(8 . "IFC"))) "" "b" ".draworder" (ssget "x" '((0 . "IMAGE"))) "" "b" ) (SETVAR "CMDECHO" CMD) (PRINT "\nISSUED FOR CONSTRUCTION") (princ);exit quietly )
Untested, but see if this works, if not it should get you pointed in the right direction. Post if you want/need more help. Tim (DEFUN C:IFC (/ CMD OSN LM LMX) (SETQ CMD (GETVAR "CMDECHO")) (SETQ OSN (GETVAR "OSMODE")) (SETVAR "OSMODE" 0) (SETVAR "CMDECHO" 1) (setq LM (GETVAR "LIMMAX") LMX (CADR LM) ) (initget "D I") (setq UI (getkword "\n Type of plan [<D>emolition, Installation]: ") (if (not UI) (setq UI "D") ) (COMMAND ".layer" "n" "IFC" "C" "249" "IFC" "S" "IFC" "" ".style" "IFC" "ROMANS" "1" "1" "0" "N" "N" "N") (COND ((= LMX 22.0) ;IF D-SIZE THEN DO THIS (COMMAND ".text" "2,17" "45" "bla bla bla" ".LAYER" "LO" "IFC" "" ".LAYER" "S" "0" "") (if (= UI "D") (command ".-insert" "Demo-d" "0,0" "1" "" "")) (command ".-insert" "Inst-D" "0,0" "1" "" "")) ); if ) ((= LMX 34.0);IF E-SIZE THEN DO THIS (COMMAND ".text" "1.75,29" "45" "bla bla bla" ".LAYER" "LO" "IFC" "" ".LAYER" "S" "0" ""))) (if (= UI "D") (command ".-insert" "Demo-e" "0,0" "1" "" "")) (command ".-insert" "Inst-e" "0,0" "1" "" ""))) ); if ) ); cond (command ".draworder" (ssget "x" '((0 . "TEXT")(8 . "IFC"))) "" "b" ".draworder" (ssget "x" '((0 . "IMAGE"))) "" "b") (SETVAR "CMDECHO" CMD) (PRINT "ISSUED FOR CONSTRUCTION") ); defun
To answer your original question: If you only have two conditions then you can use if or cond (if (= LMX 22.0) (progn <do your stuff here> ) ;else (progn <do your other stuff here> ) );end if If you have more than two conditions then cond is better and faster than a bunch of if's (cond ((= LMX 22.0) <do 22.0 stuff here> ) ((= LMX 34.0) <do 34.0 stuff here> ) ((= LMX 44.0) <do 44.0 stuff here> ) (T <do default stuff here if no other condition is met> ) );end cond news:41549c8a_2@newsprd01...
Regardless of what other problems your code may have this shows a misunderstanding of what COND does. Only the first element of a COND sublist, in this case (= RS D), is used to decide whether this part is chosen. All the other elements in the sublist are executed, and the value of the last one is returned as the value of the COND. So, here every time when (= RS D), the program executes (= lmx 22.0), and regardless of what was the result of that, proceeds to (command ...) and returns whatever that returned. You probably intended (cond ((and (= RS D) (= lmx 22.0)) (command ...)) ...) - another thing to worry about: comparing two floating point numbers for exact equality with = is risky: if they are calculated values, they may differ slightly due to rounding errors and the inherent representation inexactness of floats. --