Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Layer Properties by Group Filter

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
christopher.l.evans
942 Views, 4 Replies

Layer Properties by Group Filter

I have some layer groups defined in my layer properties manager (PAPER SPACE OFF, PAPER SPACE ON, VIEWPORT OFF, VIEW PORT ON).  I want to turn layers on/off and vpfreeze layers on/off in the vp by the layer group already defined, I'd like the option to run this on the current layout or all layouts. 

 

I spent a day trying to find an example but everything I found ignored the defined layer groups and applied the setting changes to all layers in the drawing.  I found examples on how to create layer groups via lisp but nothing on how to access that list later on.  Is this just something not accessible via lisp?

4 REPLIES 4
Message 2 of 5

Also if there were, in AutoCAD is no command or function which can handle with layergroups.

 

Build a function to read which Layers are part of the group (and sub groups?),

so you have a list of layers you can work on.

Sebastian

Message 3 of 5
pendean
in reply to: cadffm

Message 4 of 5

If you are really talking about LAYER GROUP FILTER rather than LAYER PROPERTY FILTER 

 

(vl-load-com)

;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/retrieve-layer-names-from-group-layer-filter/m-p/8805768
(defun :grouplayerfilterswlayernames nil
  ((lambda (foo) (foo (entget (cdr (assoc 330 (entget (tblobjname "layer" "0")))))))
    (lambda (enx / dic i itm rtn)
      (and (setq dic (cdr (assoc 360 (member '(102 . "{ACAD_XDICTIONARY") enx))))
	   (setq dic (cdr (assoc -1 (dictsearch dic "aclydictionary"))))
	   (while (setq itm (dictnext dic (not itm)))
	     (if (= "AcLyLayerGroup" (cdr (assoc 1 itm)))
	       (setq i	 (assoc 300 itm)
		     rtn (cons (list (cdr i) (mapcar '(lambda (y) (cdr (assoc 2 (entget (cdr y)))))
						     (vl-remove-if '(lambda (x) (/= 330 (car x))) (member i itm))))
			       rtn)))))
      (reverse rtn))))


(defun :layergroupon (name / lst)
  (if (setq lst (cadr (assoc name (:grouplayerfilterswlayernames))))
    (progn
      (command "_.layer")
      (foreach l lst (command "_on" l))
      (command ""))))

(defun :layergroupoff (name / lst)
  (if (setq lst (cadr (assoc name (:grouplayerfilterswlayernames))))
    (progn
      (command "_.layer")
      (if (vl-position (getvar 'clayer) lst)  ; if current layer is about to off
	(command "_t" "0" "_s" "0" "_u" ""))  ; than make 0 current.
      (foreach l lst (command "_off" l))
      (command ""))))

(defun c:PaperSpaceOn nil  (:layergroupon  "PAPER SPACE") (princ))
(defun c:PaperSpaceOff nil (:layergroupoff "PAPER SPACE") (princ))

 

Message 5 of 5

@ВeekeeCZ In some cases the list has nil in it one or more times and created chaos when passing the list to a command.  So I added (vl-remove nil lst) 

 

Examples 

 

("group 1" ("a" "b" "c" nil nil nil "d"))

 

("group 2" ("a" "b" "c" nil "d" "e" "f"))

 

(defun :vplayergroupoff (name / lst)
  (if (setq lst (cadr (assoc name (:grouplayerfilterswlayernames))))
    (progn
      (command "_.vplayer")
      (foreach l (vl-remove nil lst) (command "_f" l "_c"))
      (command ""))))

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report