To create layers in AutoCAD with Python, you can use the Add() method of the Layers collection of the current Document object.
The coding example below creates a new layer and sets its color to red:
import win32com.client acad = win32com.client.Dispatch("AutoCAD.Application") # create new layer and change its color doc = acad.ActiveDocument layers = doc.Layers new_layer = layers.Add("newlayer") new_layer.color = 1
In this example, the Add() method is used to create a new layer with the name “newlayer”. The layer is created via and added to the Layers collection of the AutoCAD document. The color property of the new layer is to 1 (= red color).