Here you go.
Original code by ronjonp which I then used LeeMacs code that I further modified. See comments in the code below.
Modified by 3dwannab on 2024.05.23 to add transparency, description and plot to Lee Macs function.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; _createOrUpdateLayer
;;
;; Creates a new layer or updates an existing one if it exists.
;; Will attempt to load the linetype if found in the acad*.lin file and if the layer exists, it will update the properties.
;; Original code by ronjonp, taken from: https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-layer-with-true-color-in-lisp/m-p/7904814#M367339
;;
;; USAGE:
;; (_createOrUpdateLayer "Test1" 22 "Dashed" aclnwtbylwdefault 33 :vlax-true "Test1 Description")
;; (_createOrUpdateLayer "Test2" '(100 150 200) "Continuous" aclnwtbylwdefault 33 :vlax-false "Test2 Description")
;;
;; The :vlax-true or :vlax-false in examples above is for plot on or off.
;; The 33 values represent the transparency of the layer.
;; Original help from mhupp here to get it to update layer if it exists: https://www.cadtutor.net/forum/topic/75414-defun-to-create-or-update-layers-not-updating-them/?do=findComment&comment=596266
;;
;; ARGUMENTS: ARGUMENTS SYTAX:
;; 1st arg: Layers Name = STRING
;; 2nd arg: Layers Colour = 22 or '(100 150 200) (Can be an indexed colour or true colour)
;; 3rd arg: Layers Linetype = STRING
;; 4th arg: Layers Lineweight = acLnWtByLayer, acLnWtByBlock, acLnWtByLwDefault, acLnWt000, acLnWt005, acLnWt009, acLnWt013, acLnWt015, acLnWt018, acLnWt020, acLnWt025, acLnWt030, acLnWt035, acLnWt040, acLnWt050, acLnWt053, acLnWt060, acLnWt070, acLnWt080, acLnWt090, acLnWt100, acLnWt106, acLnWt120, acLnWt140, acLnWt158, acLnWt200, acLnWt211
;; 5th arg: Layers Transparency = INTEGER (Between 0-90)
;; 6th arg: Layers is Plottable on not = :vlax-true = Plottable or :vlax-false = Not Plottable
;; 7th arg: Layers Description = STRING
;;
;; For Linewiight in vlisp, see this reply by CAB: https://www.theswamp.org/index.php?topic=22438.msg270124#msg270124
;;
;; MODIFICATIONS:
;; New code By Leemac with small modifications by 3dwannab.
;; Modified by 3dwannab on 2024.05.22 to add if the layers is plottable and also added the possibility to add a description to the layer.
;; Lee Macs code: https://www.cadtutor.net/forum/topic/66765-vla-put-truecolor/?do=findComment&comment=546879
;; Modified by 3dwannab on 2024.05.22 to add transparency, description and plot to Lee Macs function.
;; Help from mhupp here to get it to update layer if it exists: https://www.cadtutor.net/forum/topic/75414-defun-to-create-or-update-layers-not-updating-them/?do=findComment&comment=596266
(defun _createOrUpdateLayer (name color linetype lineweight transparency plottable description / _loadlinetype lay tru)
;; Credit to Grr1337
;; https://www.theswamp.org/index.php?topic=52473.msg574008#msg574008
;; (_SetLayerTransparency (getvar 'clayer) 90)
(defun _SetLayerTransparency (LayerName Transparency / lyr)
(and
(<= 0 Transparency 90)
(setq lyr (tblobjname "LAYER" LayerName))
(not (setpropertyvalue lyr "Transparency" Transparency))
(not (entupd lyr))
)
)
(defun _loadlinetype (ltype / lt out)
(cond
((tblobjname "ltype" ltype) t)
((setq lt (vla-get-linetypes (vla-get-activedocument (vlax-get-acad-object))))
(setq out (vl-catch-all-apply
'vla-load
(list lt
ltype
(findfile
(if (= 0 (getvar 'measurement))
"acad.lin"
"acadiso.lin"
)
)
)
)
)
(not (vl-catch-all-error-p out))
)
)
) ;; defun _loadlinetype
;; Set the layer properties
(setq lay (vla-add (vla-get-layers (vla-get-activedocument (vlax-get-acad-object))) name)) ;; 1st arg
(if (listp color)
(progn
(setq tru (vla-get-truecolor lay))
(apply 'vla-setrgb (cons tru color))
(vla-put-truecolor lay tru)
)
(vla-put-color lay color) ;; 2nd arg
)
(vla-put-linetype lay
(if (_loadlinetype linetype)
linetype
"continuous"
)
) ;; 3rd arg
(vla-put-lineweight lay lineweight) ;; 4th arg
(_SetLayerTransparency name transparency) ;; 5th arg
(vla-put-Plottable lay plottable) ;; 6th arg
(vla-put-description lay description) ;; 7th arg
lay
) ;; _createOrUpdateLayer defun
(_createOrUpdateLayer "Test1" 22 "Dashed" aclnwtbylwdefault 65 :vlax-true "Test1 Description")
(_createOrUpdateLayer "Test2" '(100 150 200) "Continuous" acLnWt013 65 :vlax-true "Test2 Description")