layer check and add

Discussion in 'AutoCAD' started by G. Willis, Mar 2, 2005.

  1. G. Willis

    G. Willis Guest

    Could someone please give me the lisp code to check if
    layers exist and if not then add them to the drawing?

    I need to add the following layers to the drawing:

    Center - blue - centerline
    Dims - yellow - continuous
    Object - magenta - continuous
    Text - green - continuous

    Thanks!

    Garth W.
     
    G. Willis, Mar 2, 2005
    #1
  2. Something like this might work:

    (if (not (tblsearch "Layer" "Center")) (vlMakeLayer "Center" 5 "Centerline"
    nil nil))

    (defun vlMakeLayer (name color ltype lweight desc / newLayer tcolor)
    (vl-load-com)
    (setq newLayer (vla-Add (vla-Get-Layers
    (vla-Get-ActiveDocument
    (vlax-Get-Acad-Object)
    )
    )
    name
    )
    )
    (cond ((= (type color) 'INT)
    (setq tcolor (vla-Get-TrueColor newLayer))
    (vla-Put-ColorIndex tcolor color)
    )
    ((= (type color) 'VLA-OBJECT) (setq tcolor color))
    )
    (cond (tcolor (vla-Put-TrueColor newLayer tcolor)))
    (cond (ltype (vla-Put-Linetype newLayer ltype)))
    (cond (lweight (vla-Put-Lineweight newLayer lweight)))
    (cond (desc (vla-Put-Description newLayer desc)))
    newLayer
    ) ; return layer object
     
    Allen Johnson, Mar 2, 2005
    #2
  3. G. Willis

    Matt W Guest

    This should get you started...

    ; Check for layer 'CENTER'
    (defun C:CheckForLayer ( / )
    (if (not (tblsearch "LAYER" "Center"))
    (command "-layer" "n" "Center" "lt" "Center" "Center" "c" "5" "Center"
    "")
    )
    (princ)
    )
     
    Matt W, Mar 2, 2005
    #3
  4. G. Willis

    Tom Smith Guest

    Search the newsgroup, many ways of doing this have been posted.

    One simple way, not requiring lisp, is to use the built-in layer states
    manager in the layer dialog. Make a drawing with the desired layers -- which
    you should have as a template anyway -- export this layer state to a file,
    then you can import it into any drawing you want.
     
    Tom Smith, Mar 2, 2005
    #4
  5. Hi,

    If you use the
    (command "Layer" "M" "Center" "C" "BLUE" "LT" "CENTERLINE" "" "") approach
    you don't need to check if the layer exists.

    The code above is right in principle, but only written from memory - it may
    be slightly out.

    --

    Regards,


    Laurie Comerford
    www.cadapps.com.au
     
    Laurie Comerford, Mar 2, 2005
    #5
  6. G. Willis

    G. Willis Guest

    THANK YOU GUYS FOR THE HELP.
    I have a standard template that I always use but the lisp
    routine that I'm now using requires different layers than I
    have in my template.
    I wanted the program to work for any case, no matter what
    layers were present in the user's drawing so I will revise
    the program
    to simply create the needed layers.
    Garth.
     
    G. Willis, Mar 2, 2005
    #6
  7. G. Willis

    G. Willis Guest

    thanks! I should have tried that first.

     
    G. Willis, Mar 2, 2005
    #7
  8. G. Willis

    Gary Fowler Guest

    Good routine....however I am having trouble entering a line weight valve.


    ;;;routine by Allen Johnson
    (defun ARCH:vlMakeLayer (LA LC LT LW LD / newLayer tcolor)
    (setq newLayer (vla-Add (vla-Get-Layers
    (vla-Get-ActiveDocument
    (vlax-Get-Acad-Object)
    )
    )
    LA
    )
    )
    (cond ((= (type LC) 'INT)
    (setq tcolor (vla-Get-TrueColor newLayer))
    (vla-Put-ColorIndex tcolor LC)
    )
    ((= (type LC) 'VLA-OBJECT) (setq tcolor LC))
    )
    (cond (tcolor (vla-Put-TrueColor newLayer tcolor)))
    (cond (LT (vla-Put-Linetype newLayer LT)))
    (cond (LW (vla-Put-Lineweight newLayer LW)))
    (cond (LD (vla-Put-Description newLayer LD)))
    newLayer
    )
    ;;;
    ;;;(ARCH:vlMakeLayer "A-TEST" 5 "CONTINUOUS" 0.083 "This is a Test")
    ;;;(if (not (tblsearch "Layer" "A-TEST")) (ARCH:vlMakeLayer "A-TEST" 6
    "Hidden" 0.25 "This is a Test"))
    ;;;

    Gary
     
    Gary Fowler, Mar 3, 2005
    #8
  9. The vlMakeLayer isn't my original routine....
    But, if I remember correctly, you need to use the ActiveX constant instead
    of a number:
    acLineWeight enum; read-write
    acLnWtByLayer
    acLnWtByBlock
    acLnWtByLwDefault
    acLnWt000
    acLnWt005
    acLnWt009
    acLnWt013
    acLnWt015
    acLnWt018
    acLnWt020 ...
     
    Allen Johnson, Mar 3, 2005
    #9
  10. G. Willis

    Gary Fowler Guest

    Thanks for the info...I'm still learning. How do I incorporate this
    to the routine?

    Gary
     
    Gary Fowler, Mar 4, 2005
    #10
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.