EYNLLIB Posted December 2, 2024 Posted December 2, 2024 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. I'd like the user to: Run the command Select the entity 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) ) Quote
ronjonp Posted December 2, 2024 Posted December 2, 2024 (edited) If you have PICKFIRST set to 1 you should not have to check for an implied selection. Maybe this? (defun c:foo (/ s) (if (setq s (ssget)) (setvar 'clayer (cdr (assoc 8 (entget (ssname s 0))))) ) (princ) ) Edited December 2, 2024 by ronjonp Quote
EYNLLIB Posted December 2, 2024 Author Posted December 2, 2024 (edited) 17 minutes ago, ronjonp said: If you have PICKFIRST set to 1 you should not have to check for an implied selection. Maybe this? (defun c:foo (/ cl s) (if (setq s (ssget ":L")) (progn (setq cl (list (cons 8 (getvar 'clayer)))) (foreach e (vl-remove-if 'listp (mapcar 'cadr (ssnamex s))) (entmod (append (entget e) cl))) ) ) (princ) ) i think you confused the intention behind my script but gave me direction on 'clayer vs _.layer. modified the second portion of my code accordingly and it works. strange enough i do have pickfirst set to 1, but still needed to delineate out the options in my code Thanks! Quote ;; No pre-selection, prompt for object selection (if (setq ent (car (entsel "\nSelect an object: "))) (progn (setq lay (cdr (assoc 8 (entget ent)))) (setvar 'clayer lay) (princ (strcat "\nCurrent layer set to: " lay)) ) ) ) Edited December 2, 2024 by EYNLLIB Quote
ronjonp Posted December 2, 2024 Posted December 2, 2024 Check my post above again .. I had initially misread what you were trying to do and fixed it but not before you read the old one Quote
EYNLLIB Posted December 2, 2024 Author Posted December 2, 2024 2 minutes ago, ronjonp said: Check my post above again .. I had initially misread what you were trying to do and fixed it but not before you read the old one hah! guess i was too quick...it works as intended, except i still have to confirm selection for objects i don't pre-select Quote
ronjonp Posted December 2, 2024 Posted December 2, 2024 Weird. I cannot replicate that on my system. From the AutoCAD help file: I Implied selection; objects selected while the AutoCAD PICKFIRST system variable is in effect. Note: The ssget function returns a valid selection set or nil. If an object is selected when the function is called, a valid selection set is returned. Quote
BIGAL Posted December 2, 2024 Posted December 2, 2024 (edited) If you only want to set the layer then why not use what is inbuilt. There should be a command version so could shortcut it, lll. Maybe laymcur. Edited December 2, 2024 by BIGAL Quote
ronjonp Posted December 3, 2024 Posted December 3, 2024 1 hour ago, EYNLLIB said: hah! guess i was too quick...it works as intended, except i still have to confirm selection for objects i don't pre-select @EYNLLIB Try this .. it forces single object selection (defun c:foo (/ s) (if (setq s (ssget "_:S")) (setvar 'clayer (cdr (assoc 8 (entget (ssname s 0))))) ) (princ) ) 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.