I cannot figure out why this isn't working. I am trying to insert one or another block into a drawing, and i need to do this 8 times per drawing. It should be pretty straight forward but any ideas?
(defun C:detector (/ filename gas pressure)
(repeat 8 (initget 1 "Gas Pressure")
(setq filename (getkword "\nEnter Detector Type [Gas/Pressure]: "))
(if (= filename "gas") (command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunygasdetectornew.dwg" pause "" "")
(or (if (= filename "pressure")
(command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunypressuretransmitternew.dwg" pause "" ""))
) ;;end or
) ;;end if
) ;;end repeat
)
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Solved by hmsilva. Go to Solution.
manamalewis,
perhaps something like this
(defun C:detector (/ filename gas pressure) (repeat 8 (initget 1 "Gas Pressure") (setq filename (getkword "\nEnter Detector Type [Gas/Pressure]: ")) (if (= filename "Gas");; case sensitive (command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunygasdetec?tornew.dwg" pause "" "") );; if (if (= filename "Pressure");; case sensitive (command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunypressure?transmitternew.dwg" pause "" "") );; if ) ;;end repeat );; detector
hope that helps
Henrique
Two things I notice:
The (=) function in relation to Text is case-sensitive. The (getkword) function will return text as spelled out in the (initget) function, whether the User types an upper- or lower-case initial letter. So the (if) tests need to be checking for "Gas" or "Pressure" [each capitalized].
And the (or) function is not needed -- the other possibility can be handled several ways. Merely simplifying yours, try something like this [untested]:
(defun C:detector (/ filename)
(repeat 8
(initget 1 "Gas Pressure")
(setq filename (getkword "\nEnter Detector Type [Gas/Pressure]: "))
(if (= filename "Gas")
(command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunygasdetectornew.dwg" pause "" "")
); if
(if (= filename "Pressure")
(command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunypressuretransmitternew.dwg" pause "" ""))
) ;;end if
) ;;end repeat
)
But there are better ways. Since (getkword) should ensure the User is always going to choose one of those options, you can let the Pressure possibility just be the 'else' argument to the (if) function [i.e. if it's "Gas," do this; if not, then it must be Pressure, so do that -- you don't need to check for "Pressure" explicitly]:
(defun C:detector (/ filename)
(repeat 8
(initget 1 "Gas Pressure")
(setq filename (getkword "\nEnter Detector Type [Gas/Pressure]: "))
(if (= filename "Gas")
(command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunygasdetectornew.dwg" pause "" ""); then
(command "-insert" "*T:\\acad\\schematic_circuits\\suny\\sunypressuretransmitternew.dwg" pause "" "")); else
) ;;end if
) ;;end repeat
); defun
Or, better yet, spell out the (command) and most of the drawing path/name only once, and use (if) just to feed in the variable part of the drawing name:
(defun C:detector (/ filename)
(repeat 8
(initget 1 "Gas Pressure")
(setq filename (getkword "\nEnter Detector Type [Gas/Pressure]: "))
(command "-insert"
(strcat
"*T:\\acad\\schematic_circuits\\suny\\suny"
(if (= filename "Gas") "gasdetector" "pressuretransmitter")
"new.dwg"
); strcat
pause "" ""
) ;;end command
) ;;end repeat
); defun
I've removed gas and pressure from the localized variables list -- things in that list would be only variable names that have something stored in them by (setq) [or some other lesser possibilities], not things like (initget) options.