edit lisp for check layer exists, if not, create layer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
This has been looked at many times but I have searched the forums and can not find a specific solution that will work.
Testing on AutoCAD 2016
Premise:
Load Linetype from Linetype file,
Check for layer,
if found updated properties,
if not found create..
Here's what we've got so far. Needs QC checked because it doesn't function correctly.
(defun c:NGD ()
(setq echo (getvar "cmdecho")
(setvar "cmdecho" 0)
)
;if linetype exist, reload it
;(if (tblsearch "ltype" "NATURAL_GAS(DEMO)")
(command "-linetype" "load" "NATURAL_GAS(DEMO)" "X:/Line-Types/acad.lin" "" "")
(if (tblsearch "layer" "C_1UDG_NGAS_PIPE_DEMO")
(command "clayer" "C_1UDG_NGAS_PIPE_DEMO" "")
)
(if (not (tblsearch "layer" "C_1UDG_NGAS_PIPE_DEMO"))
(command "_.LAYER" "M" "C_1UDG_NGAS_PIPE_DEMO" "c" "79" "" "LT" "NATURAL_GAS(DEMO)" "" "D" "Natural Gas Pipe Existing" "C_1UDG_NGAS_PIPE_DEMO" "")
)
(command "clayer" "C_1UDG_NGAS_PIPE_DEMO" "")
(command "graphscr")
(command "undo" "end")
(setvar "cmdecho" 1)
)