Hello,
I've modified my code as per your requirement, I've kept it simpler so that you can understand it step by step.
For assigning colors you can add colors to text directly as shown in below image.
Please try following code in attached:
(defun c:test (/ laycol layer s i o v c)
(defun laycol (o)
(if (setq
o (vla-item (vla-get-layers
(vla-get-activedocument (vlax-get-acad-object))
)
(vla-get-layer o)
)
)
(vla-get-color o)
)
)
(defun layer (name color)
(entmake (list
'(0 . "LAYER")
(cons 100 "AcDbSymbolTableRecord")
(cons 100 "AcDbLayerTableRecord")
(cons 2 name)
(cons 70 0)
(cons 62 color)
(cons 6 "Continuous")
)
)
)
(if (setq s (ssget "_:L" '((0 . "*TEXT"))))
(repeat (setq i (sslength s))
(setq o (vlax-ename->vla-object (ssname s (setq i (1- i))))
v (strcat "A-_" (vla-get-textstring o) "-N")
c (vla-get-color o)
)
(if (eq c 256)
(setq c (laycol o))
)
(if (not (tblsearch "layer" v))
(progn
(layer v c)
(princ (strcat "\nNew layer created : " v))
)
(princ (strcat "\nLayer exists : " v))
)
)
)
(princ)
)