Jump to content

Recommended Posts

Posted

 

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:

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

 

 

 

Posted (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 by ronjonp
Posted (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 by EYNLLIB
Posted

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 😂

Posted
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

Posted

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.

2024-12-02_15-51-21.gif

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

 

image.png.6b0d2c7a077f4a67c99d8926a9d0d187.png

 

Maybe laymcur.

Edited by BIGAL
Posted
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)
)

 

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