Author Topic: Creating layers with layer description option  (Read 6825 times)

0 Members and 1 Guest are viewing this topic.

EagerToLearnCad

  • Guest
Creating layers with layer description option
« on: April 14, 2010, 03:24:33 PM »
Hello,

I decided to add a layer description to this old simple handy lisp
routine that creates/makes layers. The problem is that I cannot
run it twice. It has someting to with the layer description option.
Can somebody please fix this routine or point me to one that can
do something similar...Thanks.


(defun c:Test ()
(MakeLayer "M-REFG-EQPM-DEMO" "6" "Hidden" "Refrigeration systems: equipment to be Demolished")
(MakeLayer "M-REFG-PIPE-DEMO" "75" "Hidden" "Refrigeration systems: piping to be Demolished")
)

 
;;;
(defun MakeLayer (LayerName LayerColor LayerLType LayerDesc)
(command "layer" "m" LayerName "c" LayerColor "" "lt" LayerLType "" "D" LayerDesc LayerName "")
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Creating layers with layer description option
« Reply #1 on: April 14, 2010, 04:13:46 PM »
Here's a quick example ... I'd get away from the command calls.

Code: [Select]
(defun redefinelayer (layname clr ltype plt desc / lay)
  (if (and ;;(not (tblobjname "layer" layname))
   (setq lay
  (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
   layname
  )
   )
      )
    (progn (if (tblobjname "ltype" ltype)
     (vla-put-linetype lay ltype)
     (vla-put-linetype lay "continuous")
   )
   (vla-put-linetype lay ltype)
   (vla-put-color lay clr)
   (vla-put-plottable lay plt)
   (vla-put-description lay desc)
    )
  )
)
(redefinelayer "test" 3 "continuous" :vlax-false "My Snazzy Description")
« Last Edit: April 14, 2010, 05:56:29 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Creating layers with layer description option
« Reply #2 on: April 14, 2010, 05:41:03 PM »
Code: [Select]
(defun _Layer (Name Color LType Plot? Desc)
  ;; Alan J. Thompson, 04.14.10
  ((lambda (la)
     (if (not (vl-catch-all-error-p la))
       (mapcar
         (function
           (lambda (p v)
             (not (vl-catch-all-apply
                    (function vlax-put-property)
                    (list la p v)
                  )
             )
           )
         )
         '(Color Linetype Plottable Description)
         (list Color LType Plot? Desc)
       )
     )
   )
    (vl-catch-all-apply
      (function vla-add)
      (list (vla-get-layers
              (cond (*AcadDoc*)
                    ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
              )
            )
            Name
      )
    )
  )
)

eg.
Code: [Select]
(_layer "alan$$" 2 "hidden2" :vlax-false "layer for alan's crap")

Edit: Modified to account for invalid layer name.
« Last Edit: April 14, 2010, 09:12:38 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

EagerToLearnCad

  • Guest
Re: Creating layers with layer description option
« Reply #3 on: April 14, 2010, 05:52:56 PM »
Wow..two ways of going about it. I love it. Thank you guys!

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Creating layers with layer description option
« Reply #4 on: April 14, 2010, 05:58:13 PM »
Basically the same thing, I was just playing around.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: Creating layers with layer description option
« Reply #5 on: April 14, 2010, 06:15:19 PM »
Code: [Select]
(defun CreateLayer (Name FrzLock Color LType Plot? LWeight Desc)
  (entmakex
    (list (cons 0 "LAYER")
  (cons 100 "AcDbSymbolTableRecord")
  (cons 100 "AcDbLayerTableRecord")
  (cons 2 Name)
  (cons 70 FrzLock)
  (cons 62 Color)
  (cons 6 LType)
  (cons 290 Plot?)
  (cons 370 LWeight)
  (list -3 (list "AcAecLayerStandard" (cons 1000 "") (cons 1000 Desc)))
    )
  )
)
(CreateLayer "test" 1 5 "continuous" 0 -3 "this is a test")

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Creating layers with layer description option
« Reply #6 on: April 14, 2010, 11:19:23 PM »
Didn't get a chance to post this one earlier (my little girl is sick with Strep-Throat).

Will allow you to create multiple layers.
Code: [Select]
(defun _Layers (lst)
  ;; Alan J. Thompson, 04.14.10

  ((lambda (lay)
     (foreach l lst
       ((lambda (la)
          (if (not (vl-catch-all-error-p la))
            (mapcar
              (function
                (lambda (p v)
                  (not (vl-catch-all-apply
                         (function vlax-put-property)
                         (list la p v)
                       )
                  )
                )
              )
              '(Color Linetype Plottable Description)
              ;;(list Color LType Plot? Desc)
              (cdr l)
            )
          )
        )
         (vl-catch-all-apply (function vla-add) (list lay (car l)))
       )
     )
   )
    (vla-get-layers
      (cond (*AcadDoc*)
            ((setq *AcadDoc* (vla-get-activedocument (vlax-get-acad-object))))
      )
    )
  )
)

eg.
Code: [Select]
(_layers (list '("Layer1" 1 "Hidden2" :vlax-false "Layer #1")
               '("Layer2" 2 "Continuous" :vlax-true "Layer #2")
         )
)

Vovka, I didn't know it was possible, or at least, didn't know how to add description with entmake/mod. Learn something new every day; thanks. :)
« Last Edit: April 14, 2010, 11:24:21 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox