if else statement inside cond

if else statement inside cond

DGRL
Advisor Advisor
1,121 Views
3 Replies
Message 1 of 4

if else statement inside cond

DGRL
Advisor
Advisor

Dear forum members,

 

I have a small routine with dcl to plot some dwg

Now I need an if else statement as overlay of an cond

 

If in my dcl menu button x is selected take over all the settings and do something

If the same button is not selected do something else

 

Here is my code ( below is more text to explain!!)

 

(if(= ddiag 2)
     (progn
   ;(princ "\n Using Radio_column data...You chose ")
  
 (cond

 

  ((= Choice3 "12")
 (progn
  (c:my_plot)
 );end progn
 ) ; end choise  

 

  ((= Printer "1")
 (progn
 (princ "You selected the System printer")
 (if (= choice1 "7")(c:A3))
 (if (= choice1 "8")(c:A4L))
 (if (= choice1 "9")(c:A4P))
 (if (= choice2 "10")(c:Pr-A3L))
 (if (= choice2 "11")(c:Pr-A4L))
 (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end Printer1   
 
  ((= Printer "2")
 (progn
 (princ "You selected the DWG To PDF printer")
 (if (= choice "4")(c:PDFA0))
 (if (= choice "5")(c:PDFA1))
 (if (= choice "6")(c:PDFA2))
 (if (= choice1 "7")(c:PDFA3))
 (if (= choice1 "8")(c:PDFA4L))
 (if (= choice1 "9")(c:PDFA4P))
 (if (= choice2 "10")(c:PDF-A3L))
 (if (= choice2 "11")(c:PDF-A4L))
 (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end Printer2  
 
  ((= Printer "3")
 (progn
 (princ "Are you sure you wanna have TIF?")
 ;(command "script" scr ) nice way to make temp scr files to execute LOL
 ;(alert "Still to be implemented")
 (command "script" "AlgemeenTIFF.SCR")
  (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end printer3  
 ) ;end cond 
 ) ;end progn
 ) ;end if ddiag

 

 

What I want is that when Choice3 is selected It needs to skip Printer 1 / 2 and 3

When Choice3 is not selected is needs to do Printer 1 / 2 and 3 and skip Choice3

 

I hope I am not to confusing with this

Code can be changed in any way as long as it will work lol

I broke my head on this one so far

 

Kind regards,

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
1,122 Views
3 Replies
Replies (3)
Message 2 of 4

ВeekeeCZ
Consultant
Consultant

Not sure if i do follow you, but it seems that you need to use the IF function instead of COND.

 

(if (= Choice3 "12")
  
  (c:my_plot)
  
  (progn
    (if (Printer "1")
      (progn
        (princ "You selected the System printer")
        (if (= choice1 "7")(c:A3))
        (if (= choice1 "8")(c:A4L))
        (if (= choice1 "9")(c:A4P))
        (if (= choice2 "10")(c:Pr-A3L))
        (if (= choice2 "11")(c:Pr-A4L))
        (setvar "cmdecho" oldcmdecho)
        ))
    (if (= Printer "2")
      (progn
        (princ "You selected the DWG To PDF printer")
        (if (= choice "4")(c:PDFA0))
        (if (= choice "5")(c:PDFA1))
        (if (= choice "6")(c:PDFA2))
        (if (= choice1 "7")(c:PDFA3))
        (if (= choice1 "8")(c:PDFA4L))
        (if (= choice1 "9")(c:PDFA4P))
        (if (= choice2 "10")(c:PDF-A3L))
        (if (= choice2 "11")(c:PDF-A4L))
        (setvar "cmdecho" oldcmdecho)
        ))
    
    (if (= Printer "3")
      (progn
        (princ "Are you sure you wanna have TIF?")
        ;(command "script" scr ) nice way to make temp scr files to execute LOL
        ;(alert "Still to be implemented")
        (command "script" "AlgemeenTIFF.SCR")
        (setvar "cmdecho" oldcmdecho)
        
        ))))

 

If there is something like this:

is needs to do Printer 1 / 2 and 3 and skip Choice3

... it indicates that the COND function is not good idea, because cond allows you to take JUST ONE (the first one which is T) condition.

 

 

 

EDIT: Not sure why you have so many variables... and unique choices... this is probably good place to use COND

 

(if (= Choice3 "12")
  (c:my_plot)
  
  (progn
    (if (Printer "1")
      (progn
        (princ "You selected the System printer")
        (cond ((= choice1 "7") 	(c:A3))
              ((= choice1 "8")		(c:A4L))
              ((= choice1 "9")		(c:A4P))
              ((= choice2 "10")	(c:Pr-A3L))
              ((= choice2 "11")	(c:Pr-A4L))
              )))
    (if (= Printer "2")
      (progn
        (princ "You selected the DWG To PDF printer")
        (cond ((= choice "4")		(c:PDFA0))
              ((= choice "5")		(c:PDFA1))
              ((= choice "6")		(c:PDFA2))
              ((= choice1 "7")		(c:PDFA3))
              ((= choice1 "8")		(c:PDFA4L))
              ((= choice1 "9")		(c:PDFA4P))
              ((= choice2 "10")	(c:PDF-A3L))
              ((= choice2 "11")	(c:PDF-A4L))
              )))
    (if (= Printer "3")
      (progn
        (princ "Are you sure you wanna have TIF?")
        ;(command "script" scr ) nice way to make temp scr files to execute LOL
        ;(alert "Still to be implemented")
        (command "script" "AlgemeenTIFF.SCR")
        ))
    (setvar "cmdecho" oldcmdecho)
    ))

 

Message 3 of 4

DGRL
Advisor
Advisor

Hi @ВeekeeCZ


Thanks for the reply

When I run your routine Im getting error Error: bad function: "2"

 

This one also works, as I just fixed It lol

 

(if(= ddiag 2)
     (progn
   ;(princ "\n Using Radio_column data...You chose ")
  
  
 (if button12

(c:my_plot)
 
 
 (cond

  ((= Printer "1")
 (progn
 (princ "You selected the System printer")
 (if (= choice1 "7")(c:A3))
 (if (= choice1 "8")(c:A4L))
 (if (= choice1 "9")(c:A4P))
 (if (= choice2 "10")(c:Pr-A3L))
 (if (= choice2 "11")(c:Pr-A4L))
 (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end Printer1   
 
  ((= Printer "2")
 (progn
 (princ "You selected the DWG To PDF printer")
 (if (= choice "4")(c:PDFA0))
 (if (= choice "5")(c:PDFA1))
 (if (= choice "6")(c:PDFA2))
 (if (= choice1 "7")(c:PDFA3))
 (if (= choice1 "8")(c:PDFA4L))
 (if (= choice1 "9")(c:PDFA4P))
 (if (= choice2 "10")(c:PDF-A3L))
 (if (= choice2 "11")(c:PDF-A4L))
 (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end Printer2  
 
  ((= Printer "3")
 (progn
 (princ "Are you sure you wanna have TIF?")
 ;(command "script" scr ) nice way to make temp scr files to execute LOL
 ;(alert "Still to be implemented")
 (command "script" "AlgemeenTIFF.SCR")
  (setvar "cmdecho" oldcmdecho)
 );end progn
 ) ; end printer3  
 ) ;end cond 
 ) ;end if choice3
 ) ;end progn
 ) ;end if ddiag

 

 

This one work but im running into another problem

I will make a new topic for that one after a while ( I wanna try myself first )

 

If this was of any help please kudo and/or Accept as Solution
Kind Regards
0 Likes
Message 4 of 4

ВeekeeCZ
Consultant
Consultant

@DGRL wrote:

Hi @ВeekeeCZ

...

When I run your routine Im getting error Error: bad function: "2"

 

...

 


(= Printer "1")
0 Likes