Import Layers

Discussion in 'AutoCAD' started by jlspartz, Nov 4, 2004.

  1. jlspartz

    jlspartz Guest

    Let me start out by saying we use almost 200 standard layers here. I'd like to be able to import the layers from a template (create the layers that don't exist, and leave alone the layers that already exist within the drawing). Does anyone have a lisp routine to do this? It would be easier if I could import them from a template instead of writing a routine to make 200 layers, set all their colors, linetypes, etc. Any help would be appreciated.
     
    jlspartz, Nov 4, 2004
    #1
  2. The simplest approach I can think of would be
    to create a drawing file with all of the layers
    defined and just insert it.

    It wouldn't be terribly difficult to do it with LISP,
    if that is really what you need.

    --
    Autodesk Discussion Group Facilitator



    like to be able to import the layers from a template (create the layers that
    don't exist, and leave alone the layers that already exist within the
    drawing). Does anyone have a lisp routine to do this? It would be easier
    if I could import them from a template instead of writing a routine to make
    200 layers, set all their colors, linetypes, etc. Any help would be
    appreciated.
     
    Jason Piercey, Nov 4, 2004
    #2
  3. jlspartz

    spencer1971 Guest

    We have a drawing in a read only folder with all standard layers, text styles, dimstyles etc..
    If these get accidentially purged from a working drawing, this file can simply be dragged into autocad and all the stuff is instantly replaced.
    Works OK for us.

    Spence
     
    spencer1971, Nov 4, 2004
    #3
  4. jlspartz

    Tom Smith Guest

    I agree with the above. If your goal is to NOT change any existing layers,
    then inserting an empty drawing containing all layers is the simplest and
    most straightforward way. The present drawing's layers won't be changed by
    inserting the block.

    However, if your goal is to "fix" exiting layers which have somehow gotten a
    non-standard color or whatever, then importing a saved layer state is
    another easy way to go.
     
    Tom Smith, Nov 4, 2004
    #4
  5. jlspartz

    John Schmidt Guest

    Here's a line from our custom menu that imports a layer standard called FM
    Standards, (layers predefined in the drawing/block) - after importing the
    block, it erases and purges it. This will also leave existing layers alone -
    if you want to change incorrect existing layers you'd either need to import
    layer states or write a script. We found importing layer states somewhat
    problematic when it came to automating.

    [Insert FM Standards]^C^C-insert;fm_standards.dwg;0,0;;;;(ssget "x" '((2 .
    "fm_standards")) );erase;p;;-purge;B;fm_standards;n;

    John

    like to be able to import the layers from a template (create the layers that
    don't exist, and leave alone the layers that already exist within the
    drawing). Does anyone have a lisp routine to do this? It would be easier
    if I could import them from a template instead of writing a routine to make
    200 layers, set all their colors, linetypes, etc. Any help would be
    appreciated.
     
    John Schmidt, Nov 4, 2004
    #5
  6. jlspartz

    Tom Smith Guest

    We found importing layer states somewhat problematic

    It's not that bad. The import can fail for several reasons -- you need to
    make sure the linetypes referenced in the layers exist, and you can't import
    a layer state if one of that name already exists. The routines below work
    for us. We have a toolbar button which runs (importlayers). Note that the
    layer state is named "tbinc" and is stored in the tbinc.las file. It uses
    four linetypes.

    The purpose is to restore all our standard layers to their normal settings,
    in cases where layers have been purged or changed, or when working with old
    drawings.

    (defun importltypes ()
    (setvar "filedia" 0)
    (foreach n '("center" "dashed" "hidden" "phantom")
    (if (null (tblsearch "ltype" n))
    (command "-linetype" "load" n "acad.lin" "")))
    (setvar "filedia" 1)
    (princ))

    (defun wipelstate ()
    (command "-layer" "state" "delete" "tbinc" "" "")
    (if (zerop (getvar "cmdactive"))
    (princ)
    (command "")) ;extra return if lstate not found
    (princ))

    (defun importlayers ()
    (importltypes)
    (wipelstate) ;make sure the state isn't there
    (command "-layer" "state" "import" (findfile "tbinc.las") "restore" "tbinc"
    "" "")
    (princ))
     
    Tom Smith, Nov 4, 2004
    #6
  7. jlspartz

    Rick Keller Guest

    Here is what I use.

    First create a block with the layers & dimstyles etc...
    Then change this routine to point to where your block is.
    This will insert your block which brings in all of your layers then it
    purges it out so the block isn't there anymore.



    (DEFUN C:LAD (/)
    (COMMAND "INSERT" "LA-DIM=//g12/support/template/LA-DIM.DWG" "0,0" "1" "1"
    "0")
    (command "erase" (entlast) "")
    (command "purge" "b" "la-dim" "n")

    )
     
    Rick Keller, Nov 4, 2004
    #7
  8. jlspartz

    Jim Dee Guest

    Have you tried Layer Lexicon from www.caddee.com? It's really easy to
    import your layer standards from a drawings that has them defined or to
    create new layers. What's great about it is your layer standard can exist
    on a network drive and when you add a new layer everyone has access to it
    immediately, and Layer Lexicon floats over the AutoCAD screen so you can get
    to it quickly!

    Jim Dee
    www.caddee.com
     
    Jim Dee, Nov 4, 2004
    #8
  9. jlspartz

    Tom Smith Guest

    This will insert your block which brings in all of your layers then it
    purges it out so the block isn't there anymore.

    That's not necessary. Precede the block name with an asterisk, and it
    inserts an exploded block -- the block definition isn't added to the
    drawing. Since a layer-only drawing wouldn't contain any graphic entities,
    there's nothing to erase, and there's no block to purge. You could
    accomplish the same with:

    (COMMAND "INSERT" "LA-DIM=*//g12/support/template/LA-DIM.DWG" "0,0" "1" "1"
    "0")
     
    Tom Smith, Nov 4, 2004
    #9
  10. jlspartz

    Rick Keller Guest

    (COMMAND "INSERT" "LA-DIM=*//g12/support/template/LA-DIM.DWG" "0,0" "1" "1"
    "0")
    Invalid file name.


    Originally I just inserted the block and left it there. (it didn't hurt
    anything) the command re-defines it.
    Then someone gave me the idea of purging it.... so I did.

    Rick
     
    Rick Keller, Nov 4, 2004
    #10
  11. jlspartz

    j.buzbee Guest

    Wow! Alot of inserting drawings goin on round here!

    Importing layers from a drawing: ObjectDBX is the only way to go.

    Importing Layer States: not recommended, you have to deal with missing line
    types, plot styles, etc. and you get all the layers! Better to keep them in
    the same file with your 200 "standard" layers. Open that document via
    ObjectDBX, restore the state you want, create a list of the layers and
    they're states, compare that to the layers present in the active document
    and change as needed.

    I think a posted just such an example of what I use for importing Layers.
    Search the CF for "jbImportLayers" I think.

    jb
     
    j.buzbee, Nov 4, 2004
    #11
  12. jlspartz

    Tom Smith Guest

    My mistake. You can't do the asterisk-prefix trick and the block update
    trick all in one string.

    I can see wanting to update the block if you think it might be lingering in
    the drawing, but if that's the case, wouldn't the layers already be present?

    I use the asterisk-explosion trick on inserting some blocks, not on others.
    It depends on whether I want the thing intact as a typical block, or whether
    I'm just using insert to import a complex, multi-layered group of elements,
    such as a standard detail.
     
    Tom Smith, Nov 4, 2004
    #12
  13. jlspartz

    jlspartz Guest

    Wow, I see there's lots of ways to do it. I don't want to make a list of all my layers to be imported, and layer lexicon looks nice, but I'd rather not have another window on my screen. Making a drawing with all the layers and then importing it sounds like a great idea to me. Thanks a lot for everyone's help!

    Tom Smith, Thanks for the routines you posted that import linetypes and layer states too. I am looking to do that next.
     
    jlspartz, Nov 4, 2004
    #13
  14. jlspartz

    jlspartz Guest

    I will definitely check out jbimportlayers when I got a chance. Thanks!
     
    jlspartz, Nov 4, 2004
    #14
  15. jlspartz

    jlspartz Guest

    I have the jbimportlayer utility loaded and when I type in jbimportlayer i get a message saying cannot load project jb00. what needs to be done?
     
    jlspartz, Nov 4, 2004
    #15
  16. jlspartz

    j.buzbee Guest

    You need to have the following list of files for the program to work
    properly:
    jbCommonFunctions.lsp
    jbImportLayers.lsp
    jbImportLayersDCL.lsp
    jb00.odc
    ObjectDCL.arx

    You need to have all these files in AutoCAD's search path. The best way is
    to make a folder labeled "jbTools" and add that to the search path in the
    options dialog.

    The program was provided as a programming example for useing ObjectDBX to
    import objects from a table ( or dictionary ). You can use it "as is" or
    customize the programming . . .. The way the tree control works on the
    dialog is it sorts layer names based on layer filters set up in the file
    your accessing. Example: You have the following layers; A-Door,
    A-Door-Fram, A-Door-Sill. Set up a layer filter called "Doors" and set the
    filter to "A-Door*". "Architectural Layers" - "A-*" will find and sort all
    layers starting with "A-"; "A-Wall", "A-Door-Fram" etc.

    jb
     
    j.buzbee, Nov 5, 2004
    #16
  17. jlspartz

    jlspartz Guest

    I haven't tested it out yet. But is this going to work if we delete all layer filters? We have a massive amount of layer filters, so I set it up in the acad2005doc to automatically delete all layer filters each time a drawing is opened. It's for the sake of the layer manager, so it doesn't take 5 minutes to open, and no one uses filters here anyway.
     
    jlspartz, Nov 5, 2004
    #17
  18. jlspartz

    jlspartz Guest

    I see the 'All layers' filter stays because it can't be deleted. Is there a way when going to select a drawing file to pull the layers from that it would start you out in a specific folder?
     
    jlspartz, Nov 5, 2004
    #18
  19. jlspartz

    j.buzbee Guest

    Yes. Look for the following subroutine in the jbImportLayersDCL.lsp:

    ;;; Function called when the Open button is pressed.
    ;layerlist remains global until close
    ;jb%ImpLayFile remains global for the drawing session
    (defun c:IML_OP_OnClicked ( / new-file)
    (setq new-file(getfiled "\nSelect a Layer file: " "" "dwg;dws" 0))
    (if new-file
    (progn
    (setq jb%ImpLayFile new-file)
    (Odcl_Tree_Clear jbLS_IML_LFT)
    (c:IML_OnInitialize)))
    )

    Change the directory argument in the getfiled call to wherever you want to
    start out in.

    BTW, are you using ADT2005? If so, I havn't checked to see if "Layer
    Filters" have changed. The tree control on the right sorts the layers based
    on the standard layer drawing, NOT the current drawing.

    jb
     
    j.buzbee, Nov 5, 2004
    #19
  20. jlspartz

    jlspartz Guest

    Alright, I got it going to the right folder now.

    I am running it in ADT2005. The layer filters work perfectly in it. No problem at all. I love this program. Great work! All it needs now is a select all button.
     
    jlspartz, Nov 5, 2004
    #20
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.