AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

To check for the existence of a Layer, Style or a Dimstyle can be achieved in a couple of ways. To achieve it using plain old AutoLisp and the (tblsearch) function, have a look here:

Working with Layers, DimStyles and Styles
http://www.afralisp.com/lispa/lisp31.htm

eg.
(defun C:Lon ()
(if (tblsearch "LAYER" "STEEL")
(command "layer" "on" "STEEL" "")
(princ "\nLayer STEEL not found")
)
(princ)
)

If you would like to achieve it the "new" way, (and the preferable way I
must admit) have a look at doing it using Visual Lisp :

Visual Lisp Collections
http://www.afralisp.com/vl/collect1.htm

eg.
(defun c:layerAdd ()
(vl-load-com)
(setq acadDocument (vla-get-activedocument (vlax-get-acad-object))
theLayers (vla-get-layers acadDocument)
newLayer (vla-add theLayers "Steel"))
(vla-put-color newLayer 5)
(vla-put-linetype newLayer "Dashed2")
(princ)
);defun

This routine creates a new Layer named "Steel" with Color "5" and a Linetype
of "Dashed2". If the Layer already exists, this routine simply does nothing.
Visual Lisp may seem a bit daunting at first, but believe me, it's the way
to go..

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright © 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website