Rename layer at suffix

Discussion in 'AutoCAD' started by Brockster, Jul 20, 2004.

  1. Brockster

    Brockster Guest

    I did a little searching around, but I didn't find a solution.

    I need a little program code to change any layers in a dwg file that "end" with a specific text string. Ex. A-ANNO-NOTE-65%, A-ANNO-DIMS-65%, A-ANNO-SYMS-65%. In this case, I need to change the 65%'s to 95%. Once I have the code, I'll run it using a batch program.

    Thanks in advance,
    Brock
     
    Brockster, Jul 20, 2004
    #1
  2. (setq OLS "%65")
    (setq NLS "%95")
    (setq TS (tblnext "LAYER" T))
    (while TS
    (setq OLN (cdr (assoc 2 TS)))
    (if (wcmatch OLN (strcat "*" OLS))
    (progn
    (setq NLN (strcat (substr OLN 1 (- (strlen OLN) (strlen OLS))) NLS))
    (command "RENAME" "LAYER" OLN NLN)
    (princ (strcat "\nChanged Layer " OLN " to " NLN))
    )
    (princ (strcat "\nLayer NOT Changed " OLN))
    )
    (setq TS (tblnext "LAYER"))
    )
    (princ)

    Please note - wcmatch command has special characters that may change at any
    time in future releases of AutoCAD.
    I tested this with Acad 2002 and the % is currently NOT a wildcard.
     
    Alan Henderson @ A'cad Solutions, Jul 20, 2004
    #2
  3. Brockster

    Brockster Guest

    Sorry, but this didn't work. Here's the response I recevied:

    Layer NOT Changed P-ANNO-NOTE-65%
    Layer NOT Changed P-ANNO-DIMS-65%
    Layer NOT Changed P-ANNO-SYMS-65%

    Any ideas what went wrong?
    Brock
     
    Brockster, Jul 20, 2004
    #3
  4. Brockster

    Brockster Guest

    I just read that by using ObjectDBX, simple modifications such as mine can be performed without even opening the files. This is perfect for my needs because I'm not changing geometry. Can anyone hook me up with a code for this?
     
    Brockster, Jul 20, 2004
    #4
  5. Sorry, I was being dyslexic.
    Change -
    (setq OLS "%65")
    (setq NLS "%95")
    to -
    (setq OLS "65%")
    (setq NLS "95%")
     
    Alan Henderson @ A'cad Solutions, Jul 20, 2004
    #5
  6. Brockster

    Brockster Guest

    That did it! I thought that might be the case, but you said it work in your test.

    Will this work with any layer characters I want to change within the name or just the ending letters? Can I exchange the OLS and NLS at will?

    Also, you mind if I email you?
     
    Brockster, Jul 21, 2004
    #6
  7. or just the ending letters?
    Just ending letters.
    Okay.
     
    Alan Henderson @ A'cad Solutions, Jul 21, 2004
    #7
  8. Brockster

    Brockster Guest

    Please do.

     
    Brockster, Jul 21, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.