Jump to content

Filtering a specific Layer with vlax-map-collection and wcmatch


Recommended Posts

Herr_Manu

Hi everyone

i'm Emmanuel and i've been writting (with a lot of help of this forum and all you guys) autolisp and vlisp for over a year and this is the first time i'm officially posting a question in here, so i'm quite excited :D

 

I'm currently working on in a little routine to filter layers with a specific name, in this case "WIRKFLÄCHE" (german for design area).

and i was using a ssget '((8. "*wirkf*")) but giving that i'm going to use another ssget to modified some objects later, i decided to use vlax-map-collection, and it works fine, but when i'm trying to use (if (wcmatch layername "*WIRKFLÄCHE")) it doesn't filter a thing

 

 

(defun c:layertest (/ acadDoc modelSpace theLayers dwgName layerList)
  
  (vl-load-com)

  (setq
    acadDoc    (vla-get-ActiveDocument (vlax-get-acad-object))
    modelSpace (vla-get-ModelSpace acadDoc)
  )

  (setq theLayers (vla-get-layers acadDoc))
(setq layerList '())

	(vlax-map-collection theLayers
 
  '(lambda (theLayer)
 
    (setq dwgName (vlax-get-property theLayer 'Name))

    (if
      (wcmatch dwgName "*WIRKFLÄCHE")
 	(progn
	    (setq layerList (append (list dwgName) layerList))
	    (setq layerList (reverse layerList))
    	);progn

      );end IF
 
    
 
;;;    (vlax-put-property theLayer "LayerOn" ':vlax-true)
;;; 
;;;    (vla-put-color thelayer 5)
 
  );lambda
 
);vlax-map-collection

);defun

am i missing something in here?

 

 

Link to post
Share on other sites
rkmcswain

I just took an existing drawing, created a layer named "WIRKFLÄCHE", ran your code and layerlist does equal 

 

image.png.359b9936e0417611fec3d7ed758a449b.png

Link to post
Share on other sites
Tharwat

Hi,

You need to match the case of the string to get it working with wcmatch function.

(wcmatch (strcase layername) "*WIRKFLÄCHE")

 

Link to post
Share on other sites
Herr_Manu

Thanks for the comments, but i think now i'm having some other problems.

 

When i run this function as a whole, i doesn't work, but if i do it by little pieces, it does. some times i get an error like bad argument type: stringp nil    

and some other times i get the error: no function definition: VL-LOAD-COM ... is my computer messing up with me?? 

 

Any idea what can be cause of this errors??? 

Link to post
Share on other sites
Tharwat

You may have something wrong with your AutoCAD that might missing one or more .dll file(s) but anyway try it with this little mods.

(defun c:layertest (/ acadDoc modelSpace theLayers dwgName layerList)
  (setq
    acadDoc    (vla-get-ActiveDocument (vlax-get-acad-object))
    modelSpace (vla-get-ModelSpace acadDoc)
    theLayers  (vla-get-layers acadDoc)
  )
  (vlax-map-collection
    theLayers
    '(lambda (theLayer)
       (setq dwgName (vlax-get-property theLayer 'Name))
       (if
         (wcmatch dwgName "*WIRKFLÄCHE")
          (setq layerList (cons dwgName layerList))
       )
     )
  )
  layerList
)
(vl-load-com)

 

Link to post
Share on other sites
Herr_Manu
On 10/10/2021 at 5:19 PM, Tharwat said:

You may have something wrong with your AutoCAD that might missing one or more .dll file(s) but anyway try it with this little mods.


(defun c:layertest (/ acadDoc modelSpace theLayers dwgName layerList)
  (setq
    acadDoc    (vla-get-ActiveDocument (vlax-get-acad-object))
    modelSpace (vla-get-ModelSpace acadDoc)
    theLayers  (vla-get-layers acadDoc)
  )
  (vlax-map-collection
    theLayers
    '(lambda (theLayer)
       (setq dwgName (vlax-get-property theLayer 'Name))
       (if
         (wcmatch dwgName "*WIRKFLÄCHE")
          (setq layerList (cons dwgName layerList))
       )
     )
  )
  layerList
)
(vl-load-com)

 

 

Works great! i already managed to make it work. but your version is easier to read. i'm still figuring out, what does exactly mean to use (cons item list) instead of (append). I'm gladly surprised that my approach wasn't that wrong :D

 

Thanks again for the help

 

 

Link to post
Share on other sites

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