Routine to create layer script?

Discussion in 'AutoCAD' started by John Schmidt, Mar 24, 2005.

  1. John Schmidt

    John Schmidt Guest

    I've done an Internet search and found nothing.

    'Not really asking anyone to write anything, but has anyone come across a
    routine that will look at a drawing and then generate a script that will
    create all the layers therein? I know it's easy to insert a block with all
    the layers, but the problem is that if the layers already exist, they take
    precedence, and may contain the wrong color or linetype. A script eliminates
    this problem.

    I currently manually create these scripts, but even with cut and paste from
    text screens, it's a mind-numbing exercise. We need these to correct older
    drawings, and also for generation of new ones.

    Thanks for any leads!

    John
     
    John Schmidt, Mar 24, 2005
    #1
  2. John Schmidt

    Tom Smith Guest

    No, but there are other ways to do the same thing, if I understand you. You want to get all the layer settings from one file and then be able to apply them to other files? You can use the layer state manager to export the layer settings to a file, then import that into other drawings. I suppose You could script the layer state import if you need to.
     
    Tom Smith, Mar 24, 2005
    #2
  3. John Schmidt

    gmcarter Guest

    Check this out...

    (defun makelay (lname laycol laylt)
    (tblnext "layer" T)
    (while (setq p2 (tblnext "layer"))
    (if (= (cdr (assoc 2 p2 )) lname)
    (command "-layer" "T" (strcase lname) "M" (strcase lname) "C" laycol "" "LT" laylt "" ""))
    );while
    (if (= p2 nil)
    (command "-layer" "M" (strcase lname) "C" laycol "" "LT" laylt "" ""))
    );end defun

    Now use a lisp routine to call this function providing the Layer name, color and linetype you want.
     
    gmcarter, Mar 24, 2005
    #3
  4. John Schmidt

    Shane-W Guest

    (SETQ MYLIST (LIST
    (LIST LAYER1_NAME LAYER1_CLR LAYER1_LTYPE)
    (LIST LAYER2_NAME LAYER2_CLR LAYER2_LTYPE)
    (LIST ETC ETC ETC )
    ))
    (FOREACH LIST MYLIST
    (makelay (NTH 0 LIST) (NTH 1 LIST) (NTH 2 LIST))
    )

    JUST REPLACE
    LAYERx_NAME WITH THE LAYER NAME
    LAYERx_CLR WITH THE LAYER COLOR
    LAYERx_LTYPE WITH THE LAYER LTYPE

    ALL SHOULD BE TEXT STRINGS
    EX
    (SETQ MYLIST (LIST
    (LIST "Boundry" "BLUE" "PHANTOM")
    (LIST "EASEMENT" 12 "DASHED")
    (LIST ETC ETC ETC )
    ))
    IF YOU WANT A NUMBER FOR A COLOR I BELIEVE YOU SHOULD LEAVE THAT AS A NUMBER NOT A STRING

    THIS USES THE CODE ABOVE FOR MAKELAY
     
    Shane-W, Mar 24, 2005
    #4
  5. John Schmidt

    gmcarter Guest

    Color number works as a string for sure...
     
    gmcarter, Mar 25, 2005
    #5
  6. John Schmidt

    John Schmidt Guest

    I'll look into all these suggestions.

    Thanks!

    John
     
    John Schmidt, Mar 25, 2005
    #6
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.