Isolate Layer on nested layers?

Isolate Layer on nested layers?

DC-MWA
Collaborator Collaborator
716 Views
2 Replies
Message 1 of 3

Isolate Layer on nested layers?

DC-MWA
Collaborator
Collaborator

Hello,

I have a program that uses 2 functions to isolate layers and unisolate layers after operation is complete.

I'm trying to get this to work with nested layers within xref drawings.

see below...

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;LAYER ISOLATION AND RETURN DEFUNS;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun DO_LIS (/ l n lst)
(setq *Lays_Status1* nil
*Lays_Status2* nil
l '("~*|A-WALL" "A-WALL" "~*|A-DOOR" "A-DOOR" "~*|A-GLAZ" "A-GLAZ" "~*|A-AREA-SPCE" "A-AREA-SPCE" "~*|A-AREA-SPCE-IDEN" "A-AREA-SPCE-IDEN")
)
(vlax-for x (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
(if (member (setq n (vla-get-name x)) l)
(progn
(setq *Lays_Status1*
(cons (list n (vla-get-layeron x))
*Lays_Status1*
)
)
(vla-put-layeron x :vlax-true)
)
(progn
(setq *Lays_Status2*
(cons (list n (vla-get-layeron x))
*Lays_Status2*
)
)
(vla-put-layeron x :vlax-false)
)
)
)
(princ)
);END DO_LIS
;; ;;
(defun DO_LUN (/ l n as)
(setq l '("~*|A-WALL" "A-WALL" "~*|A-DOOR" "A-DOOR" "~*|A-GLAZ" "A-GLAZ" "~*|A-AREA-SPCE" "A-AREA-SPCE" "~*|A-AREA-SPCE-IDEN" "A-AREA-SPCE-IDEN"))
(if (and *Lays_Status1* *Lays_Status2*)
(vlax-for x (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
(cond ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status1*))
(vla-put-layeron x (cadr as))
)
((setq as (assoc (setq n (vla-get-name x)) *Lays_Status2*))
(vla-put-layeron x (cadr as))
)
)
)
)
(setq *Lays_Status1* nil
*Lays_Status2* nil
)
(princ)
);END DO_LUN

 

What am I missing here?

 

 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END LAYER ISOLATION AND RETURN DEFUNS;;;;;;;;;;;;;;;;;;;;;;;;;;;;

0 Likes
Accepted solutions (1)
717 Views
2 Replies
Replies (2)
Message 2 of 3

Moshe-A
Mentor
Mentor
Accepted solution

@DC-MWA  hi,

 

Your layer list contain wild-card characters that are suits for (wcmatch). you can not compare such strings with other comparison function (= , eq or member) so to figure this out i add this anonymous function.

 

(setq _lmatch (lambda (s0 lst) (vl-some '(lambda (s1) (wcmatch s0 s1)) lst)))  

 

and the usage is:

(_lmatch (vla-get-name x) L)

 

this anonymous function iterate through your database list (l) and compare it to the questioned layer and if it finds a match, (vl-some) stops and return the result of (wcmatch) which is T, otherwise it return nil.

 

beside that i can not test your code 😀 i do not have a sample dwg.

 

enjoy

Moshe

 

 

 

(defun DO_LIS (/ _lmatch ; local function
                 l n lst)
 ; Anonymous function
 (setq _lmatch (lambda (s0 lst) (vl-some '(lambda (s1) (wcmatch s0 s1)) lst)))   
  
 (setq l '("~*|A-WALL" "A-WALL" "~*|A-DOOR" "A-DOOR" "~*|A-GLAZ" "A-GLAZ" "~*|A-AREA-SPCE" "A-AREA-SPCE" "~*|A-AREA-SPCE-IDEN" "A-AREA-SPCE-IDEN"))
 (setq *Lays_Status1* nil *Lays_Status2* nil)
  
 (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
  ; (if (member (setq n (vla-get-name x)) l)
  (if (_lmatch (setq n (vla-get-name x)) l) 
   (progn
    (setq *Lays_Status1* (cons (list n (vla-get-layeron x)) *Lays_Status1*))
    (vla-put-layeron x :vlax-true)
   )
   (progn
    (setq *Lays_Status2* (cons (list n (vla-get-layeron x)) *Lays_Status2*))
    (vla-put-layeron x :vlax-false)
   )
  ); if 
 )
  
 (princ)
);END DO_LIS
;; ;;


(defun DO_LUN (/ l n as)
; (setq l '("~*|A-WALL" "A-WALL" "~*|A-DOOR" "A-DOOR" "~*|A-GLAZ" "A-GLAZ" "~*|A-AREA-SPCE" "A-AREA-SPCE" "~*|A-AREA-SPCE-IDEN" "A-AREA-SPCE-IDEN"))
  
 (if (and *Lays_Status1* *Lays_Status2*)
  (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   (cond
    ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status1*))
     (vla-put-layeron x (cadr as))
    )
    ((setq as (assoc (setq n (vla-get-name x)) *Lays_Status2*))
     (vla-put-layeron x (cadr as))
    )
   ); cond
  ); vlax-for
 ); if
  
 (setq *Lays_Status1* nil *Lays_Status2* nil)
  
 (princ)
);END DO_LUN

 

 

Message 3 of 3

DC-MWA
Collaborator
Collaborator

Thank you, this seems to work, I need to test more.

Thanks again.

0 Likes