change an object's layer according to layer name

Discussion in 'AutoCAD' started by doug k, Sep 28, 2004.

  1. doug k

    doug k Guest

    before i try to clunk out a horribly written lisp routine that will take me
    hours to debug, can anyone provide something that will most likely be a lot
    more elegant?

    i want to select objects and have them put on a different layer, based on
    what the original layer was named.

    example:

    some objects are on layer EX-FEATURE, EX-CURB, EX-WALL

    i want to pick them and have them placed on layer TBR-FEATURE, TBR-CURB,
    TBR-WALL, respectively.

    all the layers will currently exist and not all the entities on the EX
    layers will be moved to a TBR layer, only those selected.

    the tricky part is, i don't want to have to specify the target layers, the
    routine needs to look for the similar layer names and figure it out for
    itself knowing only that i want to exchange EX for TBR (i have lots of
    layers named identically except for the prefix).

    if its far easier, i can live with changing just one object at a time.

    all/any help is sincerely appreciated.
     
    doug k, Sep 28, 2004
    #1
  2. doug k

    Matt W Guest

    Real down-and-dirty... You could use the RENAME command.

    (command "-rename" "la" "[old_layer_name]" "[new_layer_name]")


    --
    I support two teams: the Red Sox and whoever beats the Yankees.


    | before i try to clunk out a horribly written lisp routine that will take
    me
    | hours to debug, can anyone provide something that will most likely be a
    lot
    | more elegant?
    |
    | i want to select objects and have them put on a different layer, based on
    | what the original layer was named.
    |
    | example:
    |
    | some objects are on layer EX-FEATURE, EX-CURB, EX-WALL
    |
    | i want to pick them and have them placed on layer TBR-FEATURE, TBR-CURB,
    | TBR-WALL, respectively.
    |
    | all the layers will currently exist and not all the entities on the EX
    | layers will be moved to a TBR layer, only those selected.
    |
    | the tricky part is, i don't want to have to specify the target layers, the
    | routine needs to look for the similar layer names and figure it out for
    | itself knowing only that i want to exchange EX for TBR (i have lots of
    | layers named identically except for the prefix).
    |
    | if its far easier, i can live with changing just one object at a time.
    |
    | all/any help is sincerely appreciated.
    |
    |
     
    Matt W, Sep 28, 2004
    #2
  3. doug k

    Jim Claypool Guest

    Here you go.

    (defun c:chlayer ( / ss cnt layname ent)
    (princ "\nSelect objects to change: ")
    (setq ss (ssget '((8 . "EX-*"))))
    (setq cnt 0)
    (if ss
    (repeat (sslength ss)
    (setq ent (entget (ssname ss cnt)))
    (setq layname (cdr (assoc 8 ent)))
    (setq layname (strcat "TBR" (substr layname 3)))
    (entmod (subst (cons 8 layname) (assoc 8 ent) ent))
    (setq cnt (1+ cnt))
    )
    )
    (princ)
    )
     
    Jim Claypool, Sep 28, 2004
    #3
  4. doug k

    doug k Guest

    wow, thanks Jim. works great!

     
    doug k, Sep 28, 2004
    #4
  5. doug k

    doug k Guest

    only if i wanted to change all the entities.

    i don't. but thanks anyway.

    jim hooked me up.

    i wish i could pound out code like that. i can barely the handle english
    language, and its the only one i know.
     
    doug k, Sep 28, 2004
    #5
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.