31 July 2013

How to create layers in AutoLISP and how to set the layers in AutoLISP || Working with layers in AutoLISP

Hi Friends, in this article I will explain about how to create layers in AutoLISP and how to set the layers in AutoLISP.
How to create layers in AutoLISP:
The syntax of create layer is
(command "layer" "n" [layer name] "c" [layer color] [layer name] "")

Example:
(command "layer" "n" "text" "c" "blue" "text" "")

We can create all layers in one function and use this function anywhere in the program. Let’s see how I create function and use the function.
Open the Visual Lisp Editor and write the following code or simply copy and paste the below code.
(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" "")
)

How to set layers in AutoLISP:
The syntax of set layer is
(command "layer" "s" [layer name] "")
Example:
(command "layer" "s" "text" "")

I explained with one example.In this example I create one rectangle,one line,one circle and giving hatch to circle and text as AutoLISP-kishore.

(defun c:lay()
  (create_layer) ;;;;calling the create layer function
  (setq p1(getpoint "\n pick first point")
p2(getpoint "\n pick second point")
)
  (change_layer "beam")
  (command "rectang" p1 p2 "")
  (change_layer "crossb")
  (command "line" p1 p2 "")
  (change_layer "title")
  (command "text" "s" "text" "j" "br" p2 5 "0" "AutoLISP-kishore")
  (change_layer "cir")
  (command "circle" p1 2 "")(change_layer "hatch")
  (command "hatch" "net" "0.5" "45" "l" "")
  )
;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun create_layer()
(command "layer" "n" "text" "c" "blue" "text" "")
(command "layer" "n" "wall" "c" "white" "wall" "")
(command "layer" "n" "line" "c" "red" "line" "")
(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" "")
)
;*****************************************************************************
(defun change_layer(la_name)
(command "layer" "s" la_name "")
)

Save the above code as LAY.LSP. Open AutoCAD, In command prompt enter (load “lay”), lay and pick first point and second point.

Command: (load "lay")
Command: lay
pick first point
 pick second point
Then the output will like below.


Thank you for reading my blog AutoLISP-Kishore..If you like my blog please like the facebook page AutoLISP-Kishore.

No comments:

Post a Comment