john_0104 Posted December 15, 2022 Posted December 15, 2022 Hi , I am new in lisp world and have searched a lot of topics about renaming layer but haven't found a specific one that would cater to my need. The point is I received survey files from different surveyors and I want to rename them into a new one. Ex. Received layers "219_POWER DOME", "268_POWER METER BOX", "power_mh" to be merged into new one "v-SERV-powr-" On some instances, some of the aforementioned received layers were not present on a specific file. I don't want to searched for a specific layer name and changed it to mine because various entities named their layers differently so a single letter, number or character may ruin the program, and it'll be tedious to encode all the layers. I just want to find a common keyword in the 100+ layers and renamed/ categorized it into my standards. It would be also helpful if I can modify the linetype and color too on the LISP, but if I can't it's okay. Thanks a lot, John Quote
mhupp Posted December 15, 2022 Posted December 15, 2022 (edited) Merge all layers to "v-SERV-powr-" and purge layers only. Type LMA or LayMrgAll What exactly do you want to do with the linetypes and color if bylayer match layer prop before merge? ;;----------------------------------------------------------------------------;; ;; Merge All Existing Layers to "v-SERV-powr-" and Purge (defun C:LMA () (C:LayMrgAll)) (defun C:LayMrgAll (/ Drawing x SS) (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "v-SERV-powr-") (70 . 0) (62 . 7))) (vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if (/= (setq x (vla-get-name lay)) "v-SERV-powr-") (progn (setq SS (ssget "X" (list (cons 8 x)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ;future linetype code ;future color code (vla-put-Layer (vlax-ename->vla-object ent) "v-SERV-powr-") ) (vl-cmdf "_Purge" "LA" x "N") ) ) ) (vla-endundomark Drawing) (princ) ) Edited December 15, 2022 by mhupp Quote
john_0104 Posted December 16, 2022 Author Posted December 16, 2022 17 hours ago, mhupp said: Merge all layers to "v-SERV-powr-" and purge layers only. Type LMA or LayMrgAll What exactly do you want to do with the linetypes and color if bylayer match layer prop before merge? ;;----------------------------------------------------------------------------;; ;; Merge All Existing Layers to "v-SERV-powr-" and Purge (defun C:LMA () (C:LayMrgAll)) (defun C:LayMrgAll (/ Drawing x SS) (vla-startundomark (setq Drawing (vla-get-activedocument (vlax-get-acad-object)))) (entmake '((0 . "LAYER") (100 . "AcDbSymbolTableRecord") (100 . "AcDbLayerTableRecord") (2 . "v-SERV-powr-") (70 . 0) (62 . 7))) (vlax-for lay (vla-get-Layers (vla-get-ActiveDocument (vlax-get-acad-object))) (if (/= (setq x (vla-get-name lay)) "v-SERV-powr-") (progn (setq SS (ssget "X" (list (cons 8 x)))) (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))) ;future linetype code ;future color code (vla-put-Layer (vlax-ename->vla-object ent) "v-SERV-powr-") ) (vl-cmdf "_Purge" "LA" x "N") ) ) ) (vla-endundomark Drawing) (princ) ) I am not only merging all layers into one. I am receiving file with 100+ layers that' would need to be categorized each into my designated 30-40 layers. I am looking for an automation to combine some layers into new one using keywords from layer name of the received file. Hope this makes sense. Quote
BIGAL Posted December 17, 2022 Posted December 17, 2022 It is looking like you need a old,new file and each file is relevant to who supplied you the survey, I would start by contacting them and trying to get a full list of their layer names, not just the ones in a dwg, if they are using CIV3D this is buried in the description keys, but the good news is you can export the keys to excel. I have done this where we get the survey from another package so rename layers and change color, existing survey is set to light grey color so sits in background. Quote
ronjonp Posted December 17, 2022 Posted December 17, 2022 (edited) @john_0104 Give this a try .. refer to the comments in the code. (defun c:foo (/ a d l la nl) ;; Create your list of conditions, the first entry is the check and the second is the new layername ;; Refer to WCMATCH filters atthe link below ;; https://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-EC257AF7-72D4-4B38-99B6-9B09952A53AD (setq l '(;; ("219_POWER DOME,268_POWER METER BOX,power_mh" "v-SERV-powr-") ;; This changes all layers that have 'POWER' and 'PWR' to the new layer .. a bit easier to maintain than the check above ("*POWER*,*PWR*" "v-SERV-powr-") ("*LIGHT*" "V-SERV-LIGHT-") ("*TOILET*" "V-SERV-SEWER-") ) ) (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object)))) (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a)))) ) ;; Create the new layers (foreach x l (vla-add (vla-get-layers d) (cadr x))) (vlax-for b (vla-get-blocks d) (if (= -1 (vlax-get b 'islayout)) (vlax-for o b (cond ((vlax-write-enabled-p o) (setq la (strcase (vla-get-layer o))) (if (vl-some '(lambda (x) (and (wcmatch la (strcase (car x))) (setq nl (cadr x)))) l) (vla-put-layer o nl) ) ) ) ) ) ) (foreach l a (vlax-put l 'lock -1)) ;; Purge Layers (repeat 2 (vla-purgeall d)) (princ) ) Edited December 17, 2022 by ronjonp Quote
john_0104 Posted January 9, 2023 Author Posted January 9, 2023 Hi Ron, Sorry it took a while before I responded, I was so excited that I already trust the encoding you did and enlisted all the layers I needed to merge/purge. At the end, the code did not work with all the layers I enlisted. So I tried your given code and created only the layers in your sample. What happened was it all deletes the layers except for "0". I'm gonna upload the screenshot of the sample and the lisp with all the layers I encoded. Please check and advise. Thanks On 12/18/2022 at 4:33 AM, ronjonp said: @john_0104 Give this a try .. refer to the comments in the code. (defun c:foo (/ a d l la nl) ;; Create your list of conditions, the first entry is the check and the second is the new layername ;; Refer to WCMATCH filters atthe link below ;; https://help.autodesk.com/view/ACD/2018/ENU/?guid=GUID-EC257AF7-72D4-4B38-99B6-9B09952A53AD (setq l '(;; ("219_POWER DOME,268_POWER METER BOX,power_mh" "v-SERV-powr-") ;; This changes all layers that have 'POWER' and 'PWR' to the new layer .. a bit easier to maintain than the check above ("*POWER*,*PWR*" "v-SERV-powr-") ("*LIGHT*" "V-SERV-LIGHT-") ("*TOILET*" "V-SERV-SEWER-") ) ) (vlax-for l (vla-get-layers (setq d (vla-get-activedocument (vlax-get-acad-object)))) (cond ((= -1 (vlax-get l 'lock)) (vlax-put l 'lock 0) (setq a (cons l a)))) ) ;; Create the new layers (foreach x l (vla-add (vla-get-layers d) (cadr x))) (vlax-for b (vla-get-blocks d) (if (= -1 (vlax-get b 'islayout)) (vlax-for o b (cond ((vlax-write-enabled-p o) (setq la (strcase (vla-get-layer o))) (if (vl-some '(lambda (x) (and (wcmatch la (strcase (car x))) (setq nl (cadr x)))) l) (vla-put-layer o nl) ) ) ) ) ) ) (foreach l a (vlax-put l 'lock -1)) ;; Purge Layers (repeat 2 (vla-purgeall d)) (princ) ) Survey Layer Rename 7.lsp Quote
ronjonp Posted January 9, 2023 Posted January 9, 2023 (edited) @john_0104 Weird .. post your sample drawing. I could have fat fingered something in the code as I did not test it out. Edited January 9, 2023 by ronjonp Quote
john_0104 Posted January 10, 2023 Author Posted January 10, 2023 Here are the 2 samples of the CAD files I used. You may already use the accumulated list of keywords and layer names on the code. Thanks. 16733.dwg 20009-F01-1.0.dwg Quote
ronjonp Posted January 10, 2023 Posted January 10, 2023 (edited) 13 hours ago, john_0104 said: Here are the 2 samples of the CAD files I used. You may already use the accumulated list of keywords and layer names on the code. Thanks. 16733.dwg 290.98 kB · 0 downloads 20009-F01-1.0.dwg 3.87 MB · 0 downloads The code works here .. but you need to close the first line: (defun c:slr (/ a d l la nl) Edited January 10, 2023 by ronjonp Quote
ILoveMadoka Posted January 11, 2023 Posted January 11, 2023 LAYTRANS works for this type situation too in case there is not consistency in layer names. Quote
john_0104 Posted January 12, 2023 Author Posted January 12, 2023 21 hours ago, ronjonp said: The code works here .. but you need to close the first line: (defun c:slr (/ a d l la nl) Hi Ron, This works really great. I just need to update some of the keywords that are not included in the list I've encoded. Nonetheless, it's a applaudable lisp. Thanks a lot. Quote
ronjonp Posted January 12, 2023 Posted January 12, 2023 2 hours ago, john_0104 said: Hi Ron, This works really great. I just need to update some of the keywords that are not included in the list I've encoded. Nonetheless, it's a applaudable lisp. Thanks a lot. Glad to help 1 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.