That may get the color of the object, but not of its Layer. The object's color can be an override, but if it is getting its color from the Layer, it will be ByLayer, and the routine returns 256 for that. Try this minimal adjustment to get the color of the Layer it's drawn on:
(DEFUN C:CN()
(SETQ
ENT (CAR (ENTSEL "\n Select object:"))
obj (vlax-ename->vla-object ENT)
NO (itoa (cdr (assoc 62 (tblsearch "layer" (VLA-GET-LAYER OBJ)))))
)
(ALERT NO)
(PRINT NO)
)
I changed the (RTOS) in your original to (itoa) above for the sake of those who use Architectural Imperial Units, because with (rtos), it is converted to feet and inches [256 wouldn't occur as a Layer's color, but, for example, 255 comes across as 21'-3"]. That could be avoided in another way, by keeping (rtos) but adding mode and precision arguments:
....
NO (RTOS (cdr (assoc 62 (tblsearch "layer" (VLA-GET-LAYER OBJ)))) 2 0)
....
If you prefer, it could be made to report the override color of the object if its color is not ByLayer, or the color of the Layer if it is ByLayer. It could also be made to use words ["Red" etc.] for color numbers from 1 to 7, or from 0 to 7 if you want to account for "ByBlock" as a color assignment.
Kent Cooper, AIA