Multiple Cond statements

Multiple Cond statements

Anonymous
Not applicable
5,151 Views
6 Replies
Message 1 of 7

Multiple Cond statements

Anonymous
Not applicable

I am trying to update a couple of lisp routines to for us changing over to annotative dimensioning. However since we are just switching I need for commands to work on the old files and the new files. I had looked into cond statements so that I could have 4 different conditions similar to what I had before. The lisp we were running before had only two conditions looking at tilemode but now i need to look at tilemode and dimanno to make sure I am entering the correct things. Here is what I have, but it wont load and vlisp says "; error: malformed list on input" and I cannot tell what the problem is from looking arond and trying new things.  Any help on this is greatly appriciated, this is what has kept us from updating to annotative dimensioning in the past. 

 

 

(defun C:CS-ENV-1 ( / TILE ANNO )

(setq TILE (getvar "tilemode"))
(setq ANNO (getvar "dimanno"))

(cond ((and (= ANNO 1) (= TILE 0)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nAnnotative Layout.")
       ) ;_ end of first condition
	((and (= ANNO 1) (= TILE 1)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nAnnotative Model.")
       ) ;_ end of second condition 
	((and (= ANNO 0) (= TILE 0)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "textsize" "3/32" "LAYON" "VPLAYER" "THAW" "*" "CURRENT" "" "VPLAYER" "FREEZE" "*dim*,*ceiling*,*flooring*,*rcp*" "CURRENT" "" "VPLAYER" "THAW" "*CS-DIM1*,*PSL-DIM1*" "CURRENT" "" "VPLAYER" "FREEZE" "*CS-DIM16*,*CS-DIM12*,*PSL-DIM16*,*PSL-DIM12*" "CURRENT" "")
	(princ "\nStandard Layout.")
       ) ;_ end of third condition
	((and (= ANNO 0) (= TILE 1)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "dimscale" "1" "textsize" "3/32" "LAYON" "-layer" "set" "CS-AW-MILLWORK1-SECT" "" "-layer" "off" "*dim*,*ceiling*,*flooring*,*rcp*" "on" "*CS-DIM1*,*PSL-DIM1*" "OFF" "*CS-DIM12*,*CS-DIM16*,*PSL-DIM16*,*PSL-DIM12*" "" "users1" ".")
	(princ "\nStandard Model.")
       ) ;_ end of fourth condition
      ) ;_ end of condition
	(princ)
)
0 Likes
Accepted solutions (1)
5,152 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

So with some help I got this to work for the cond statement but now my command line is saying dynmode nil or rejected a bunch of times. I tried to get that to turn off, but what is causing that? Here is the revised code...

 

(defun C:CS-ENV-1 ( / TILE ANNO ECHO DYNM DYNP)

(setq DYNM (getvar "dynmode"))
(setq DYNP (getvar "dynprompt"))
(setq ECHO (getvar "cmdecho"))
(setq TILE (getvar "tilemode"))
(setq ANNO (getvar "dimanno"))
(setvar "cmdecho" 0)
(setvar "dynmode" 0)
(setvar "dynprompt" 0)

(cond ;cond1
  ((and (= ANNO 1) (= TILE 0)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       ))) ;_ end of first condition

(cond ;cond2
  	((and (= ANNO 1) (= TILE 1)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       ))) ;_ end of second condition
(cond ;cond3
	((and (= ANNO 0) (= TILE 0) 
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "textsize" "3/32" "LAYON" "VPLAYER" "THAW" "*" "CURRENT" "" "VPLAYER" "FREEZE" "*dim*,*ceiling*,*flooring*,*rcp*" "CURRENT" "" "VPLAYER" "THAW" "*CS-DIM1*,*PSL-DIM1*" "CURRENT" "" "VPLAYER" "FREEZE" "*CS-DIM16*,*CS-DIM12*,*PSL-DIM16*,*PSL-DIM12*" "CURRENT" "")
	(princ "\nSet Legacy Layers and Dimscale")
       ))) ;_ end of third condition
(cond ;cond4
	((and (= ANNO 0) (= TILE 1)
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "dimscale" "1" "textsize" "3/32" "LAYON" "-layer" "set" "CS-AW-MILLWORK1-SECT" "" "-layer" "off" "*dim*,*ceiling*,*flooring*,*rcp*" "on" "*CS-DIM1*,*PSL-DIM1*" "OFF" "*CS-DIM12*,*CS-DIM16*,*PSL-DIM16*,*PSL-DIM12*" "" "users1" ".")
	(princ "\nSet Legacy Layers and Dimscale")
       ))) ;_ end of fourth condition
(setvar "cmdecho" ECHO)
(setvar "dynmode" DYNM)
(setvar "dynprompt" DYNP)
	(princ)
)
0 Likes
Message 3 of 7

Kent1Cooper
Consultant
Consultant

Don't pull it apart into separate (cond) functions -- that destroys the purpose of the function.  You're just missing closing parentheses on the (and) test portions of the conditions:

(cond
  ((and (= ANNO 1) (= TILE 0))
....
  ((and (= ANNO 1) (= TILE 1))
.... 
  ((and (= ANNO 0) (= TILE 0))
....
  ((and (= ANNO 0) (= TILE 1))
....
) ;_ end of condition

 

Fix that, and see whether it works [I didn't look deeply enough to see whether there might be any other issues...].

Kent Cooper, AIA
0 Likes
Message 4 of 7

ВeekeeCZ
Consultant
Consultant

In addition what Kent said... I would change the setting of current layer from _set to _make. It set the layer current if it's in the drawing, and if the layer does not exist yet, then it creates the new one. Prevent the error. 

 

Spoiler
(defun C:CS-ENV-1 ( / TILE ANNO ECHO DYNM DYNP)
  
  (setq DYNM (getvar "dynmode"))
  (setq DYNP (getvar "dynprompt"))
  (setq ECHO (getvar "cmdecho"))
  (setq TILE (getvar "tilemode"))
  (setq ANNO (getvar "dimanno"))
  (setvar "cmdecho" 0)
  (setvar "dynmode" 0)
  (setvar "dynprompt" 0)
  
  (cond ;cond1
    ((and (= ANNO 1) (= TILE 0))
     (setvar "cannoscale" "1'-0\" = 1'-0\"")
     (princ "\nSet Annotative Scale to Full Scale")
     ) ;_ end of first condition
    ((and (= ANNO 1) (= TILE 1))
     (setvar "cannoscale" "1'-0\" = 1'-0\"")
     (princ "\nSet Annotative Scale to Full Scale")
     ) ;_ end of second condition
    ((and (= ANNO 0) (= TILE 0))
     (setvar "cannoscale" "1'-0\" = 1'-0\"")
     (setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")
     ;(FL:LoadTable)
     (command "textsize" "3/32"
	      "LAYON" "VPLAYER" "THAW" "*" "CURRENT" "" "VPLAYER" "FREEZE" "*dim*,*ceiling*,*flooring*,*rcp*" "CURRENT" "" "VPLAYER" "THAW" "*CS-DIM1*,*PSL-DIM1*" "CURRENT" "" "VPLAYER" "FREEZE" "*CS-DIM16*,*CS-DIM12*,*PSL-DIM16*,*PSL-DIM12*" "CURRENT" "")
     (princ "\nSet Legacy Layers and Dimscale")
     ) ;_ end of third condition
    ((and (= ANNO 0) (= TILE 1))
     (setvar "cannoscale" "1'-0\" = 1'-0\"")
     (setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")
     ;(FL:LoadTable)
     (command "dimscale" "1" "textsize" "3/32"
	      "LAYON" "-layer" "make" "CS-AW-MILLWORK1-SECT" ""
	      "-layer" "off" "*dim*,*ceiling*,*flooring*,*rcp*" "on" "*CS-DIM1*,*PSL-DIM1*" "OFF" "*CS-DIM12*,*CS-DIM16*,*PSL-DIM16*,*PSL-DIM12*" "" "users1" ".")
     (princ "\nSet Legacy Layers and Dimscale")
     )
    );_ end of fourth condition
  (setvar "cmdecho" ECHO)
  (setvar "dynmode" DYNM)
  (setvar "dynprompt" DYNP)
  (princ)
)

 

0 Likes
Message 5 of 7

Anonymous
Not applicable

So If i close the and statement the lisp no longer runs through correctly. I did change the layer to make instead of set, however I am still getting the following on my command line:

 

Command: cs-env-1
FLay.tab LOADED
; error: AutoCAD variable setting rejected: "dynmode" nil
; error: AutoCAD variable setting rejected: "dynmode" nil

All layers have been turned on.; error: AutoCAD variable setting rejected: "dynmode" nil
; error: AutoCAD variable setting rejected: "dynmode" nil
; error: AutoCAD variable setting rejected: "dynmode" nil
; error: AutoCAD variable setting rejected: "dynmode" nil

 

Here is my revised code...

(defun C:CS-ENV-1 ( / TILE ANNO ECHO DYNM DYNP)

(setq DYNM (getvar "dynmode"))
(setq DYNP (getvar "dynprompt"))
(setq ECHO (getvar "cmdecho"))
(setq TILE (getvar "tilemode"))
(setq ANNO (getvar "dimanno"))
(setvar "cmdecho" 0)
(setvar "dynmode" 0)
(setvar "dynprompt" 0)

(cond
  ((and (= ANNO 1) (= TILE 0))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       )) ;_ end of first condition

  	((and (= ANNO 1) (= TILE 1))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       )) ;_ end of second condition

	((and (= ANNO 0) (= TILE 0)) 
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "textsize" "3/32" "LAYON" "VPLAYER" "THAW" "*" "CURRENT" "" "VPLAYER" "FREEZE" "*dim*,*ceiling*,*flooring*,*rcp*" "CURRENT" "" "VPLAYER" "THAW" "*CS-DIM1*,*PSL-DIM1*" "CURRENT" "" "VPLAYER" "FREEZE" "*CS-DIM16*,*CS-DIM12*,*PSL-DIM16*,*PSL-DIM12*" "CURRENT" "")
	(princ "\nSet Legacy Layers and Dimscale")
       )) ;_ end of third condition

	((and (= ANNO 0) (= TILE 1))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "dimscale" "1" "textsize" "3/32" "LAYON" "-layer" "make" "CS-AW-MILLWORK1-SECT" "" "-layer" "off" "*dim*,*ceiling*,*flooring*,*rcp*" "on" "*CS-DIM1*,*PSL-DIM1*" "OFF" "*CS-DIM12*,*CS-DIM16*,*PSL-DIM16*,*PSL-DIM12*" "" "users1" ".")
	(princ "\nSet Legacy Layers and Dimscale")
       )) ;_ end of fourth condition
(setvar "cmdecho" ECHO)
(setvar "dynmode" DYNM)
(setvar "dynprompt" DYNP)
	(princ)
)
0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

       )) ;_ end of first condition

 

is too many right parentheses -- should be

 

       ) ;_ end of first condition

 

This is where it helps to use indentation to line up all closing right parentheses [that do not occur on the same line as their opening left ones] in the same horizontal position as their opening left ones, so you can really see the relationships.  All the examples in the AutoLisp Reference structure things this way.

 

(cond
  ( ; open first condition

    (and (= ANNO 1) (= TILE 0)); test function
    (setvar "cannoscale" "1'-0\" = 1'-0\""); stuff to do if test did not return nil...
    (princ "\nSet Annotative Scale to Full Scale")
  ) ;_ end of first condition

  ( ; open second condition

....

 

The extra one was completing the (cond) function, and probably the next one was completing the command definition, so loading the file went on to perform the functions that followed that.  Since the setting of the DYNM and other variables is inside the command definition and they therefore haven't been set yet [because the command hasn't been run yet], when it got to the resetting at the end [attempted because they're outside the command definition], it had nothing to work with.

 

Kent Cooper, AIA
Message 7 of 7

Anonymous
Not applicable

So I got everything to work. I think my dynmode was being caused by another list I had loaded into my CUI. I will work on that one another day. I appricate the help! Here is the corrected code that works on annotative and our old dimscale versions. 

 

(defun C:CS-ENV-1a ( / TILE ANNO ECHO DYNM DYNP)

(setq DYNM (getvar "dynmode"))
(setq DYNP (getvar "dynprompt"))
(setq ECHO (getvar "cmdecho"))
(setq TILE (getvar "tilemode"))
(setq ANNO (getvar "dimanno"))
(setvar "cmdecho" 0)
(setvar "dynmode" 0)
(setvar "dynprompt" 0)

(cond
  ((and (= ANNO 1) (= TILE 0))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       ) ;_ end of first condition

  	((and (= ANNO 1) (= TILE 1))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(princ "\nSet Annotative Scale to Full Scale")
       ) ;_ end of second condition

	((and (= ANNO 0) (= TILE 0)) 
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "textsize" "3/32" "LAYON" "VPLAYER" "THAW" "*" "CURRENT" "" "VPLAYER" "FREEZE" "*dim*,*ceiling*,*flooring*,*rcp*" "CURRENT" "" "VPLAYER" "THAW" "*CS-DIM1*,*PSL-DIM1*" "CURRENT" "" "VPLAYER" "FREEZE" "*CS-DIM16*,*CS-DIM12*,*PSL-DIM16*,*PSL-DIM12*" "CURRENT" "")
	(princ "\nSet Legacy Layers and Dimscale")
       ) ;_ end of third condition

	((and (= ANNO 0) (= TILE 1))
	(setvar "cannoscale" "1'-0\" = 1'-0\"")
	(setq FL:FLAYTAB "C:\\Canova and Stone\\Customizations\\CS - Autodesk AutoCAD 2017\\Programming\\FLAY.TAB")(FL:LoadTable)
	(command "dimscale" "1" "textsize" "3/32" "LAYON" "-layer" "make" "CS-AW-MILLWORK1-SECT" "" "-layer" "off" "*dim*,*ceiling*,*flooring*,*rcp*" "on" "*CS-DIM1*,*PSL-DIM1*" "OFF" "*CS-DIM12*,*CS-DIM16*,*PSL-DIM16*,*PSL-DIM12*" "" "users1" ".")
	(princ "\nSet Legacy Layers and Dimscale")
       ) ;_ end of fourth condition
  ) ;_ end of condition statements
(setvar "cmdecho" ECHO)
(setvar "dynmode" DYNM)
(setvar "dynprompt" DYNP)
	(princ)
)
0 Likes