RubberDinero Posted August 29, 2016 Posted August 29, 2016 At my job, i have a very tedious job of changing layers from proposed to existing and vice versa our layer setup is very basic "LayerName"=existing layer "LayerName-PR"=Proposed layer. i have recently bought a book to to learn AutoLisp and I've gotten the basic concept. I know that i want to ssget LayerName and setq that name to L then CHPROP LA to L-PR. but i want to know if someone has anything like this already and could help me. I'd like to do a mass select and have it automatically change the entities to their respective PR layer. also vice versa, to remove PR. i'm not looking for a layer renaming lisp. i'm looking for a entity layer changing lisp. anything helps. thanks. Quote
Lee Mac Posted August 29, 2016 Posted August 29, 2016 Are you looking to change everything on "LayerName" to "LayerName-PR", including nested objects? Or only objects selected by a user? Quote
RubberDinero Posted August 29, 2016 Author Posted August 29, 2016 Are you looking to change everything on "LayerName" to "LayerName-PR", including nested objects? Or only objects selected by a user? Selected items via box selection or pickbox. i would like to layiso a bunch of layers select the entities and run the lisp. or run the lisp and select the entities. It would have to be different then renaming a layer, because there are going to be some items on the same layer i don't want to change to -pr or remove the pr, they have to remain. thanks. Quote
Lee Mac Posted August 29, 2016 Posted August 29, 2016 The following is quickly written using some existing code: (defun c:lay2pr ( / enx idx lay sel ) (if (setq sel (ssget "_:L" '((8 . "~*-PR")))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (strcat (cdr lay) "-PR"))) lay enx)) ) ) (princ) ) (defun c:pr2lay ( / enx idx lay sel ) (if (setq sel (ssget "_:L" '((8 . "*?-PR")))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 3)))) lay enx)) ) ) (princ) ) (defun matchlayer ( src new ) (or (tblsearch "layer" new) (entmake (subst (cons 2 new) (cons 2 src) (vl-remove-if '(lambda ( x ) (member (car x) '(-1 5 102 360))) (entget (tblobjname "layer" src))) ) ) ) new ) (princ) The commands are LAY2PR and PR2LAY. Quote
RubberDinero Posted August 30, 2016 Author Posted August 30, 2016 The following is quickly written using some existing code:(defun c:lay2pr ( / enx idx lay sel ) (if (setq sel (ssget "_:L" '((8 . "~*-PR")))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (strcat (cdr lay) "-PR"))) lay enx)) ) ) (princ) ) (defun c:pr2lay ( / enx idx lay sel ) (if (setq sel (ssget "_:L" '((8 . "*?-PR")))) (repeat (setq idx (sslength sel)) (setq enx (entget (ssname sel (setq idx (1- idx)))) lay (assoc 8 enx) ) (entmod (subst (cons 8 (matchlayer (cdr lay) (substr (cdr lay) 1 (- (strlen (cdr lay)) 3)))) lay enx)) ) ) (princ) ) (defun matchlayer ( src new ) (or (tblsearch "layer" new) (entmake (subst (cons 2 new) (cons 2 src) (vl-remove-if '(lambda ( x ) (member (car x) '(-1 5 102 360))) (entget (tblobjname "layer" src))) ) ) ) new ) (princ) The commands are LAY2PR and PR2LAY. Wow! that was amazing and fast! i'm going to study this code. I'm not a programmer so I'm reading "AutoLisp in Plain English" very interesting stuff! the book even came with a floppy disk. thank you very much! do i have to do like a solution found option and pick your response? Quote
Grrr Posted August 30, 2016 Posted August 30, 2016 Wow! that was amazing and fast! i'm going to study this code.I'm not a programmer so I'm reading "AutoLisp in Plain English" very interesting stuff! the book even came with a floppy disk. thank you very much! do i have to do like a solution found option and pick your response? I would suggest you to start with afralisp.com, and after reaching certain level to visit Lee Mac's tutorials: http://www.lee-mac.com/tutorials.html And after reading your comments I don't think you'll "study" too much from his code at this point (no offense), since usually LM's codes are written in advanced/high level - avoiding any possible faults in them. Quote
RubberDinero Posted August 30, 2016 Author Posted August 30, 2016 Thanks. what would you suggest from afralisp? it's pretty much a book list from amazon. that's where i bought my book. since it seemed to be for noobs, i felt it was perfect for me. I've already written some very basic lsp (defun c:wa nil (setq s (ssget "_X" '((8 . "*water*,*watr*,*wtr*,*wa-*")))) (command "_.chprop" s "" "LA" "VU-WATR-PIPE""") (princ) ) I know its just an "ssx macro" turned lsp, but i was kind of proud of myself. Quote
RubberDinero Posted August 30, 2016 Author Posted August 30, 2016 afralisp.com I think this website if no longer in service. Quote
Lee Mac Posted August 30, 2016 Posted August 30, 2016 Wow! that was amazing and fast! i'm going to study this code.I'm not a programmer so I'm reading "AutoLisp in Plain English" very interesting stuff! the book even came with a floppy disk. thank you very much! You're very welcome - feel free to ask if you have questions regarding the posted code. do i have to do like a solution found option and pick your response? Not at all - a 'thank you' is more than sufficient. Quote
Lee Mac Posted August 30, 2016 Posted August 30, 2016 I think this website if no longer in service. I believe 'Grrr' meant AfraLISP.net Here are some resources to get you started: AfraLISP Jeffery Sanders AutoLISP Tutorial Ron Leigh AutoLISP Lessons Lee Mac Programming Tutorials Quote
Lee Mac Posted August 30, 2016 Posted August 30, 2016 When posting code to the forum, I would also suggest you read these guidlines to correctly format the code. When writing your code, I would also strongly suggest using a code editor if you are not already doing so - Personally, I find that the Visual LISP IDE provided with AutoCAD is by far the most suitable for writing AutoLISP: The Visual LISP Editor - Part 1 The Visual LISP Editor - Part 2 An Introduction to the Visual LISP IDE Retrieving Information About a Function A Shortcut to Localising Variables Debugging Code with the Visual LISP IDE Quote
crgonzo Posted February 3, 2023 Posted February 3, 2023 I am having a similar need except my layer names are a bit different. I-EQPT-21, for instance, will change to XI-EQPT-81 representing a change from new to existing. In other cases, the opposite is true. The numbers represent the layer color and the X represents "existing". I was able to modify the code above to make the change from I-EQPT-21 to XI-EQPT-81 by selection method noted but can't figure out how to go in reverse. I can tell that the ENTMOD code removes the last 3 characters of the layer name when switching back. Obviously, I don't need that to happen. Is it possible to easily do what I need without completely rewriting the code? Thanks a bunch for any tips. 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.