Jump to content

Recommended Posts

Posted

I have a LISP that looks something like this

 

(defun c:usermenu ()
(initget 2 "duplicate move rotate")
(setq ans (getkword "\nAdjustment? (Duplicate/Move/Rotate): "))
(if
  (= ans "duplicate")
   (progn
      "Do a Copy, etc etc "
   )
 )
 (if
  (= ans "move")
   (progn
      "Move something, etc etc"

.....You get the idea

At the moment, if the user hits 'enter' when a keyword is requested, the program will end and do nothing, (which is fine).

 

I would like the user to be able to select the option that he or she would like, AutoCAD to perform that option and then return to the keyword menu - and then if the user presses enter (with no keyword), the LISP routine will finish; or else (with a keyword) complete the option selected and again return to the menu.

 

Any help is much appreciated. :)

Posted

Here is a lisp that has what you want in it. You can us what you need.

 

(defun c:setup ( / SHEET SCALE SF1)
 (initget "1 2 3 4 Exit")
 (setq SHEET (getkword "\nEnter Sheet [1]22X34,[2]24X36,[3]30X42,[4]36X48/<Exit>: "))
 (if (or (not SHEET) (= SHEET "Exit")) (exit))
 (initget "1 2 3 4 5 6 7 8 9 Exit")
 (setq SCALE (getkword "\nEnter Scale [1]FULL,[2]1/2,[3]1/4,[4]1/8,[5]1/20,[6]1/30,[7]1/40,[8]1/50,[9]custom/<Exit>: "))
 (if (or (not SCALE) (= SCALE "Exit")) (exit))

 (setq SCALE
  (cond
    ((= SCALE "1")   1.0)
    ((= SCALE "2")  24.0)
    ((= SCALE "3")  48.0)
    ((= SCALE "4")  96.0)
    ((= SCALE "5") 240.0)
    ((= SCALE "6") 360.0)
    ((= SCALE "7") 480.0)
    ((= SCALE "8") 600.0)
    ((= SCALE "9")
      (initget "Exit")
      (setq SF1 (getreal "\nEnter the desired scale factor/<Exit>: "))
      (if (or (not SF1) (= SF1 "Exit")) (exit))
      SF1
    ) ;_ c9
  ) ;_ cond
 ) ;_ setq
 (command ".DIMSCALE" SCALE ".LTSCALE" (/ SCALE 2.0))
 (cond
   ((= SHEET "1")
    ;; 22X34
    ;; DO SOMETHING FOR THIS SHEET
   ) ;_ c1
   ((= SHEET "2")
    ;; 24X36
    ;; DO SOMETHING FOR THIS SHEET
   ) ;_ c2
   ((= SHEET "3")
    ;; 30X42
    ;; DO SOMETHING FOR THIS SHEET
   ) ;_ c3
   ((= SHEET "4")
    ;; 36X48
    ;; DO SOMETHING FOR THIS SHEET
   ) ;_ c4
 ) ;_ cond
(princ "\nDimscale = ") (princ (getvar "dimscale"))
(princ "\nLTscale = ") (princ (getvar "ltscale"))
 (princ)
) ;_ defun c:setup

 

Hope this helps!!!

Posted

For example:

 

(defun c:test(/ cFlag ans)
 (while(not cFlag)
   (initget "Duplicate Move Rotate")
   (setq ans(getkword "\nAdjustment? [Duplicate/Move/Rotate]: "))
   (cond
     ((= ans "Duplicate")
      (alert "You select Duplicate.\n\nPress Ok to return menu...")
      ); end condition #1
     ((= ans "Move")
      (alert "You select Move.\n\nPress Ok to return menu...")
      ); end condition #2
     ((= ans "Rotate")
      (alert "You select Rotate.\n\nPress Ok to return menu...")
      ); end condition #3
     (T
      (alert "You press Enter.\n\nGoodbuy Lee Mac guy:)")
      (setq cFlag T)
      ); end condition #3
     ); end cond
   ); end while
 (princ)
 ); end of c:test

 

Because don't you localize your variables? In this case you must localize 'cFlag' variable or write (setq cFlag nil) at program begin. Localize is right way...

Posted

If it was me I would use this lisp and just set my Default Mode under Righ-Click Customization, to be Repeat Last Command. So when the lisp ends, you can just do a right click to start it again or just go on about you business. I also change the key in command so you don't have to type out the whole thing just the first letter now.

 

(defun c:test ()
  (initget "D M R")
  (setq ans (getkword "\nAdjustment? [D]uplicate,[M]ove,[R]otate]: "))
    (cond
     ((= ans "D")
       (command "_copy" pause pause)
       );end cond #1
     ((= ans "M")
       (command "_move" pause pause)
      );end cond #2
     ((= ans "R")
       (command "_rotate" pause pause pause)
      );end cond #3
    );end cond
  (princ)
);end c:test

Posted

Thanks for all the help, much appreciated.

 

I will most likely use your method ASMI thanks

 

Because don't you localize your variables?

 

I would localize normally, but I wrote the LISP quickly. :)

Posted

ASMI, I have used your method and keep receiving an error like the one shown below:

error - syntax error

 

The error occurs upon loading the LISP routine. Any Ideas?

Posted
error - syntax error

 

Can be what be parenthsess are lost? Or error is outside this code? All works for me. It is too simple code not to work.

Posted

Can you please remember to use descriptive thread titles which help the search function to work!

Posted

This is a variation of the example from ASMI. It does not use the Flag variable but uses a progn

to wrap the code. Basically the last return value is passed to the progn & it in turn passes this

value to the while loop. So to exit the loop pass nil. To say in the loop pass a non nil value.

The advantage is that you can call a routine from the cond and then have that routine return

the value to exit or stay in the loop.

(defun c:test (/ ans)
 (while
   (progn
     (initget "Duplicate Move Rotate")
     (setq ans (getkword "\nAdjustment? [Duplicate/Move/Rotate]: "))
     (cond
       ((= ans "Duplicate")
        (alert "You select Duplicate.\n\nPress Ok to return menu...")
        t ; stay in loop
       ) ; end condition #1
       ((= ans "Move")
        (alert "You select Move.\n\nPress Ok to return menu...")
        t ; stay in loop
       ) ; end condition #2
       ((= ans "Rotate")
        (alert "You select Rotate.\n\nPress Ok to return menu...")
        t ; stay in loop
       ) ; end condition #3
       (T
        (alert "You press Enter.\n\nGoodbuy Lee Mac guy:)")
        nil ; exit loop
       ) ; end condition #3
     )   ; end cond
   )     ; end progn
 )       ; end while
 (princ)
)         ; end of c:test

Posted

Lee Mac,

You may edit your first post & change the thread title now.

Maybe "Manage getkword Options"

Posted

Thanks CAB,

 

I have used ASMI's code and that seems to work, but as yours eliminates the need for the cFlag, I'll probably end up using that instead.

 

Thanks as always. :)

Posted

I have tried to change the title of the thread, but can only seem to change the title of my first post.

 

Again, my apologies for my bad post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...