Creating a layer with Description under 2002 and 2005?

Discussion in 'AutoCAD' started by Sage Cowsert, May 19, 2004.

  1. Sage Cowsert

    Sage Cowsert Guest

    I'm incorporating AutoCAD layer descriptions into my standard set of lisp
    routines. So far this is where I'm at. Sometimes when I run it line by line
    it will set the description. When ran as is sometimes it doesn't set it at
    all and I can't figure out why? Plus I'm sure this code can be trimmed down
    some. I'd also like this code to run on both AutoCAD 2002 and 2005.

    Thoughts? Oh and Thanks a bunch for taking a look. :)

    Sage


    ;(MAKELAYER "TEST" "1" "CONTINUOUS" "" "TESTING TESTING")

    (defun MAKELAYER (LAYNAME LAYCLR LAYLT LAYWEIGHT DESCRIPTION / ELIST)
    (setq ELIST '((0 . "LAYER")
    (100 . "AcDbSymbolTableRecord")
    (100 . "AcDbLayerTableRecord")
    (70 . 0)
    )
    )
    (setq ELIST (append ELIST (list (cons 2 LAYNAME))))

    (if LAYCLR
    (setq ELIST (append ELIST (list (cons 62 (read LAYCLR)))))
    )
    (if LAYLT
    (setq ELIST (append ELIST (list (cons 6 LAYLT))))
    )
    (if (= LAYNAME "DEFPOINTS")
    (setq ELIST (append ELIST '((290 . 0))))
    )
    (if (/= NIL (distof LAYWEIGHT))
    (setq ELIST (append ELIST (list (cons 370 (atoi LAYWEIGHT)))))
    )
    (entmake ELIST)

    (if DESCRIPTION
    (progn
    (setq LAYER_OBJECT (tblobjname "layer" LAYNAME))
    (entmod (append (entget LAYER_OBJECT)
    (list (list -3 (list "AcAecLayerStandard" '(1000 . "") (cons 1000
    DESCRIPTION))))
    )
    )
    )
    )
    )
     
    Sage Cowsert, May 19, 2004
    #1
  2. Thoughts... move to ActiveX.

    --
    R. Robert Bell


    I'm incorporating AutoCAD layer descriptions into my standard set of lisp
    routines. So far this is where I'm at. Sometimes when I run it line by line
    it will set the description. When ran as is sometimes it doesn't set it at
    all and I can't figure out why? Plus I'm sure this code can be trimmed down
    some. I'd also like this code to run on both AutoCAD 2002 and 2005.

    Thoughts? Oh and Thanks a bunch for taking a look. :)

    Sage


    ;(MAKELAYER "TEST" "1" "CONTINUOUS" "" "TESTING TESTING")

    (defun MAKELAYER (LAYNAME LAYCLR LAYLT LAYWEIGHT DESCRIPTION / ELIST)
    (setq ELIST '((0 . "LAYER")
    (100 . "AcDbSymbolTableRecord")
    (100 . "AcDbLayerTableRecord")
    (70 . 0)
    )
    )
    (setq ELIST (append ELIST (list (cons 2 LAYNAME))))

    (if LAYCLR
    (setq ELIST (append ELIST (list (cons 62 (read LAYCLR)))))
    )
    (if LAYLT
    (setq ELIST (append ELIST (list (cons 6 LAYLT))))
    )
    (if (= LAYNAME "DEFPOINTS")
    (setq ELIST (append ELIST '((290 . 0))))
    )
    (if (/= NIL (distof LAYWEIGHT))
    (setq ELIST (append ELIST (list (cons 370 (atoi LAYWEIGHT)))))
    )
    (entmake ELIST)

    (if DESCRIPTION
    (progn
    (setq LAYER_OBJECT (tblobjname "layer" LAYNAME))
    (entmod (append (entget LAYER_OBJECT)
    (list (list -3 (list "AcAecLayerStandard" '(1000 . "") (cons 1000
    DESCRIPTION))))
    )
    )
    )
    )
    )
     
    R. Robert Bell, May 19, 2004
    #2
  3. Sage Cowsert

    Sage Cowsert Guest

    Hehe... I guess I did as for Thoughts. :)

    Man that sounds like homework though. ;)
     
    Sage Cowsert, May 19, 2004
    #3
  4. It is not as bad as it seems.

    Granted, this posted code does not do any real error handling, such as
    checking that the linetype is loaded. But it ought to give you a start, and
    as a bonus it supports TrueColor, which your code did not.


    (defun MakeLayer (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


    (MakeLayer "Test" 3 "Continuous" acLnWt015 "Just kidding")
    <VLA-OBJECT IAcadLayer2 0a2e6ac4>

    (setq myColor (vla-GetInterfaceObject (vlax-Get-Acad-Object)
    "AutoCAD.AcCmColor.16"))
    <VLA-OBJECT IAcadAcCmColor 0a3072a0>
    (vla-SetRGB myColor 37 82 56)
    nil
    (MakeLayer "Test2" myColor nil nil "Just kidding again")
    <VLA-OBJECT IAcadLayer2 0a302cb4>
    (vlax-Release-Object myColor)



    --
    R. Robert Bell


    Hehe... I guess I did as for Thoughts. :)

    Man that sounds like homework though. ;)
     
    R. Robert Bell, May 19, 2004
    #4
  5. Sage Cowsert

    Sage Cowsert Guest

    Thanks Robert, that code works great. I haven't tested it yet but I assume
    the vla-Put-Description doesn't exist in 2002?
     
    Sage Cowsert, May 20, 2004
    #5
  6. I'm sure it didn't. But you can easily check for TuTu as part of the
    (cond)'s test.

    --
    R. Robert Bell


    Thanks Robert, that code works great. I haven't tested it yet but I assume
    the vla-Put-Description doesn't exist in 2002?
     
    R. Robert Bell, May 20, 2004
    #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.