Sunday, January 26, 2014

How To Create Layers With AutoLISP

You know about layers. You can create them in AutoCAD or an alternative program for AutoCAD. And draw on them.


But you can also create them with AutoLISP. I know. You want to know how it is done. That is what you'll find in this post.


Kishore Gave Me An Idea


Talking about creating layers with AutoLISP. Kishore gave me that idea. I read about it on his blog. His blog is here:


http://autolisp-kishore.blogspot.com/


Kishore had an AutoLISP program for creating layers with AutoLISP. This is the program that he had.


Kishore's AutoLISP Program


(defun create_layer()
(command "layer" "n" "text"
"c" "blue" "text"
""
)
(command "layer" "n" "wall"
"c" "white" "wall"
""
)
(command "layer" "n" "line"
"c" "red" "dim"
""
)
(command "layer" "n" " title "
"c" "cyan" " title "
""
)
(command "layer" "n" "cir"
"c" "13" "cir"
""
)
(command "layer" "n" "hatch"
"c" "magenta" "hatch"
""
)
(command "layer" "n" "Beam"
"c" "green" "Beam"
""
)
(command "layer" "n" "crossb"
"c" "yellow" "crossb"
"lt" "hidden" "crossb"
""
)
)


With the AutoLISP program the following layers were created:


- TEXT
- WALL
- LINE
- TITLE
- CIR
- HATCH
- BEAM
- CROSSB


All the layers were given a color and of the last layer even the line type was changed.


Extra Information


I would like to give you a little bit extra information. Let's talk about the LAYER command first. This is the prompt:


? to list/New/Make/Set/Color/Ltype/LWeight/Print/ PStyle/ON/OFF/Freeze/Thaw/LOck/Unlock:


As you can see the LAYER command has got 15 options. You can invoke an option by entering the capitalized character at the prompt.


I'm not going to talk about all the options of the LAYER command. I do not want to write an AutoCAD course. But two options I will mention.


NEW Option And MAKE Option


I will mention the NEW option and the MAKE option. Both options can be used for creating a new layer with AutoLISP.


But these two options do not work the same. They work differently. Kishore has used the New option. I only use the MAKE option.


If you use the NEW option, then there is asked for the name of the new layer. Next you want to give the new layer a color.


You invoke the COLOR option. You enter the color that you want. Next there is asked what layer gets that color.


You gave the name of the new layer. But that name isn't shown. So you must enter the name of the new layer again.


OK. A new layer is created. But the new layer is not activated. If you want to draw on that layer, you must SET it first.


Do you see. In the AutoLISP program from Kishore the name of the new layer is given again after a color has been selected.


The MAKE Option


The MAKE option is different. Let me show you with a program of myself.


(defun nwlyr ()
(command "layer" "m" "025"
"c" "red" ""
""
)
(command "layer" "m" "035"
"c" "yellow" ""
""
)
(command "layer" "m" "050"
"c" "green" ""
""
)
)


Do you see? I have entered the color of the new layer. There is asked to what layer the color goes. Between brackets is the new layer.


So I do not have to enter the name of the layer again. I can give a return or click on the right mouse button.


New Layer Is Activated


There is another difference with NEW option of the LAYER command. The newly created layer is activated. You can draw on it right away.


I think that is a very important advantage. I create new layers with the MAKE option. I don't have to set the new layer.


OK. I gave you some additional information. I did not do that to suggest the Kishore didn't give good information.


The Blog Of Kishore


In fact. You can visit the blog of Kishore. He has got a lot more AutoLISP programs on his blog. This is the address:


http://autolisp-kishore.blogspot.com/










No comments:

Post a Comment