TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: EagerToLearnCad 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 "")
)
-
Here's a quick example ... I'd get away from the command calls.
(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")
-
(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.
(_layer "alan$$" 2 "hidden2" :vlax-false "layer for alan's crap")
Edit: Modified to account for invalid layer name.
-
Wow..two ways of going about it. I love it. Thank you guys!
-
Basically the same thing, I was just playing around.
-
(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")
-
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.
(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.
(_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. :)