Sub addlay(name As String, co As Long) Dim lay0 As AcadLayer '定义作为图层的变量 Dim lay1 As AcadLayer Dim findlay As Long findlay = 0 '寻找图层的结果的变量,0没有找到,1找到 For Each lay0 In ThisDrawing.Layers '在所有的图层中进行循环 If lay0.name = name Then '如果找到图层名 findlay = 1 '把变量改为1标志着图层已经找到 If Not lay0.LayerOn Then lay0.LayerOn = True '打开 ThisDrawing.ActiveLayer = lay0 '把当前图层设为已经存在的图层 Exit For '结束寻找 End If Next lay0 If findlay = 0 Then '没有找到图层 Set lay1 = ThisDrawing.Layers.Add(name) '增加一个名为“临时图层”的图层 lay1.color = co '图层设置为黄色 ThisDrawing.ActiveLayer = lay1 '将当前图层设置为新建图层 End If End Sub