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

Layer Filter Existence Test

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
ВeekeeCZ
1273 Views, 3 Replies

Layer Filter Existence Test

Hi guys,

 

trying to figure out a test whether some layer filter exists or not. Found some examples that helped me to retrieve a list of filters on a TOP level of a filter tree, but I have no idea how to include lower levels too.  

 

image.png

 

 

(defun :LayerPropertiesFilterList (/ dict)
  (if (setq dict (dictsearch
                   (vlax-vla-object->ename
                     (vla-getextensiondictionary
                       (vla-get-layers
                         (vla-get-activedocument
                           (vlax-get-acad-object)))))
                   "ACAD_LAYERFILTERS"))
    (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 3)) dict))))

 

Or:

 

(defun :LayerFilterList (typ / obj dict ent def name lst)

  ;; typ: properties/group/group
  (setq typ (cond ((= typ "properties")	"ACLYLAYERFILTER")
                  ((= typ "group") 	"ACLYLAYERGROUP")
                  ((= typ "both")	"ACLYLAYERFILTER,ACLYLAYERGROUP")
                  ))
  (if (and (setq obj (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))))
	   (= (vla-get-hasextensiondictionary obj) :vlax-true)
	   (setq obj (vla-GetExtensionDictionary obj))
	   (not (vl-catch-all-error-p
		  (setq dict (vl-catch-all-apply 'vla-item (list obj "AcLyDictionary"))))))
    (vlax-for itm dict
      (if (and (setq ent (vlax-vla-object->ename itm))
	       (setq def (entget ent))
	       (= (type (cdr (assoc 1 def))) 'STR)
	       (wcmatch (strcase (cdr (assoc 1 def))) typ)
	       (= (type (setq name (cdr (assoc 300 def)))) 'STR)
               )
        (setq lst (cons name lst)))))
  (reverse lst))

 

thx for any direction... 

 

3 REPLIES 3
Message 2 of 4
doaiena
in reply to: ВeekeeCZ

That is really interesting. I poked around for a few minutes, but i couldn't find information about the lower level filters. The "Level2" entity doesn't seem to contain any information about the lower levels. I didn't have enough time to look around thorougly, but i'm starting to think the lower level info is not contained in the entity, but somewhere in the main dictionary? It would make sense that the information for each level down will be contained in its parent entity. But it doesn't seem to be the case here.

Message 3 of 4
doaiena
in reply to: ВeekeeCZ

I think i've got it. In order to find the sub filters you should search the "ACLYDICTIONARY" dictionary.  This ugly code will get you to the first sub level, if you want to get all levels you should write a recursive function to dig deep into all sub filters. Hope it helps.

(defun test (/ dict topLevel ed ents)
  (if (setq dict (dictsearch
                   (vlax-vla-object->ename
                     (vla-getextensiondictionary
                       (vla-get-layers
                         (vla-get-activedocument
                           (vlax-get-acad-object)))))
                             "ACLYDICTIONARY"))
                           
(progn
(setq topLevel (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) dict)))
                   
(foreach ent topLevel
(setq ed (entget ent))
(if (assoc 360 ed)

(setq ents (append topLevel (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) (entget (cdr (assoc 360 (entget (cdr (assoc 360 ed))))))))))
)
)

))
(mapcar '(lambda (x) (cdr (assoc 300 (entget x)))) ents)
);defun

 

Message 4 of 4
ВeekeeCZ
in reply to: doaiena

Hi @doaiena,

 

thank you for your research! I've done mine too and I was thinking about exploring the acly dict..., but have't that much time and patient.

 

Yes, your code is the right way to do that - although the final collection of entities must be little modified to work correctly on more complicated filter tree than is the sample.

 

Thanks!! 

 

 

Final code recursive to cover all levels: 

 

(defun :LayerFilterList (/ :SubFilterList)

  ; su returns list of main filter and sub filters right behind
  (defun :SubFilterList (dict / ent lst)
    (foreach ent (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 350)) dict))
      (setq lst (append lst
                        (cons ent (if (assoc 360 (entget ent))
                                    (:SubFilterList (entget (cdr (assoc 360 (entget (cdr (assoc 360 (entget ent)))))))))))))
    lst)

  (mapcar '(lambda (x) (cdr (assoc 300 (entget x))))
          (:SubFilterList (dictsearch
                            (vlax-vla-object->ename
                              (vla-getextensiondictionary
                                (vla-get-layers
                                  (vla-get-activedocument
                                    (vlax-get-acad-object)))))
                            "ACLYDICTIONARY"))))

 

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