Jump to content

Recommended Posts

Posted

I hope someone could help me with a little lisp routine.

I'm looking to improve layiso command for my needs.

I would like to select some objects on some layers and isolate those layers (so far so good)...  and in the same time select a xref and a block and isolate all unfrozen layers in those as well.

Layiso command only isolates layers that block and xref are on. I would like to autoselect all block-xref entities and isolate those layers.

Posted (edited)

Yeah, sure.

With NENTSEL you van select nested items: for example items inside a XREF or Block.

 

Here's a function that turns off layers of selected nested items.

Command LOFF, for Layers OFF

 

Command NLAYISO for the question you asked for

 

;; @see https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/turning-off-layers-in-autolisp/td-p/6339611
(DEFUN LAYER_OFF (mylayer on_off / Layoff )
  ;;(setq Layoff(getstring "\Should the Layer C165-C345-EBENE turned off? (j/n): "))
  (setq Layoff "Y")
  (if (or (= Layoff "j") (= Layoff "J") (= Layoff "y") (= Layoff "Y"))
    (if (/= (tblsearch "layer" mylayer) nil)
      ;;(command "_layer" "_off" mylayer "")
      (command "_layer" on_off mylayer "")
      ;;(princ mylayer)
    );IF
  );IF
);DEFUN LAYER_OFF


;; Turns off layers of NENTSEL selection, of the layer of nested objects
(defun c:loff ( / sel obj lay lst)
	(while (setq sel (nentsel "Select object: "))
		(setq obj (car sel))
		(setq lay (cdr (assoc 8 (entget obj))))
		(LAYER_OFF lay "_off")
	)
)


;; nLayiso for Nested Layiso
(defun c:nLayiso ( / blk sel obj lay lst)
	(setq lst (list))
	(while (setq sel (nentsel "\nSelect object: "))
		(setq obj (car sel))
		(setq lay (cdr (assoc 8 (entget obj))))
		(setq lst (append lst (list lay)))
		(princ lay)
	)
	
	;; loop over all layers in the drawing
	(vlax-for lyr
		(vla-get-layers
			(vla-get-activedocument
				(vlax-get-acad-object)
			)
		)
		(setq lay (vla-get-name lyr))
		;; exclude current layer
		(if (/= lay (getvar "CLAYER"))
			;; IF layer is in lst then turn on, else turn off
			(if (member lay lst)
				(LAYER_OFF lay "_on")
				(LAYER_OFF lay "_off")
			)
		)
	)	
)

 

 

Happy with this?

Edited by Emmanuel Delay
  • Like 2
Posted (edited)

Managed to achieve what I was after using chatgpt-s help:

 

(defun c:isolay (/ ss lay layers-to-keep lay-name i doc layer first-layer)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq ss (ssget))
  (if ss
    (progn
      (setq layers-to-keep '())
      (setq first-layer (vla-get-layer (vlax-ename->vla-object (ssname ss 0))))
      (setq i 0)
      (repeat (sslength ss)
        (setq lay-name (vla-get-layer (vlax-ename->vla-object (ssname ss i))))
        (if (not (member lay-name layers-to-keep))
          (setq layers-to-keep (cons lay-name layers-to-keep))
        )
        (setq i (1+ i))
      )
      (setq first-layer (vla-item (vla-get-layers doc) first-layer))
      (if (and first-layer
               (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-name (list first-layer)))))
        (vla-put-activelayer doc first-layer)
      )
      (vlax-for layer (vla-get-layers doc)
        (setq lay-name (vla-get-name layer))
        (if (and (not (vl-catch-all-error-p (vl-catch-all-apply 'vla-get-name (list layer))))
                 (not (equal lay-name (vla-get-name first-layer)))
                 (not (vl-string-search "|" lay-name)))
          (vla-put-freeze layer :vlax-true)
        )
      )
      (foreach lay layers-to-keep
        (setq layer (vla-item (vla-get-layers doc) lay))
        (if (and layer
                 (not (vl-catch-all-error-p
                       (vl-catch-all-apply 'vla-get-name (list layer)))))
          (if (and (vla-get-freeze layer)
                   (not (equal lay (vla-get-name first-layer))))
            (vla-put-freeze layer :vlax-false)
          )
          (vla-put-lock layer :vlax-false)
        )
      )
    )
  )
  (princ)
)

 

Edited by SLW210
Added Code Tags!!
Posted

Please use Code tags for your code, not Quote Tags. (<> in the editor toolbar)

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