TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: caddman6425 on January 07, 2012, 08:40:00 PM

Title: If within if
Post by: caddman6425 on January 07, 2012, 08:40:00 PM
I think that is wrong and you should use a cond statment, but I've got so many cond statments now, that I'm lost.  I want to ask a yes or no question and if they answer yes then it asks to make a choice between 3 answers.  Depending on this answer it goes into a cond statment.  There might not be enough here to see what I'm trying to accomplish.  Jest let me know if you want the whole thing.  I havent got the cond statment all worked out though.
Code: [Select]
;;;                         Choices                               ;;;
(initget "Yes No")
(setq ch  (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: "); If the answer is yes then I want to ask this next question
 (if (= ch "Yes")
   (progn
     (initget "2 3 4")
     (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> ")
     ); End setq
   ); End prognn
   (progn
     (setq sp     '(0 0)
           wid     (getreal  "\nWhat is the width of this Member Shape?  ")
           dep     (getreal  "\nWhat is the depth of this Member Shape?  ")
           memshna (getstring T "\nWhat is the name of the Member Shape? ")
     ); End setq
   ); End progn
 ); End if
); End setq   
   

Title: Re: If within if
Post by: CAB on January 07, 2012, 11:16:07 PM
What you have looks ok except the ans variable when ENTER is pressed.
I would do it this way. Although more error checking is needed.
Code: [Select]
(initget "Yes No")
(if (setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
  ;; ONLY USE ch if you need it, in this case ch=true when YES else ch=nil
  (progn
    (initget "2 3 4")
    (if (null (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> ")))
      (setq ans "2")
    )
  )
  (setq sp      '(0 0)
        wid     (getreal "\nWhat is the width of this Member Shape?  ")
        dep     (getreal "\nWhat is the depth of this Member Shape?  ")
        memshna (getstring t "\nWhat is the name of the Member Shape? ")
  ) ; End setq
) ; End if

More info here:
http://www.theswamp.org/index.php?topic=13046.msg158557#msg158557
Title: Re: If within if
Post by: BlackBox on January 08, 2012, 12:29:55 AM
Another option:

Code: [Select]
(initget "Yes No")
(if (or (setq opt (getkword "\nSelect an option [Yes/No] <Yes>: "))
     (= nil opt))
  ;; Either yes, no, or enter (right click) selected
  (prompt (strcat "\nYou selected " opt))
  ;; Nothing selected
  )
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 06:04:13 AM
Well, that checked out untill I ran the whole thing, Now I get this error, I used my error checking routine:


Code - Auto/Visual Lisp: [Select]
  1. Command: SMC
  2.  
  3. Is this going to be a Multi-Member Unit? [Yes or No] <No>: y
  4.  
  5. How many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> 2
  6.  
  7. AutoLISP Error:  bad argument type: numberp: nil-layer
  8. Current layer:  "0"
  9. Enter an option
  10. [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/PSt
  11. yle/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]: s
  12. Enter layer name to make current or <select object>: 0 Enter an option
  13. [?/Make/Set/New/Rename/ON/OFF/Color/Ltype/LWeight/TRansparency/MATerial/Plot/PSt
  14. yle/Freeze/Thaw/LOck/Unlock/stAte/Description/rEconcile]:
  15.  
  16.  
  17. Here is all of the code, predicate 1-3 are all  the same at the moment, so forget them.
  18.  
  19. ;;                                Copyright© 2012 by Nick Haury                                    ;;;
  20. ;*****************************************************************;
  21. (defun *error* (msg);                                                
  22.   (if (/= msg "Function cancelled") ;                                
  23.     (princ (strcat "\nAutoLISP Error:  " msg)) ;                    
  24.     (terpri);                                                        
  25.   );                                                                
  26.   (setvar "CMDECHO" S_CMD)              ;                            
  27.   (setvar "ORTHOMODE" S_ORTH)           ;                            
  28.   (setvar "OSMODE" S_OSM)               ;                            
  29.   (command "-layer" "s" CL "" "redraw") ;                            
  30. ); End defun                                                        
  31. ;;                                                                  
  32. ;;             Subroutine to Start program                          
  33. (defun start ();                                                    
  34.   (graphscr)                           ;                            
  35.   (setq CL (getvar "CLAYER"))          ; Stores Current Layer;      
  36.   (setq S_CMD (getvar "CMDECHO"))      ; Stores Command Mode State;  
  37.   (setq S_ORTH (getvar "ORTHOMODE"))   ; Stores Orthomode State;    
  38.   (setq S_OSM (getvar "OSMODE"))       ; Stores Object Snap State;  
  39.   (setvar "CMDECHO" 1)                 ; No echo;                    
  40.   (setvar "ORTHOMODE" 1)               ; Ortho on;                  
  41.   (setvar "OSMODE" 0)                  ; Snap None;                  
  42. ); End defun                                                        
  43. ;;                                                                  
  44. ;;            Subroutine to end program                              
  45. (defun Stop ()                        ;                              
  46.   (setvar "CMDECHO" S_CMD)            ; Restores Stored Command Echo
  47.   (setvar "OSMODE" S_OSM)             ; Restores Stored Object Snap  
  48.   (command "-LAYER" "s" CL "")        ; Restores Current Layer State
  49. ); End defun                                                        
  50. ;;;                        Start Routine                          ;;;
  51. (defun c:smc ()
  52. (start)
  53. ;;;                         Choices                               ;;;
  54. (initget "Yes No")
  55. (if (setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
  56.   (progn
  57.     (initget "2 3 4")
  58.     (if (null (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> ")))
  59.       (setq ans "2")
  60.     ); End if
  61.   ); End progn
  62.   (setq sp      '(0 0)
  63.         wid     (getreal "\nWhat is the width of this Member Shape?  ")
  64.         dep     (getreal "\nWhat is the depth of this Member Shape?  ")
  65.         memshna (getstring t "\nWhat is the name of the Member Shape? ")
  66.   ); End setq
  67. ); End if
  68. ;;;                        Do the Math                            ;;;
  69. (setq x1 (car sp)
  70.        x2 (+ x1 (/ wid 2.0))
  71.        x3 (+ x1 wid)
  72.        y1 (cadr sp)
  73.        y2 (+ y1 dep)
  74. ); End setq
  75. ;;;                       Point Assignment                        ;;;
  76. (setq p1 (list x1 y1)
  77.        p2 (list x2 y1)
  78.        p3 (list x3 y1)
  79.        p4 (list x3 y2)
  80.        p5 (list x1 y2)
  81. ); End setq
  82. ;;;                         Lets Draw                             ;;;
  83.      "_.pline" p1 p3 p4 p5 "c"
  84. ); End command
  85. ;;;          Let's Define the Multi-Member Shapes & Styles        ;;;
  86.  (if (= ch "Yes")
  87.   (progn
  88.    ; (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> "))
  89. ;;;          Let's Define the Double Multi-Member Shape & Style          ;;;
  90.     (cond
  91.      (; Start predicate1
  92.       (= ans 2)
  93.       (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
  94.       (command "_-AecsMemberShapeDefine"
  95.             "_New" memshna
  96.             "_Graphics"
  97.             "_Low"    (entlast) "" p2
  98.             "_Medium" (entlast) p2
  99.             "_High"   (entlast) p2 "" "" ""
  100.       ); End command
  101.       (entdel (entlast))
  102.       (command "-MemberStyle"  
  103.             "_New" memstyna
  104.             "_Component" "_Edit" "1" "_Name" "Section" "STart"
  105.             "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
  106.             "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
  107.             memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
  108.             "_Offset" "" "" "" "" "" "" "" "" ""
  109.       ); End command  
  110.      ); End predicate1
  111. ;;;          Let's Define the Triple Multi-Member Shape & Style          ;;;
  112.      (; Start predicate2
  113.       (= ans 3)
  114.       (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
  115.       (command "_-AecsMemberShapeDefine"
  116.             "_New" memshna
  117.             "_Graphics"
  118.             "_Low"    (entlast) "" p2
  119.             "_Medium" (entlast) p2
  120.             "_High"   (entlast) p2 "" "" ""
  121.       ); End command
  122.       (entdel (entlast))
  123.       (command "-MemberStyle"  
  124.             "_New" memstyna
  125.             "_Component" "_Edit" "1" "_Name" "Section" "STart"
  126.             "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
  127.             "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
  128.             memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
  129.             "_Offset" "" "" "" "" "" "" "" "" ""
  130.       ); End command  
  131.      ); End predicate2
  132. ;;;          Let's Define the Quadruple Multi-Member Shape & Style          ;;;
  133.      (; Start predicate3
  134.       (= ans 4)
  135.       (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
  136.       (command "_-AecsMemberShapeDefine"
  137.             "_New" memshna
  138.             "_Graphics"
  139.             "_Low"    (entlast) "" p2
  140.             "_Medium" (entlast) p2
  141.             "_High"   (entlast) p2 "" "" ""
  142.       ); End command
  143.       (entdel (entlast))
  144.       (command "-MemberStyle"  
  145.             "_New" memstyna
  146.             "_Component" "_Edit" "1" "_Name" "Section" "STart"
  147.             "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
  148.             "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
  149.             memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
  150.             "_Offset" "" "" "" "" "" "" "" "" ""
  151.       ); End command  
  152.      ); End predicate3
  153.     ); End cond      
  154.   ); End progn        
  155. ;;;          Let's Define the Unequal Multi-Member Shape & Style          ;;;
  156. ;;; Maybe something here
  157. ;;;               Let's Define the Member Shape & Style                   ;;;
  158.    (progn
  159.     (setq memstyna (getstring T "\nWhat is the Member Style Name going to be? ")); End setq
  160.     (command "_-AecsMemberShapeDefine"
  161.              "_New" memshna
  162.              "_Graphics"
  163.              "_Low"    (entlast) "" p2
  164.              "_Medium" (entlast) p2
  165.              "_High"   (entlast) p2 "" "" ""
  166.     ); End command
  167.     (entdel (entlast))
  168.     (command "-MemberStyle"
  169.              "_New" memstyna
  170.              "_Component" "_Edit"    "1" "_Name" "Section"
  171.              "_STart" "_SHape"    memshna "" "_ENd" "_SHape"
  172.              memshna "" "" "" "" ""
  173.     ); End command
  174.    ); end progn
  175.   ); end if
  176. (stop)
  177. ); End C:SMC
Title: Re: If within if
Post by: ribarm on January 08, 2012, 07:17:10 AM
You must define variables if your first choice is "Y" to make routine continue (your actual error is variable wid = nil) - Start VLIDE for debugging, open your *.lsp, press "Load active edit window" button, then press "Activate AutoCAD" button, type SMC in command prompt and if it brakes it will return you automatically to VLIDE => press icon "Last break" and you'll see where error occurs :

;;;                         Choices                               ;;;
(initget "Yes No")
(if (setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
  (progn
    (initget "2 3 4")
    (if (null (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> ")))
      (setq ans "2")
    ); End if
    (setq sp      '(0 0)
        wid     (getreal "\nWhat is the width of this Member Shape?  ")
        dep     (getreal "\nWhat is the depth of this Member Shape?  ")
        memshna (getstring t "\nWhat is the name of the Member Shape? ")
    ); End setq
  ); End progn
  (setq sp      '(0 0)
        wid     (getreal "\nWhat is the width of this Member Shape?  ")
        dep     (getreal "\nWhat is the depth of this Member Shape?  ")
        memshna (getstring t "\nWhat is the name of the Member Shape? ")
  ); End setq
); End if

M.R.
Title: Re: If within if
Post by: Ketxu on January 08, 2012, 12:49:00 PM
@ caddman6425 & ribarm : oh, what happened with Codebox ^^
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 01:04:12 PM
Hmmmm, whats that?  If I should have pasted the code as an attachment, then I'm sorry.  If so how would I do that?  If that is not the case, then what are you talking about?  Is that better?  I was wondering if that was what it was for.  Uh next time, why don't you do a private email and clue me in then  wasting the time to do this.  Sorry I offended you.
Title: Re: If within if
Post by: CAB on January 08, 2012, 02:55:05 PM
Not a big deal but he is referring to the [ code] [ /code] tags.
Highlight your code and click on the # button.

I'll revise your first post as an example.
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 03:09:16 PM
Do you prefer just code or code = autolisp


Code: [Select]
Code, code, code
or

Code - Auto/Visual Lisp: [Select]
  1. Code, code, code

Oh yeah, what ribarm did worked but now I think I have definite problems with the cond statements, they don't seem to work.  What I'm trying to accomplish is an understanding of what I'm doing before I put most of the setq to OpenDCL
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 03:24:45 PM
Do I have these cond statments set up correctly?

Code: [Select]
(if (= ch "Yes")
  (progn
;;;          Let's Define the Double Multi-Member Shape & Style          ;;;
    (cond ((= ans 2)
           (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
           (shapename)
           (princ "Hi")
           (command "-MemberStyle"   
                    "_New" memstyna
                    "_Component" "_Edit" "1" "_Name" "Section" "STart"
                    "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                    "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                    memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                    "_Offset" "" "" "" "" "" "" "" "" ""
           ); End command 
          ); End predicate1
;;;          Let's Define the Triple Multi-Member Shape & Style          ;;;
          ((= ans 3)
           (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
           (shapename)
           (command "-MemberStyle"   
                 "_New" memstyna
                 "_Component" "_Edit" "1" "_Name" "Section" "STart"
                 "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                 "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                 memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                 "_Offset" "" "" "" "" "" "" "" "" ""
           ); End command 
          ); End predicate2
;;;          Let's Define the Quadruple Multi-Member Shape & Style          ;;;
         ((= ans 4)
          (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
          (shapename)
          (command "-MemberStyle"   
                "_New" memstyna
                "_Component" "_Edit" "1" "_Name" "Section" "STart"
                "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                "_Offset" "" "" "" "" "" "" "" "" ""
          ); End command 
         ); End predicate3
    ); End cond       
  ); End progn       
;;;          Let's Define the Unequal Multi-Member Shape & Style          ;;;
;;; Maybe something here
;;;               Let's Define the Member Shape & Style                   ;;;
  (progn
   (setq memstyna (getstring T "\nWhat is the Member Style Name going to be? ")); End setq
   (shapename)
   (command "-MemberStyle"
            "_New" memstyna
            "_Component" "_Edit"    "1" "_Name" "Section"
            "_STart" "_SHape"    memshna "" "_ENd" "_SHape"
            memshna "" "" "" "" ""
   ); End command
  ); end progn
 ); end if

Can I use the same 'IF' twice?
Title: Re: If within if
Post by: ribarm on January 08, 2012, 03:32:55 PM
You have to group "then" conditions after predicate statement :
(cond
  ((= ans "2")
   (progn (...)(...)(...)...)
  )
  ((= ans "3")
   (progn ....)
  )
  ...
); End of cond

M.R.
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 03:37:17 PM
Darn. I just keep forgetting that progn, darn little thing.  No, that argument is not true, I just keep tripping over my own brain. ;-D
Title: Re: If within if
Post by: CAB on January 08, 2012, 04:39:28 PM
(COND does not require progn, only the (IF requires them if you have more than one code group.
The following works just fine.
Code: [Select]
(cond
  ((= ans "2")
    (...)(...)(...)
  )
  ((= ans "3")
    (....)
  )
); End of cond
 
Title: Re: If within if
Post by: Lee Mac on January 08, 2012, 05:51:32 PM
Code: [Select]
(if
    (or
        (setq opt (getkword "\nSelect an option [Yes/No] <Yes>: "))
        (= nil opt)
    )
    ...
)

This says: "If (<opt> or (not <opt>)): do this ..."

The IF statement is redundant since the 'else' expression will NEVER be evaluated (<opt> can only be nil or non-nil).

Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 06:15:01 PM
OOOKKKay, uh, where and how would I use this? :|
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 06:42:50 PM
I think that something is wrong in the code.  It's not making a dbl member, it acts like it is just skipping the cond and going right to making a single member.

Look for "(cond ((= ans 2)" it's in this section

Code: [Select]
;;               Copyright© 2012 by Nick Haury                     ;;;
;;;;**************************************************************;;;;
(defun *error* (msg);                                                 
  (if (/= msg "Function cancelled") ;                                 
    (princ (strcat "\nAutoLISP Error:  " msg)) ;                     
    (terpri);                                                         
  );                                                                 
  (setvar "CMDECHO" S_CMD)              ;                             
  (setvar "ORTHOMODE" S_ORTH)           ;                             
  (setvar "OSMODE" S_OSM)               ;                             
  (command "-layer" "s" CL "" "redraw") ;                             
); End defun                                                         
;;                                                                   
;;             Subroutine to Start program                           
(defun start ()                         ;                             
  (graphscr)                            ;                             
  (setq CL (getvar "CLAYER"))           ; Stores Current Layer;       
  (setq S_CMD (getvar "CMDECHO"))       ; Stores Command Mode State; 
  (setq S_ORTH (getvar "ORTHOMODE"))    ; Stores Orthomode State;     
  (setq S_OSM (getvar "OSMODE"))        ; Stores Object Snap State;   
  (setvar "CMDECHO" 1)                  ; No echo;                   
  (setvar "ORTHOMODE" 1)                ; Ortho on;                   
  (setvar "OSMODE" 0)                   ; Snap None;                 
); End defun                                                         
;;                                                                   
;;            Subroutine to end program                               
(defun Stop ()                          ;                             
  (setvar "CMDECHO" S_CMD)              ; Restores Stored Command Echo
  (setvar "OSMODE" S_OSM)               ; Restores Stored Object Snap
  (command "-LAYER" "s" CL "")          ; Restores Current Layer State
); End defun                                                         
(defun shapename ()
       (command "_-AecsMemberShapeDefine"
            "_New" memshna
            "_Graphics"
            "_Low"    (entlast) "" p2
            "_Medium" (entlast) p2
            "_High"   (entlast) p2 "" "" ""
      ); End command
      (entdel (entlast))
); End defun
;;;                        Start Routine                          ;;;
(defun c:smc ()
(start)
;;;                         Choices                               ;;;ze
(initget "Yes No")
(if (setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
  (progn
    (initget "2 3 4")
    (if (null (setq ans (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> ")))
      (setq ans "2")
    ); End if
    (setq sp      '(0 0)
          wid     (getreal "\nWhat is the width of this Member Shape?  ")
          dep     (getreal "\nWhat is the depth of this Member Shape?  ")
          memshna (getstring t "\nWhat is the name of the Member Shape? ")
    ); End setq   
  ); End progn
  (setq sp      '(0 0)
        wid     (getreal "\nWhat is the width of this Member Shape?  ")
        dep     (getreal "\nWhat is the depth of this Member Shape?  ")
        memshna (getstring t "\nWhat is the name of the Member Shape? ")
  ); End setq
); End if
;;;                        Do the Math                            ;;;
(setq x1 (car sp)
       x2 (+ x1 (/ wid 2.0))
       x3 (+ x1 wid)
       y1 (cadr sp)
       y2 (+ y1 dep)
); End setq
;;;                       Point Assignment                        ;;;
(setq p1 (list x1 y1)
       p2 (list x2 y1)
       p3 (list x3 y1)
       p4 (list x3 y2)
       p5 (list x1 y2)
); End setq

;;;                         Lets Draw                             ;;;
(command
     "_.pline" p1 p3 p4 p5 "c"
); End command
;;;          Let's Define the Multi-Member Shapes & Styles        ;;;
 (if (= ch "Yes")
  (progn
;;;          Let's Define the Double Multi-Member Shape & Style          ;;;
    (cond ((= ans 2)
           (progn
            (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
            (shapename)
            (command "-MemberStyle"   
                     "_New" memstyna
                     "_Component" "_Edit" "1" "_Name" "Section" "STart"
                     "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                     "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                     memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                     "_Offset" "" "" "" "" "" "" "" "" ""
            ); End command 
           ); End progn
          ); End predicate1
;;;          Let's Define the Triple Multi-Member Shape & Style          ;;;
          ((= ans 3)
           (progn
            (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
            (shapename)
            (command "-MemberStyle"   
                     "_New" memstyna
                     "_Component" "_Edit" "1" "_Name" "Section" "STart"
                     "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                     "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                     memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                     "_Offset" "" "" "" "" "" "" "" "" ""
            ); End command
           ); End progn   
          ); End predicate2
;;;          Let's Define the Quadruple Multi-Member Shape & Style          ;;;
          ((= ans 4)
           (progn
            (setq memstyna (getstring T "\nWhat is the Member Style Name going to be?  ")); End setq
            (shapename)
            (command "-MemberStyle"   
                     "_New" memstyna
                     "_Component" "_Edit" "1" "_Name" "Section" "STart"
                     "_SHape" memshna "" "_ENd" "_SHape" memshna "" ""
                     "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape"
                     memshna "_Offset" "" wid "" "" "_ENd" "_SHape" memshna
                     "_Offset" "" "" "" "" "" "" "" "" ""
            ); End command
           ); End progn   
          ); End predicate3
    ); End cond       
  ); End progn       
;;;          Let's Define the Unequal Multi-Member Shape & Style          ;;;
;;; Maybe something here
;;;               Let's Define the Member Shape & Style                   ;;;
  (progn
   (setq memstyna (getstring T "\nWhat is the Member Style Name going to be? ")); End setq
   (shapename)
   (command "-MemberStyle"
            "_New" memstyna
            "_Component" "_Edit"    "1" "_Name" "Section"
            "_STart" "_SHape"    memshna "" "_ENd" "_SHape"
            memshna "" "" "" "" ""
   ); End command
  ); end progn
 ); end if
(princ)
(stop)
); End C:SMC
Title: Re: If within if
Post by: Lee Mac on January 08, 2012, 06:45:04 PM
'ch' never equals "Yes", 'ch' will either equal T or nil since you have:

Code: [Select]
(setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
And '=' will only ever return T or nil.

As a quick fix, use instead:

Code: [Select]
(= (setq ch (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ")) "Yes")
Title: Re: If within if
Post by: Lee Mac on January 08, 2012, 06:45:40 PM
OOOKKKay, uh, where and how would I use this? :|

Use what?
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 06:55:51 PM
Soooo, I won't use the 'IF' here at this point?
Title: Re: If within if
Post by: Lee Mac on January 08, 2012, 06:59:02 PM
Soooo, I won't use the 'IF' here at this point?

The 'IF' where? At which point?

Why not take some time to study the responses and construct a more comprehensible question.
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 07:24:52 PM
Lee, I'm sorry that I'm not as adept as you are at wrighting code.  I'm just trying to relearn it all over again, and it take me some time to do it.  If I was as smart as you, then I'd know how to phrase my questions, and if I could do that, then I'd be smart enough, that I would need to ask for your help.  So, I guess not understanding is a crime to you so, why don't we just for get it.  You seem put out that I don't understand.  So just cancel this thread, I don't need this or you!!!!! :realmad:  And BTW, I'm talking about your post 16, that if statment.  That is the first if  (if (setq ch (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes"))
You know, no one has really answered my real question, "can you do an if within an if!  I did post the whole code.

Sorry that your put out with me and I aplogize for getting upset and if I'm wrong about your attitude, then I applogize for that also.

AIA (Appolgize in advance)
Title: Re: If within if
Post by: ronjonp on January 08, 2012, 08:17:23 PM
Dude...chill out.  :-o
Title: Re: If within if
Post by: caddman6425 on January 08, 2012, 08:43:22 PM
You know something, I am a firm believer that you browbeat, criticize, or just talk negatively to some one in front of everyone.  Do it in private.  But no, in order of trying to save some kind of face in front of every one I had to defend myself.  Let it be know why I'm so backward, and I really don't put this out, but it seems that I have to now, is in 97 I had two massive strokes and I lost just about everything use to know.  I wrote fairly comprehensive lisp code, Vlisp, CC+ and the like, well I'm having to relearn it.  So thing don't come easy to me anymore and I have to see to understand.  I am unable at this time to phrase my questions intelligibly.  I just have to walk my way through some things,  this thread is one of them, so I can retain the information.  I don't just take what someone says as gospel I have to understand why.  Again I appoligize for my outburst!
Title: Re: If within if
Post by: CAB on January 08, 2012, 09:12:48 PM
We all can be a bit sensitive at times and I can say  that rarely do participants mean any harm.
All the folks here are willing to lend a helping hand when you ask and Lee has helped often.
It's easy communicating face to face but through the forums it is important to be very specific
when discussing programing because as you know one miss step and errors occur.

I'll have more time in the morning & will be glad to look into your code a little deeper.
LISP can be very frustrating until you get you get the basics down pat.

Please take the night off and start fresh tomorrow.  8-)
Title: Re: If within if
Post by: BlackBox on January 08, 2012, 09:35:56 PM
Code: [Select]
(if
    (or
        (= "Yes" (setq opt (getkword "\nSelect an option [Yes/No] <Yes>: ")))
        (= nil opt)
    )
    ;; Yes, or Enter
    ;; No
)

This says: "If (<opt> or (not <opt>)): do this ..."

The IF statement is redundant since the 'else' expression will NEVER be evaluated (<opt> can only be nil or non-nil).

My goof, typed quickly on my iPhone :oops:

Fixed code here to be more like what I was going after; my bad.
Title: Re: If within if
Post by: Lee Mac on January 09, 2012, 07:36:44 AM
Dude, chill out - I was only trying to help.  :-o

You know something, I am a firm believer that you browbeat, criticize, or just talk negatively to some one in front of everyone.

Example?
Title: Re: If within if
Post by: BlackBox on January 09, 2012, 09:35:10 AM
*Looks for Alan's 'popcorn' GIF*  :?
Title: Re: If within if
Post by: Ketxu on January 09, 2012, 10:57:27 AM
Hmmmm, whats that?  If I should have pasted the code as an attachment, then I'm sorry.  If so how would I do that?  If that is not the case, then what are you talking about?  Is that better?  I was wondering if that was what it was for.  Uh next time, why don't you do a private email and clue me in then  wasting the time to do this.  Sorry I offended you.
Srr..English isn't my language
but, why i've to sent sth private with that small problem ? Or mod 'll do ?
And, if you've edited your post, you don't need to explain ^^ Maybe it's a ex of wasting the time.
Sorry if I offended you, too  ;-)
Title: Re: If within if
Post by: CAB on January 09, 2012, 11:46:56 AM
Nick,
See the revised code below. Notes added for explanation.
I did NO testing and the error handler is disabled so it should point you to any errors.

Code: [Select]
;;               Copyright© 2012 by Nick Haury                     ;;;
;;;;**************************************************************;;;;

;;  NOTE by CAB
;;  I made some assumptions which affects my changes to your routine.



;;;                        Start Routine                          ;;;
(defun c:smc (/ ; LOCAL variables follow
              *error* ; error routine declaried local
              mbrs ch cl dep memshna memstyna p1 p2 p3 p4 p5 sp s_cmd s_orth s_osm wid x1 x2 x3 y1 y2
             )

  ;;  NOTE: error routines should be made LOCAL and placed with in the main defun
  ;;  During testing the error routine should be disab;ed as you do not want
  ;; to trap any errors, so use

  ;|  this disables the error routine

(defun *error* (msg);                                                 
  (if (/= msg "Function cancelled") ;                                 
    (princ (strcat "\nAutoLISP Error:  " msg)) ;                     
    (terpri);                                                         
  );                                                                 
  (setvar "CMDECHO" S_CMD)              ;                             
  (setvar "ORTHOMODE" S_ORTH)           ;                             
  (setvar "OSMODE" S_OSM)               ;                             
  (command "-layer" "s" CL "" "redraw") ;                             
); End defun         
|; ; end of error routine disable



  ;;            Subroutine to end program                               
  ;;  subroutines should be cantained within the main defun unless thay are used
  ;;  by other routines, in that case they are libriary routines


  (defun shapename (p) ; point is passed here from calling function
    (command "_-AecsMemberShapeDefine"
             "_New"  memshna "_Graphics" "_Low" (entlast)  ""
             p "_Medium" (entlast)
             p "_High" (entlast)
             p "" "" ""
    ) ; End command
    (entdel (entlast))
  ) ; End defun



  ;; (start) ; use only if you have a library routine or is called more than once, else include code here
  ;; you want to keep your variables LOCAL if you can

  (graphscr) ;                             
  (setq cl (getvar "CLAYER")) ; Stores Current Layer;       
  (setq s_cmd (getvar "CMDECHO")) ; Stores Command Mode State;
  (setq s_orth (getvar "ORTHOMODE")) ; Stores Orthomode State;     
  (setq s_osm (getvar "OSMODE")) ; Stores Object Snap State;   
  (setvar "CMDECHO" 1) ; No echo;                   
  (setvar "ORTHOMODE" 1) ; Ortho on;                   
  (setvar "OSMODE" 0) ; Snap None;                 


  ;;                         Choices                               ;;;ze
  (initget "Yes No")
  (if (= (getkword "\nIs this going to be a Multi-Member Unit? [Yes or No] <No>: ") "Yes")
    (progn
      (initget "2 3 4")
      (if (null
            (setq mbrs (getkword "\nHow many members will make up this Multi-Member Unit? (2, 3, or 4)  <2> "))
          )
        (setq mbrs "2")
      ) ; End if
    ) ; End progn
    (setq mbrs "1")
  ) ; End if

  (setq sp '(0 0))
  (initget (+ 1 2 4))
  (setq wid     (getreal "\nWhat is the width of this Member Shape?  "))
  (initget (+ 1 2 4))
  (setq dep     (getreal "\nWhat is the depth of this Member Shape?  "))
  (setq memshna (getstring t "\nWhat is the name of the Member Shape? "))



  ;; ERROR check befor proceeding
  (if (and ; all the following must be true or (not nill)
        (> wid 0)
        (> dep 0)
        (/= "" memshna)
      )
    (progn

  ;;                        Do the Math                            ;;;
  (setq x1 (car sp)
        x2 (+ x1 (/ wid 2.0))
        x3 (+ x1 wid)
        y1 (cadr sp)
        y2 (+ y1 dep)
  ) ; End setq
  ;;                       Point Assignment                        ;;;
  (setq p1 (list x1 y1)
        p2 (list x2 y1)
        p3 (list x3 y1)
        p4 (list x3 y2)
        p5 (list x1 y2)
  ) ; End setq

  ;;                         Lets Draw                             ;;;
  (command "_.pline" p1 p3 p4 p5 "c")

  ;;          Let's Define the Multi-Member Shapes & Styles        ;;;
  (cond
    ((= mbrs "1")
     (setq memstyna (getstring t "\nWhat is the Member Style Name going to be? ")) ; End setq
     (shapename p2)
     (command "-MemberStyle" "_New" memstyna "_Component" "_Edit" "1" "_Name" "Section" "_STart" "_SHape" memshna ""
              "_ENd" "_SHape" memshna "" "" "" "" ""
             ) ; End command
    ) ; End predicate1
    ((= mbrs "2")
     (progn
       (setq memstyna (getstring t "\nWhat is the Member Style Name going to be?  ")) ; End setq
       (shapename p2)
       (command "-MemberStyle" "_New" memstyna "_Component" "_Edit" "1" "_Name" "Section" "STart" "_SHape" memshna ""
                "_ENd" "_SHape" memshna "" "" "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape" memshna "_Offset"
                "" wid "" "" "_ENd" "_SHape" memshna "_Offset" "" "" "" "" "" "" "" "" ""
               ) ; End command
     ) ; End progn
    ) ; End predicate2
    ;;          Let's Define the Triple Multi-Member Shape & Style          ;;;
    ((= mbrs "3")
     (progn
       (setq memstyna (getstring t "\nWhat is the Member Style Name going to be?  ")) ; End setq
       (shapename p2)
       (command "-MemberStyle" "_New" memstyna "_Component" "_Edit" "1" "_Name" "Section" "STart" "_SHape" memshna ""
                "_ENd" "_SHape" memshna "" "" "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape" memshna "_Offset"
                "" wid "" "" "_ENd" "_SHape" memshna "_Offset" "" "" "" "" "" "" "" "" ""
               ) ; End command
     ) ; End progn   
    ) ; End predicate3
    ;;          Let's Define the Quadruple Multi-Member Shape & Style          ;;;
    ((= mbrs "4")
     (setq memstyna (getstring t "\nWhat is the Member Style Name going to be?  ")) ; End setq
     (shapename p2)
     (command "-MemberStyle" "_New" memstyna "_Component" "_Edit" "1" "_Name" "Section" "STart" "_SHape" memshna ""
              "_ENd" "_SHape" memshna "" "" "_Add" "_Edit" "2" "_Name" "Section" "_Start" "_SHape" memshna "_Offset" ""
              wid "" "" "_ENd" "_SHape" memshna "_Offset" "" "" "" "" "" "" "" "" ""
             ) ; End command
    ) ; End predicate4
  ) ; End cond

 
   ) ; progn
   (princ "\n***  Error in user input  ***")
 ) ; endif

 
  (princ)

  ;;(stop) ; use only if you have a library routine or is called more than once, else include code here
  (setvar "CMDECHO" s_cmd) ; Restores Stored Command Echo
  (setvar "OSMODE" s_osm) ; Restores Stored Object Snap
  (command "-LAYER" "s" cl "") ; Restores Current Layer State

) ; End C:SMC

Title: Re: If within if
Post by: dgorsman on January 09, 2012, 12:13:09 PM
Stupid question time: OP, are you stepping through your code to ensure the logic is operating properly, and inspecting variables as you go?
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 12:23:44 PM
That's my problem, it isn't acting logically. But I can't get it to step, but I think it is at the point when you decide that you want a multi unit and pic tha tyou want (2), it seems as if I have a syntax problem here and it just skips it and goes to the end and operates the single part of the routine.  I don't know any way to say it better that this.
Title: Re: If within if
Post by: CAB on January 09, 2012, 12:36:27 PM
Nick did you try the code I posted?

Do you get an error message?
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 12:44:20 PM
Not yet, I'm just now getting into the office and I wanted to post that answer, I'll get onto that code and try and see what I did wrong,  I do know what I hadn't finished yet though
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 01:51:51 PM
Boy I sure wish they had a smilie face scratching his head! :)

OK, CAB, why did you put these, (initget (+ 1 2 4)), here?  Oh oh, I just remembered why!  You don't know how good it feels to access a part of my memory that once was lost by those strokes.  Oh, this is so cool, praise GOD!!!!
Thank You CAB, this is now getting fun.
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 02:15:22 PM
OK, I bite, why the p2 after the shapename function?
Title: Re: If within if
Post by: CAB on January 09, 2012, 02:39:41 PM
Rather than making p2 a global variable I sent it as an argument to the sub-function.
The p in the function keeps it local to that function.

Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 02:49:49 PM
Uh, you do know that p2 is already called as a point, don't you?  Also, when you call the p before the "_Medium, _High, and the "" "" "",  it seems to me that it is going to bomb the command string.  Those are a specific set of answers to question that will define a structural member shape and style.  Or am I missing something?
Title: Re: If within if
Post by: CAB on January 09, 2012, 03:27:02 PM
I am using ACAD 2006 so I can not test the routine but it appears to me that my modifications should work as intended.
The variable p2 is assigned a value at line 105 and never changed again. The sub function calls are later in the routine
and therefore use the same p2 as you intended. Only difference is that I have made it an argument in the sub function call.
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 03:41:31 PM
Just tried it on the command line and using the 'p' before the _Medium and so forth doesn't work.  As far as the p2 is concerned, it is only used for a point to define the position of the baseline in the profile that is defined and then that profile is deleted after the shape is defined.  What am I missing here, it seem that you are defining that point and defining it again as just p
Title: Re: If within if
Post by: CAB on January 09, 2012, 03:48:39 PM
I'm a little confused.
Does the routine I posted work?

Do you call the sub-function shapename from the command line for any reason?
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 03:55:51 PM
On the command line you type out what is in that function, but it can be used 4 different times.  I'm lost, where do you call out 'p' as equal to 'p2'?
Title: Re: If within if
Post by: CAB on January 09, 2012, 04:03:38 PM
(setq p2 '(10 25))
(shapename p2) ; sends the value (10 25) to the sub function shapename
(defun shapename (p)  ; this assigns (10 25) to the variable p
when shapename returns to the calling rutine the variable p is destroyed.

I have to go off for several hours..
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 04:34:52 PM
That's not what I'm asking it to do, the memshna is used the same but in diferent conditions.  Here are the questions that the command line asks and the answers I put.
Code: [Select]
Command: _-AECSMEMBERSHAPEDEFINE
Shape [New/Copy/Edit/Purge/?]: n
New style name or [?]: 2x12

New style 2x12 created.

Shape definition [Name/Description/Graphics]: G

Shape designation [Low detail/Medium detail/High detail]: L

Select lines, arcs, circles, or polylines for Low Detail: Here I put (entlast) and it returns: 1 found

Select lines, arcs, circles, or polylines for Low Detail: <enter out of command>

Insertion point or [Add entity]:Here is put the defined point 'p2'

Shape designation [Low detail/Medium detail/High detail]: M

Select a closed polyline, spline, ellipse, or circle for an outer ring:Here I put (entlast)

Insertion point or [Add ring/Centroid]:Here is put the defined point 'p2'

Shape designation [Low detail/Medium detail/High detail]: H

Select a closed polyline, spline, ellipse, or circle for an outer ring:Here I put (entlast)

Insertion point or [Add ring/Centroid]:Here is put the defined point 'p2'

Shape designation [Low detail/Medium detail/High detail]: <enter out of command>

Shape definition [Name/Description/Graphics]: <enter out of command>

Shape [New/Copy/Edit/Purge/?]: <enter out of command>

So you see the line of code is just the answers to the above question, and I don't need 'p'
Title: Re: If within if
Post by: BlackBox on January 09, 2012, 05:37:55 PM
You, who shall not be named, may want to reconsider posting your phone number publically in your signature. Just saying.
Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 05:55:08 PM
Oooouh, you think?????
Title: Re: If within if
Post by: CAB on January 09, 2012, 07:37:59 PM
That's not what I'm asking it to do, the memshna is used the same but in diferent conditions.  Here are the questions that the command line asks and the answers I put.

So you see the line of code is just the answers to the above question, and I don't need 'p'

The variable p in shapename is p2, just a LOCAL form of it.

Title: Re: If within if
Post by: caddman6425 on January 09, 2012, 07:56:07 PM
But you don't need it, why define that point twice, just use p2, it's only used in that one spot
Title: Re: If within if
Post by: CAB on January 09, 2012, 11:13:42 PM
Because it's proper form to keep variables LOCALized.
It works both ways. SO do as you see fit.  8-)
Title: Re: If within if
Post by: caddman6425 on January 10, 2012, 12:50:05 AM
I'm sorry, I just don't understand.  Again, I'm sorry.
Title: Re: If within if
Post by: Kerry on January 10, 2012, 03:49:09 AM
I'm sorry, I just don't understand.  Again, I'm sorry.
http://exchange.autodesk.com/autocad/enu/online-help/search#WS73099cc142f4875516d84be10ebc87a53f-7c3f.htm
http://exchange.autodesk.com/autocad/enu/online-help/search#WS1a9193826455f5ff18cb41610ec0a2e719-7358.htm
http://exchange.autodesk.com/autocad/enu/online-help/search#WS73099cc142f4875516d84be10ebc87a53f-7c3e.htm
http://exchange.autodesk.com/autocad/enu/online-help/search#WS1a9193826455f5ff18cb41610ec0a2e719-7356.htm

http://www.afralisp.net/autolisp/tutorials/quick-start.php

... as well as inumerable mentions here at TheSwamp
Title: Re: If within if
Post by: caddman6425 on January 10, 2012, 11:50:57 AM
Thank You,I will study