Author Topic: If within if  (Read 3947 times)

0 Members and 1 Guest are viewing this topic.

caddman6425

  • Guest
Re: If within if
« Reply #15 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

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: If within if
« Reply #16 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")

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: If within if
« Reply #17 on: January 08, 2012, 06:45:40 PM »
OOOKKKay, uh, where and how would I use this? :|

Use what?

caddman6425

  • Guest
Re: If within if
« Reply #18 on: January 08, 2012, 06:55:51 PM »
Soooo, I won't use the 'IF' here at this point?

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: If within if
« Reply #19 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.

caddman6425

  • Guest
Re: If within if
« Reply #20 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)

ronjonp

  • Needs a day job
  • Posts: 7148
Re: If within if
« Reply #21 on: January 08, 2012, 08:17:23 PM »
Dude...chill out.  :-o

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC

caddman6425

  • Guest
Re: If within if
« Reply #22 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!

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: If within if
« Reply #23 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-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

BlackBox

  • King Gator
  • Posts: 3745
Re: If within if
« Reply #24 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.
« Last Edit: January 09, 2012, 12:24:44 AM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

Lee Mac

  • Seagull
  • Posts: 12390
  • London, England
Re: If within if
« Reply #25 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?

BlackBox

  • King Gator
  • Posts: 3745
Re: If within if
« Reply #26 on: January 09, 2012, 09:35:10 AM »
*Looks for Alan's 'popcorn' GIF*  :?
"How we think determines what we do, and what we do determines what we get."

Ketxu

  • Newt
  • Posts: 104
Re: If within if
« Reply #27 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  ;-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10388
Re: If within if
« Reply #28 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

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

dgorsman

  • Water Moccasin
  • Posts: 2422
Re: If within if
« Reply #29 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?
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}