See the top rated post in this thread. Click here

Results 1 to 6 of 6

Thread: Copy but adjust layer name

  1. #1
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Copy but adjust layer name

    I would like to create a lisp that enables the user to copy and paste an object,

    During this process I would like it to take the layer name of the object its copying e.g VEIWPORT_001 and create a new layer with an incremental integer on the end. (VEIWPORT_001,VEIWPORT_002,VEIWPORT_003 etc).

    Any help would be appreciated.

  2. #2
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    1

    Default Re: Copy but adjust layer name

    I've used AutoCAD for 30 years and every viewport I've ever added has been on layer Viewports.
    Each of them are separate objects with their own object & entity names.

    Can you describe a little more about what you're trying to accomplish?
    Why would you want to create all those layers?
    Even if you freeze a viewport's layer it wouldn't affect the display of the viewport, only the border would disappear.

  3. #3
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Re: Copy but adjust layer name

    VEIWPORT_001 may have been a bad example

    I want to be able to do a "copy" in a drawing, however I would like it to take the layer name of the object that is being copied and add a value to the end of the layer name going up in increments of 1

    OBJECT_LAYER_NAME_001,OBJECT_LAYER_NAME_002,OBJECT_LAYER_NAME_003 etc.

    If possible the lisp would scan the drawing for the highest value OBJECT_LAYER_NAME and add 1 to it.

    Thanks in advance.

  4. #4
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Copy but adjust layer name

    I would recommend you break this down into specific tasks within your routine. Have you written out your steps you want to take in your spoken language yet? That would help organize your routine.

    You will need a few tasks within your routine
    • Selecting of an object
    • Reading the layer name of the selected object
    • Copy selected object
    • Store newly copied object in a variable for later use
    • Scan all layer names for last available numbers (or strings because 003 is not a number)
    • Create new layer with desired name
    • Set layer name of copied object to new layer name


    Rinse and repeat gets your routine you are attempting to write. All of these tasks could be brought piecemeal into a your routine. You probably can search these forums for most of the tasks.

    BTW, please do not send me your drawing with all of these layer names. It would be a chore to find what to turn on and off with all of these layer names. Theoretically there is no limit to layer names in a drawing, but there are counts that trigger undesirable performances within drawings.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  5. #5
    Member
    Join Date
    2021-08
    Posts
    23
    Login to Give a bone
    0

    Default Re: Copy but adjust layer name

    This is what i have so far

    . Selecting of an object

    defun C:Cx1 ( / E Oldlayer Newlayer)

    (if (ssget "_X" '((0 . "INSERT") (2 . "VEIWPORT_OUTLINE_001")))
    (command
    "_.chprop"
    (ssname (ssget "_X" '((0 . "INSERT") (2 . "VEIWPORT_OUTLINE_001"))) 0)


    . Reading the layer name of the selected object
    . Copy selected object

    (if (not (setq E (car (entsel)))) ; select one object
    (doThis) ; action if there's nothing selected
    (progn ; action if selection exists
    (setq oldLayer (getvar "CLAYER")) ; saves current layer
    (setq newLayer (cdr (assoc 8 (entget E)))) ; get selection's layer
    (setvar "CLAYER" newLayer) ; make that layer current

    (command "copy")


    . Store newly copied object in a variable for later use



    . Scan all layer names for last available numbers (or strings because 003 is not a number)



    . Create new layer with desired name

    "_layer" "make" setq
    (loop for x from expr1)
    for y = nil then x
    collect (list x y))


    . Set layer name of copied object to new layer name
    Last edited by Wdobbin ; 2022-03-24 at 02:51 AM.

  6. #6
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,106
    Login to Give a bone
    0

    Default Re: Copy but adjust layer name

    Quote Originally Posted by Wdobbin View Post
    I am not very experienced with writing .lsp routines but I will give it a go.
    Neither was I when I first started. I just started before you. You might check out the Learning Lisp thread. It is a little old, but still has several links that still work.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

Similar Threads

  1. ADD LAYER WILL COPY A CURRENT LAYER NAME
    By Wish List System in forum AutoCAD Wish List
    Replies: 5
    Last Post: 2020-10-27, 05:01 PM
  2. 2016: How to lock origin but have UCS adjust
    By lynx_20 in forum AutoCAD General
    Replies: 5
    Last Post: 2018-12-19, 09:25 PM
  3. 2015: Can't Cope two beams error "coping applied but no cut was made. adjust coping ..."
    By vitolopes8699207 in forum Revit Structure - General
    Replies: 1
    Last Post: 2015-04-30, 02:13 PM
  4. 2012: Copy Layer but Freeze in Viewports
    By vweavers in forum AutoCAD General
    Replies: 8
    Last Post: 2013-07-03, 10:21 AM
  5. Replies: 12
    Last Post: 2010-01-08, 07:49 PM

Tags for this Thread

Posting Permissions

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