Herr_Manu Posted October 7, 2021 Posted October 7, 2021 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 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? Quote
rkmcswain Posted October 7, 2021 Posted October 7, 2021 I just took an existing drawing, created a layer named "WIRKFLÄCHE", ran your code and layerlist does equal Quote
Tharwat Posted October 8, 2021 Posted October 8, 2021 Hi, You need to match the case of the string to get it working with wcmatch function. (wcmatch (strcase layername) "*WIRKFLÄCHE") Quote
Herr_Manu Posted October 8, 2021 Author Posted October 8, 2021 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??? Quote
Tharwat Posted October 10, 2021 Posted October 10, 2021 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) Quote
Herr_Manu Posted October 11, 2021 Author Posted October 11, 2021 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 Thanks again for the help Quote
Tharwat Posted October 13, 2021 Posted October 13, 2021 Append function requires an empty list or a list of elements to append item(s) to it but the cons function does not and it is straight forward. Quote
Recommended Posts
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.