Jump to content

Recommended Posts

Posted (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 by NoroZorro
Posted

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)
)

Posted

Thank you, i will put this code on my analyze code list

Posted

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
  )
)

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...