+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
  1. #1
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Idea Change entity layer

    Registered forum members do not see this ad.

    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.

  2. #2
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Are you looking to change everything on "LayerName" to "LayerName-PR", including nested objects? Or only objects selected by a user?
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  3. #3
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Lee Mac View Post
    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.

  4. #4
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    The following is quickly written using some existing code:
    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.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  5. #5
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Lee Mac View Post
    The following is quickly written using some existing code:
    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?

  6. #6
    Super Member
    Discipline
    Multi-disciplinary
    Using
    AutoCAD 2015
    Join Date
    Nov 2013
    Posts
    1,080

    Default

    Quote Originally Posted by RubberDinero View Post
    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.

  7. #7
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    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.

  8. #8
    Full Member
    Using
    AutoCAD 2016
    Join Date
    Aug 2016
    Posts
    31

    Default

    Quote Originally Posted by Grrr View Post
    afralisp.com
    I think this website if no longer in service.

  9. #9
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Quote Originally Posted by RubberDinero View Post
    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.

    Quote Originally Posted by RubberDinero View Post
    do i have to do like a solution found option and pick your response?
    Not at all - a 'thank you' is more than sufficient.
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

  10. #10
    Quantum Mechanic Lee Mac's Avatar
    Computer Details
    Lee Mac's Computer Details
    Operating System:
    Windows 7 Ultimate (32-bit)
    Discipline
    Multi-disciplinary
    Lee Mac's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Custom Programming / Software Customisation
    Using
    AutoCAD 2013
    Join Date
    Aug 2008
    Location
    London, England
    Posts
    19,322

    Default

    Registered forum members do not see this ad.

    Quote Originally Posted by RubberDinero View Post
    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
    Lee Mac ProgrammingTwitterExchange App StoreDropbox (500MB free)

    With Mathematics there is the possibility of perfect rigour, so why settle for less?

Similar Threads

  1. LISP to change entity colour by layer name using wildcard?
    By ctrlaltdel in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 9th Aug 2016, 07:58 am
  2. Lisp to change an entity layer in a nested block without entering block
    By Tripledot in forum AutoLISP, Visual LISP & DCL
    Replies: 16
    Last Post: 27th Jul 2016, 12:39 pm
  3. change entity to layer
    By rookie37 in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 4th Jun 2009, 08:36 pm
  4. Entity Layer name change in BlkDef Table
    By ML0940 in forum AutoLISP, Visual LISP & DCL
    Replies: 13
    Last Post: 28th Jul 2008, 08:40 pm
  5. change entity to a certain layer
    By rookie37 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 30th Mar 2007, 02:30 am

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts