NoroZorro Posted June 18, 2016 Posted June 18, 2016 (edited) Привет форум, 1.Is it possible for a user to select multiple layers from a list of existing layers without playing with DCL? If yes,how? 2.Is it true, that getkword function allows to select only one item? I want the user to pick layers from a list and record picked layers ("Layer3" "Layer2" "Layer1" "0") Спасибо Edited June 19, 2016 by NoroZorro Quote
Lee Mac Posted June 19, 2016 Posted June 19, 2016 Here's a simple example: (defun getlayers ( / def itm lay lst sel ) (while (setq def (tblnext "layer" (not def))) (setq lst (cons (cdr (assoc 2 def)) lst)) ) (while (/= "" (setq lay (getstring t "\nEnter layer name <done>: "))) (cond ( (not (setq itm (car (member (strcase lay) (mapcar 'strcase lst))))) (princ (strcat "\nLayer " lay " not found.")) ) ( (member itm sel) (princ (strcat "\nLayer " itm " already selected.")) ) ( (setq sel (cons itm sel)) (princ (strcat "\nSelected layers: " (last sel))) (foreach lay (cdr (reverse sel)) (princ ", ") (princ lay)) ) ) ) (princ) ) Quote
NoroZorro Posted June 19, 2016 Author Posted June 19, 2016 Thank you, i will put this code on my analyze code list Quote
pkenewell Posted June 20, 2016 Posted June 20, 2016 To answer your question #2. (getkword) allows a user to select from a list of options established by a preceding call to the (initget) function. See the basic example of (getkword) below: ;; Initialize the options. ;; NOTE: Capitalized letter can be typed in by itself ;; i.e. "O" will return "One", "T" will return "Two", etc... ;; Optionally (initget) can be called with a bitcode of 1 to force the user to type an ;; option, rather than just <ENTER>. There are additional bitcodes as well, but ;; only bitcode 1 can apply to (getkword) ;; CORRECTION (getkword) can also accept bitcode 128 to allow other arbitrary input strings, but I would not recommend it. ;; Example: (initget 1 "One Two tHree Four") ;; (setq opt (getkword "\nYou must enter one of the following options [One/Two/tHree/Four]: ")) (initget "One Two tHree Four") (setq opt (getkword "\nSelect an Option [One/Two/tHree/Four] <One>: ")) (if (= opt nil)(setq opt "One")) ;; set the default if the user just pressed <ENTER> ;; Note (getkword) will always return the complete keyword, ;; regardless if the user used the shortcut mnemonic or the whole keyowrd. (cond ((= opt "One") ;; do code for Option 1 ) ((= opt "Two") ;; do code for Option 2 ) ((= opt "tHree") ;; do code for Option 3 ) ((= opt "Four") ;; do code for Option 4 ) ) Quote
Recommended Posts
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.