Message 1 of 2
Adding Prefix and Suffix options for newly created Layer names

Not applicable
05-31-2020
01:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Dear Experts,
I got a code from this forum only, which can create layers for selected polylines.
The requirement is to ask the user for Prefix and Suffix names for newly created layers at command prompt.
Thanks a lot in advance.
(Defun c:CPL ( / checkName made _reMade _newLay ss i ent lay clay p f)
(defun checkName (s n)
(while (tblsearch
"Layer"
(Setq ln (Strcat s "_" (itoa n))))
(Setq n (1+ n)))
(list ln n)
)
(defun _reMade (cly / f)
(if (setq f (assoc cly made))
(progn
(setq gn (checkName cly (1+ (Cadr f)))
made (subst (list cly (Cadr gn)) f made))
(car gn)
)
)
)
(defun _newLay (cly n / gn)
(setq gn (checkName cly n))
(setq made (cons (list cly (cadr gn)) made))
(Car gn)
)
(if (setq ss (ssget "_:L" '((0 . "LWPOLYLINE"))));<-- this could be filtered for exclusion of ---
(repeat (Setq i (sslength ss))
(setq ent (entget (ssname ss (Setq i (1- i)))))
(Setq lay (entget (tblobjname "LAYER"
(setq clay (Cdr (Assoc 8 ent))))))
(Setq nlay
(cond
((and
(wcmatch clay "*_#*")
(Setq p (vl-string-position 95 clay))
(numberp (setq n (read (substr clay (+ 2 p)))))
)
(if (setq f (_reMade (substr clay 1 p))) f
(_newLay (substr clay 1 p) n)
)
)
( (setq f (_reMade clay)) )
( (_newLay clay 1) )
)
)
(entmake (append
(list (cons 0 "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 nlay)
)
(mapcar '(lambda (d)(assoc d lay)) '(70 62 6 290 370))))
(entmod (subst (cons 8 nlay) (assoc 8 ent) ent))
)
)
(princ)
)