Requesting Layer LISP routine

Discussion in 'AutoCAD' started by Scott Davis, Aug 5, 2004.

  1. Scott Davis

    Scott Davis Guest

    I'm looking for a LISP that does several things with layers. First, I need
    to search existing drawings for specific layer names. If they are present,
    it checks the color of the layer and changes it if it doesnt meet standards.
    If not present, it creates the layer and assigns a color. If there are
    layers in the drawing that aren't in the standard list, I need to rename
    them to something like FIXME1 so that I know i need to do some additional
    clean up.

    I know its alot, but figured someone has run into something similar!

    TIA
     
    Scott Davis, Aug 5, 2004
    #1
  2. Scott Davis

    Chip Harper Guest

    Are you looking for assistance to write your own or are you looking for the
    finished product?
     
    Chip Harper, Aug 5, 2004
    #2
  3. Scott Davis

    jclaidler Guest

    The code below will create layer '27' if it doesn't exist, then set the color to yellow.


    (if (not (tblsearch "LAYER" "27")) (command "LAYER" "N" "27" ""))
    (command "-layer" "c" "yellow" "27" "")
     
    jclaidler, Aug 5, 2004
    #3
  4. Scott Davis

    Tom Smith Guest

    (if (not (tblsearch "LAYER" "27")) (command "LAYER" "N" "27" ""))
    Not necessary if you use the layer "make" option -- it will change the
    layer's properties is it exists or create if if necessary.

    (command "layer" "make" "27" "c" "27" "")

    The standards checker in 2004 can be used to check for non-conforming
    layers.
     
    Tom Smith, Aug 5, 2004
    #4
  5. Scott Davis

    jclaidler Guest

    yeah.. that's another way to do it, but with the same result.
     
    jclaidler, Aug 5, 2004
    #5
  6. Scott Davis

    Scott Davis Guest

    Thanks guys!

    Is there an easy way to build a list, say from an Excel document or TXT
    file, that would contain the layer names that would need to be checked?
    Something like:

    (command "layer" "make" "A-ANNO-DIMS" "c" "1" "")
    (command "layer" "make" "A-ANNO-NOTE" "c" "2" "")
    (command "layer" "make" "A-ANNO-SYMB" "c" "2" "")
    (command "layer" "make" "A-ANNO-TEXT" "c" "3" "")
    etc.
    etc.

    Where the layer names are compiled from a list? Hmmmm...I have an idea. An
    Excel table, where:

    cell A is (
    cell B is command
    cell C is "layer"
    etc.

    Then export the Excel to a TXT file, save as LAYERFIX.lsp I will need to
    put the required spaces in the cells...but I think it will work.

    Any other ideas? Thanks again for getting me going.
     
    Scott Davis, Aug 5, 2004
    #6
  7. Scott Davis

    Scott Davis Guest

    A little of both...I can write some code, or if someone has something
    similar, I could borrow that. If someone is willing to share a finished
    product, well that would be cool too!
     
    Scott Davis, Aug 5, 2004
    #7
  8. Scott Davis

    Mack Attack Guest

    Just my $.02 but while you are doing this you might want to add the linetype
    in also I had done one similar to what you have below and didn't add
    linetypes and sure enough there were a few linetypes that had been changed.
     
    Mack Attack, Aug 5, 2004
    #8
  9. Scott Davis

    Scott Davis Guest

    Thanks for the help! I'll check it out.

     
    Scott Davis, Aug 5, 2004
    #9
  10. Scott Davis

    Scott Davis Guest

    cool! good idea, and thanks for the advice!
     
    Scott Davis, Aug 5, 2004
    #10
  11. Scott Davis

    Tom Smith Guest

    As I mentioned, the CAD standards utility which is built into 2004 does
    exactly this, and it's standard. Prior to 2004, it was an extension
    available to subscription customers. I don't believe in doing custom
    programming which duplicates or very nearly duplicates a built-in
    capability.

    As has been hinted, another way to accomplish the same thing, using a
    built-in methodology, is to use the layer manager to export a list of
    standard layers from a "clean" drawing. Import this layer state into a
    non-standard drawing, and you're done. Existing layers will have all their
    properties corrected, missing layers will be created, and the only things
    remaining to fix will be the non-standard extraneous layers.

    Unless there are very many of these, or hundreds of drawings to process, I
    think it ought to be easy enough to spot the nonconforming layers and fix
    them manually.
     
    Tom Smith, Aug 5, 2004
    #11
  12. Scott Davis

    Tom Smith Guest

    yeah.. that's another way to do it, but with the same result.

    What a gracious way of saying "gosh, I didn't know that."

    Yeah, it's "another" way, that's shorter, more direct, and devoid of
    unnecessary and redundant code, taking advantage of the way the layer
    command has always worked.
     
    Tom Smith, Aug 5, 2004
    #12
  13. Scott Davis

    jclaidler Guest

    But with lisp, it can be done 'behind the scenes' without any need for user input.
     
    jclaidler, Aug 5, 2004
    #13
  14. Scott Davis

    j.buzbee Guest

    What I use is a drawing as the database ( when it comes to resident AutoCAD
    objects I don't see why people go to outside databases???). Here's how it
    works:

    In the "Standard" drawing I have all the layers I'm ever going to use.
    Using the Layer State Manager object I've saved all the combinations of
    those layers ( architecture: floor plan, reflected ceiling plan, etc. )
    From the active document I can access the "standard" drawing using the
    ObjectDBX activex object. I make two lists: one of the layers in the active
    document and one from the standard drawing then compare. This appliqué
    allows one to easily mange standard layers in an AutoCAD environment while
    being easily accessed by other users. This approach could easily be
    tailored to your needs.

    What you'll need:
    A collection of routines to "open" and "close" a dbx document. ( do a
    search - Tony T. has some excellent examples)
    A collection of routines for manipulating the Layer State object. ( the
    AutoCAD help has some examples )
    Some simple routines for manipulating layers in the active document. (
    believe it or not I use "command -layer . . .")

    Believe me, EVERYTHING you need to write this yourself is on the net.
    You'll find a number of fishermen (fisherpersons?) willing to show you how
    to catch the big fish but very few fish mongers willing to give you a fish.

    jb

    p.s. I've written some very powerful programs with the help of individuals
    on the NG ( thanks again guys! )
     
    j.buzbee, Aug 5, 2004
    #14
  15. Scott Davis

    Scott Davis Guest

    I checked into the Standards Checker. Seems like this just 'notifies' you
    of violations of the standards.....or does it actually fix them? Any
    insight into how this works? I thought about the layer manager thing, too.
     
    Scott Davis, Aug 5, 2004
    #15
  16. Scott Davis

    Tom Smith Guest

    All we use is the built-in layer manager. We have saved layer states meeting our standards, and a button on a toolbar which simply runs the layer command with the option to import a saved layer state from a file. If a drawing is fouled up, you push a button, ka-ching, you're done. The only programming involved was writing the button macro.

    Again, I don't believe in spending time on creating a customization which duplicates a built-in capability. I'm not afraid of writing lisp when the situation requires it, but I don't do it for sport.

    The answer to most common questions is to spend more time in the help docs and learn how close the software already comes to meeting your needs. Explore and understand every option of the command-line -LAYER command first. Then tweak it as necessary.
     
    Tom Smith, Aug 6, 2004
    #16
  17. Scott Davis

    Scott Davis Guest

    Using the layer manager and saved layer states, this will create layers that
    are not present? If you have a saved layer state with 100 layers, open a
    new file with no layers, and restore the saved layer state, it will create
    all 100 layers?


    meeting our standards, and a button on a toolbar which simply runs the
    layer command with the option to import a saved layer state from a file. If
    a drawing is fouled up, you push a button, ka-ching, you're done. The only
    programming involved was writing the button macro.
    duplicates a built-in capability. I'm not afraid of writing lisp when the
    situation requires it, but I don't do it for sport.
    and learn how close the software already comes to meeting your needs.
    Explore and understand every option of the command-line -LAYER command
    first. Then tweak it as necessary.
     
    Scott Davis, Aug 6, 2004
    #17
  18. Scott Davis

    j.buzbee Guest

    So what if your standard layer file has over 700 layers? When you import a
    layer state you import all layers instead of only those needed. Sounds like
    a sledge hammer when all was needed is a screw driver!

    As for programming for sport - just because you lack the capacity to
    understand that the true power of AutoCAD is it's open architecture doesn't
    mean those who utilize that power are excercising mental masturbation.

    just my humble E0.02 (which = about 0.017 USD)

    jb


    meeting our standards, and a button on a toolbar which simply runs the
    layer command with the option to import a saved layer state from a file. If
    a drawing is fouled up, you push a button, ka-ching, you're done. The only
    programming involved was writing the button macro.
    duplicates a built-in capability. I'm not afraid of writing lisp when the
    situation requires it, but I don't do it for sport.
    and learn how close the software already comes to meeting your needs.
    Explore and understand every option of the command-line -LAYER command
    first. Then tweak it as necessary.
     
    j.buzbee, Aug 6, 2004
    #18
  19. Scott Davis

    Tom Smith Guest

    Using the layer manager and saved layer states, this will create layers
    that are not present?

    Yes, try it.
     
    Tom Smith, Aug 9, 2004
    #19
  20. Scott Davis

    Tom Smith Guest

    So what if your standard layer file has over 700 layers?

    Mine doesn't, and apparently neither does the OP's. We have several saved
    layer states which contain the same list of standard layers, with different
    visibility settings appropriate to different tasks. If we needed different
    sets of layers for different types of drawings, then I would probably
    maintain a standard "clean" version of each drawing type from which to
    export its layer state. The OP refered to one standard list of layers, not
    multiple possible standard lists.
    The OP wanted to create any layers on his standard list which were missing,
    or fix the layer properties if they didn't match standards. If his standard
    demanded 700 layers, then I would assume he would want all 700 of them
    created. In fact he's asking about 100 layers. He said he wants them all
    imported. Sounds like offering the tool that was requested!
    Offensive and unnecessary.

    You proposed that the OP go off on a programming expedition to do something
    which, from your description, appears to duplicate the functionality of the
    layer states manager, if it were applied to his case. I suggested that he
    use the layer states manager as is. If that fails to meet his needs I'm sure
    he'll continue looking for a solution. Relax.
     
    Tom Smith, Aug 9, 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.