Standards coversion for layers - layer mapping

Discussion in 'AutoCAD' started by litespeed_nz, Apr 15, 2004.

  1. litespeed_nz

    litespeed_nz Guest

    Hello,

    I have searched thou the forums and seen that some people have had tried in the past to use some kind of standards conversion to move their current layers to a new layername for the new standards.

    I fould 1 topice where you used a txt file with the "oldlayername" and "newlayername"
    and some lisp to run thru it, but because our project is in such a mess i am looking for some help to add some features in.

    Below is what I currently have:

    Text file called 'layermap.txt"
    "oldlayername" "newlayername"
    ("Dim" "PM_ANOTREFC_D_N")
    ("ELECSIG" "PE_ELECSIGL_E_N")
    ("EQUIPMENT" "PM_PRCSEQPT_E_N")
    ("INLINE" "PM_PRCSINLI_E_N")

    A lisp with the following code:
    ;=========layermap.lsp==========
    (defun C:LayMap (/ fn f l ol nl ss)
    (if (setq fn (findfile "layermap.txt"))
    (progn
    (setq f (open fn "r"))
    (while (setq l (read (read-line f)))
    (setq ol (car l)
    nl (cadr l)
    )
    (if (not (tblobjname "LAYER" nl))
    ;;cannot rename layer "0"
    (if (not (= "0" ol))
    (command "._rename" "layer" ol nl)
    )
    ;;move all objects to the new layer
    (if (setq ss (ssget "X" (list (cons 8 ol))))
    (command "._chprop" ss "" "la" nl "")
    )
    )
    )
    (close f)
    )
    (princ)
    )
    )
    ===============================

    ok this works fine but I get some problems if certain varibles are not consistant.
    1. if the new layer name exists the lisp crashes out. need some error checking
    2. i need this lisp to see if the layer exists, then if so, just move everything from old layername to new layer name.
    3. if the new layer name does not exist then when it's created, can it be a certain colour & line style also?

    Any help woud be great.
    I prefer using the text file because it removes the need for the layer names to be hard coded in the lisp.

    Oh, before you tell me to use the standards manager, I am only using acad 2000i - the suite have short arms and deep pockets :)

    I have about 120 drawings i need to clean up.

    Thanks
     
    litespeed_nz, Apr 15, 2004
    #1
  2. you are not tsting for hardwired blocks where the layer def is contained
    within the block.

    I would recommend the following method instead

    Create all new layers as you read them in - (command ".layer" "m" nl "")

    then read in the old names and create an association list (list (cons ol
    nl))

    then (cdr (assoc ol layerlist)) gives you the new layer.

    Then step through the block definition table

    (setq data (tblnext "blocks" ... wait , what am I doing!? I wrote this
    already -


    (defun c:fixents (/ ss1 temp ent1 looper entdat bnm ctr enttyp bl_list)
    ;;;(arctvsav) save sysvars etc
    (command ".layer" "t" "0" "un" "0" "s" "0" "")
    ;;; put your code here to create your lists and set up all layers and
    linetypes needed )I recommend loading acad.lin first
    (setq layerlist (list (cons "0" "0")))
    ;;;now read in your new layers and create 'em and put 'em in a list
    ;;;then read in your old layers
    ;;;now make your assoc list
    (setq ss1 (ssadd) looper T ctr 0)
    (while looper
    (prompt "\nSelect Entities to set to be adjusted to New Layers: ");;; k',
    type all here
    (setq ss1 (ssget))
    (if ss1 (setq looper nil))
    )
    (repeat (sslength ss1)
    (setq ent1 (ssname ss1 ctr) entdat (entget ent1) enttyp (cdr (assoc 0
    entdat)))
    (if (= enttyp "INSERT")
    (progn
    (setq bl_list (list (cdr (assoc 2 entdat))))
    (foreach bnm bl_list
    (jddfixablock bnm layerlist)
    )
    )
    (progn
    (setq entdat (subst (cons 8 (cdr (assoc ol layerlist))(assoc 8
    entdat) entdat);;; here's the layerlist and ol doing the assoc thing
    ;;;entdat (subst (cons 62 256)(assoc 62 entdat) entdat)
    ;;;set colour and linetype bylayer if you want
    ;;; entdat (subst (cons 6 "Bylayer")(assoc 6 entdat) entdat)
    )
    (entmod entdat)(entupd ent1)
    )
    )
    (setq ctr (+ ctr 1))
    )


    ;;;(arctvrst) restore vars
    (princ)
    )
    (defun jddfixablock (bname layerlist / enam1 end1 nl1)
    (setq enam1 (tblobjname "block" bname))
    (while (setq enam1 (entnext enam1) end1 (entget enam1))
    ;;;(princ "\nEntity was: ")(princ (entget enam1))
    (setq end1 ;;;(subst (cons 62 256)(assoc 62 end1) end1) set it
    bylayer
    ;;; (subst (cons 6 "Bylayer")(assoc 6 end1) end1)
    nl1 (cdr (assoc (cdr (assoc 8 end1)) layerlist))
    end1 (subst (cons 8 nl1)(assoc 8 end1) end1);;;layerlist
    agasin
    )
    (entmod end1)
    (if (= (cdr (assoc 0 (entget enam1))) "INSERT")(setq bl_list (append
    bl_list (list (cdr (assoc 2 (entget ent1)))))))
    )
    )



    check the parentheses pleas and spelling too.




    Jamie Duncan

    Consulting - If you're not part of the solution, there's good money in
    prolonging the problem.
    in the past to use some kind of standards conversion to move their current
    layers to a new layername for the new standards.
    am looking for some help to add some features in.
    everything from old layername to new layer name.
    a certain colour & line style also?
    names to be hard coded in the lisp.
    2000i - the suite have short arms and deep pockets :)
     
    Jamie Duncan \(remove lock to reply\), Apr 16, 2004
    #2
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.