Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Help with this lisp

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
gcsjlewis
514 Views, 4 Replies

Help with this lisp

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

)

4 REPLIES 4
Message 2 of 5
hmsilva
in reply to: gcsjlewis

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

EESignature

Message 3 of 5
Kent1Cooper
in reply to: gcsjlewis

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.

Kent Cooper, AIA
Message 4 of 5
gcsjlewis
in reply to: hmsilva

Thanks, missed the caps

Jason Lewis | CAD Technician

General Control Systems, Inc.
a PPL Energy Service Company
Tel: 518.270.8045 ext. 327 | Fax: 518.270.8042
Direct: 518.279-7544
60 Cohoes Ave, Green Island N.Y. 12183

www.gcontrol.net
P Please consider the environment before printing this email


________________________________
The information contained in this message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately, and delete the original message.
Message 5 of 5
hmsilva
in reply to: gcsjlewis

You're welcome, Jason

Henrique

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost