View Full Version : A command inside a cond
tflaherty
2005-05-20, 10:22 PM
Is what I'm trying to here correct or can you not have a "command" function inside a "cond statement?
(defun section (/)
(initget "Left Right")
(setq sectres (getkword "Specify which end section to insert: [Left/Right] "))
(if (= sectres "Left")
(progn
(setq sectipt llcrnr)
(cond ((= vhght 9) (command "insert" 9secleft sectipt "1" "1" "0"))
((= vhght 10) (command "insert" 10secleft sectipt "1" "1" "0"))
((= vhght 11) (command "insert" 11secleft sectipt "1" "1" "0"))))
(progn
(setq sectipt lrcrnr)
(cond ((= vhght 9) (command "insert" 9secright sectipt "1" "1" "0"))
((= vhght 10) (command "insert" 10secright sectipt "1" "1" "0"))
((= vhght 11) (command "insert" 11secright sectipt "1" "1" "0")))))
(princ)
)
scwegner
2005-05-20, 10:31 PM
Your syntax is fine. Two problems though: you need to use "-insert" to suppress the dialog box and the name of your block has to be in quotes. ...or is that a variable? If it's a variable, you can't start a variable with a number.
tflaherty
2005-05-20, 10:45 PM
I made those changes but it still kicks me out as soon as I type in l for left. Is that because l is already defined as a shortcut to the line command?
scwegner
2005-05-20, 10:52 PM
I made those changes but it still kicks me out as soon as I type in l for left. Is that because l is already defined as a shortcut to the line command?
Nah, that's not it. Think of how many commands have keyword options that use the same letters as command aliases. Can you imagine programming around all that?
Can you post what you've got now? Have you tried running it through VLIDE to see exactly where it's dumping you out?
tflaherty
2005-05-20, 11:03 PM
Here's what I've got so far. I think I've found the problem and here's my solution.
The problem: at the prompt for ceiling height (setq vhght......) the user inputs 9', 10' etc., which AutoLISP converts to inches (i.e 10' = 120). So, when it gets to the cond statements: (cond (= vhght 9) ....) it craps out becuase obviously 120 doesn't equal 9, 10 or 11.
The easiest solution would be to change the cond statements to:
(cond (= vhght (* 12 9))...)
Is there another way or am I on the right track?
(defun section (/)
(initget "Left Right")
(setq
sectres (getkword
"\nSpecify which end section to insert: [Left/Right] "
) ;_ end of getkword
) ;_ end of setq
(if (= sectres "Left")
(progn
(setq sectipt llcrnr)
(cond ((= vhght 9)
(command "-insert" "9secleft" sectipt "1" "1" "0")
)
((= vhght 10)
(command "-insert" "10secleft" sectipt "1" "1" "0")
)
((= vhght 11)
(command "-insert" "11secleft" sectipt "1" "1" "0")
)
) ;_ end of cond
) ;_ end of progn
(progn
(setq sectipt lrcrnr)
(cond ((= vhght 9)
(command "-insert" "9secright" sectipt "1" "1" "0")
)
((= vhght 10)
(command "-insert" "10secright" sectipt "1" "1" "0")
)
((= vhght 11)
(command "-insert" "11secright" sectipt "1" "1" "0")
)
) ;_ end of cond
) ;_ end of progn
) ;_ end of if
(princ)
) ;_ end of defun
(defun c:INTRS (/)
(setq VWDTH (getdist "\nSpecify length of view: ")
VHGHT (getdist "\nSpecify ceiling height: ")
VINPT (getpoint "\nSelect point to insert view: ")
LLCRNR VINPT
ULCRNR (list (car LLCRNR) (+ (cadr LLCRNR) VHGHT))
LRCRNR (list (+ (car LLCRNR) VWDTH) (cadr LLCRNR))
URCRNR (list (car LRCRNR) (cadr ULCRNR))
) ;_ end of setq
(command "rectang"
VINPT
(STRCAT "@" (rtos VWDTH) "," (rtos VHGHT))
"explode"
"last"
) ;_ end of command
(initget "Section End Base Wall Crown")
(setq ETYPE
(getkword
"\nEntity to create: [end Section/cabinet end/Base run/Wall run/Crown moulding] "
) ;_ end of getkword
) ;_ end of setq
(cond ((= etype "Base") (base))
((= etype "Wall") (wall))
((= etype "Section") (section))
((= etype "End") (end))
((= etype "Crown") (crown))
) ;_ end of cond
(princ)
) ;_ end of defun
tflaherty
2005-05-20, 11:35 PM
Well, I had it working, so I added the next option which is to insert both the right & left end sections, but now it doesn't work. Here's what I've got:
(defun section (/)
(initget "Left Right Both")
(setq
sectres
(getkword
"\nSpecify which end section to insert: [Left/Right/Both] "
) ;_ end of getkword
) ;_ end of setq
(cond (= sectres "Left")
(progn
(setq lsectipt llcrnr)
(cond ((= vhght (* 12 9))
(command "-insert" "9secleft" lsectipt "1" "1" "0")
)
((= vhght (* 12 10))
(command "-insert" "10secleft" lsectipt "1" "1" "0")
)
((= vhght (* 12 11))
(command "-insert" "11secleft" lsectipt "1" "1" "0")
)
) ;_ end of cond
)
(= sectres "Right")
(progn
(setq rsectipt lrcrnr)
(cond ((= vhght (* 12 9))
(command "-insert" "9secright" rsectipt "1" "1" "0")
)
((= vhght (* 12 10))
(command "-insert" "10secright" rsectipt "1" "1" "0")
)
((= vhght (* 12 11))
(command "-insert" "11secright" rsectipt "1" "1" "0")
)
) ;_ end of cond
)
(= sectres "Both")
(progn
(setq lsectipt llcrnr
rsectipt lrcrnr
) ;_ end of setq
(cond ((= vhght (* 12 9))
(command "-insert" "9secright" rsectipt
"1" "1" "0" "-insert"
"9secleft" lsectipt "1" "1"
"0"
) ;_ end of command
)
((= vhght (* 12 10))
(command "-insert" "10secright" rsectipt
"1" "1" "0" "-insert"
"10secleft" lsectipt "1"
"1" "0"
) ;_ end of command
)
((= vhght (* 12 11))
(command "-insert" "11secright" rsectipt
"1" "1" "0" "-insert"
"11secleft" lsectipt "1"
"1" "0"
) ;_ end of command
)
) ;_ end of cond
)
) ;_ end of cond
(princ)
) ;_ end of defun
CAB2k
2005-05-21, 03:07 AM
Try one of these.
(defun section (/)
(initget 1 "Left Right Both")
(setq
sectres
(getkword
"\nSpecify which end section to insert: [Left/Right/Both] "
) ;_ end of getkword
) ;_ end of setq
(setq cht (itoa (/ vhght 12))) ; convert to string feet
(setq lsectipt llcrnr)
(cond
((= sectres "Left")
(command "-insert" (strcat cht "secleft") lsectipt "1" "1" "0")
)
((= sectres "Right")
(command "-insert" (strcat cht "secright") lsectipt "1" "1" "0")
)
((= sectres "Both")
(command "-insert" (strcat cht "secleft") lsectipt "1" "1" "0")
(command "-insert" (strcat cht "secright") lsectipt "1" "1" "0")
)
) ;_ end of cond
(princ)
) ;_ end of defun
;;===============================
;; Here is another way to do it
;;===============================
(defun section (/)
(initget 1 "Left Right Both")
(setq
sectres
(getkword
"\nSpecify which end section to insert: [Left/Right/Both] "
) ;_ end of getkword
) ;_ end of setq
(setq cht (itoa (/ vhght 12))) ; convert to string feet
(setq lsectipt llcrnr)
(if (member sectres '("Left" "Both"))
(command "-insert" (strcat cht "secleft") lsectipt "1" "1" "0")
)
(if (member sectres '("Right" "Both"))
(command "-insert" (strcat cht "secright") lsectipt "1" "1" "0")
)
(princ)
) ;_ end of defun
vBulletin® v3.6.7, Copyright ©2000-2010, Jelsoft Enterprises Ltd.