Help with selection confirmation

Help with selection confirmation

king
Enthusiast Enthusiast
558 Views
3 Replies
Message 1 of 4

Help with selection confirmation

king
Enthusiast
Enthusiast

For my code below the first section for preselected entities works as intended, but using ssget in the second section requires the user to confirm the selection. The attached image shows how the code wants the user to continue selecting objects (or enter) after an object is selected

 

I'd like the user to:

  1. Run the command
  2. Select the entity
  3. Have layer of the selected entity be set to current without confirmation

 

Any ideas?

 

thanks in advance

 

 

(defun c:TEC (/ ss ent entLayer)
  (vl-load-com)
  (setvar "CMDECHO" 0)
  ;; First check for preselected entities
  (if (setq ss (ssget "_I"))
    (progn
      (setq ent (ssname ss 0))
      (setq entLayer (cdr (assoc 8 (entget ent))))
      (command "_.layer" "_set" entLayer "")
      (princ (strcat "\nCurrent layer set to: " entLayer))
    )
    ;; If no preselection, prompt for selection
    (if (setq ss (ssget))
      (progn
        (setq ent (ssname ss 0))
        (setq entLayer (cdr (assoc 8 (entget ent))))
        (command "_.layer" "_set" entLayer "")
        (princ (strcat "\nCurrent layer set to: " entLayer))
      )
      (princ "\nNo object selected.")
    )
  )
  (setvar "CMDECHO" 1)
  (princ)
)
king_0-1733176729199.gif

 

 

 

 

0 Likes
559 Views
3 Replies
Replies (3)
Message 2 of 4

ec-cad
Collaborator
Collaborator

You could use (entsel) function, as in:

(defun c:TEC (/ ss ent entLayer)
  (vl-load-com)
  (setvar "CMDECHO" 0)
  ;; First check for preselected entities
  (if (setq ss (ssget "_I"))
    (progn
      (setq ent (ssname ss 0))
      (setq entLayer (cdr (assoc 8 (entget ent))))
      (command "_.layer" "_set" entLayer "")
      (princ (strcat "\nCurrent layer set to: " entLayer))
    ); progn
  ); if
  ;; If no preselection, prompt for selection
  (if (not (setq ss (ssget "_I")))
   (progn
    (setq ent (entsel))
     (if ent
      (progn
       (setq entLayer (cdr (assoc 8 (entget (car ent)))))
       (command "_.layer" "_set" entLayer "")
       (alert (strcat "\nCurrent layer set to: " entLayer))
      ); progn
       (princ "\nNo object selected.")
     ); if
   ); progn
  ); if
;   (if (setq ss (ssget))
;      (progn
;        (setq ent (ssname ss 0))
;        (setq entLayer (cdr (assoc 8 (entget ent))))
;        (command "_.layer" "_set" entLayer "")
;        (princ (strcat "\nCurrent layer set to: " entLayer))
;      )
;      (princ "\nNo object selected.")
;    )
;  )
  (setvar "CMDECHO" 1)
  (princ)
)

 

ECCAD

0 Likes
Message 3 of 4

CodeDing
Mentor
Mentor

@king ,

 

Nothing wrong with practicing your Lisp skills, but in case you did not know, this command exists already. It is called LAYMCUR.

See Here:

https://help.autodesk.com/view/ACD/2024/ENU/?guid=GUID-E44FA50E-DB98-48C4-AE6B-052ED7287497 

 

Best,

~DD

Message 4 of 4

ronjonp
Mentor
Mentor

@ec-cad I think the more succinct solution ( other than using laymcur ) is forcing single object selection (ssget "_:S").

0 Likes