yltc 发表于 2008-7-14 14:27:00

VB中设置图层为当前图层及如何设置图层颜色。

VB中设置图层为当前图层及如何设置图层颜色。

nhy12345678 发表于 2008-7-14 22:37:00

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

yltc 发表于 2008-7-15 08:28:00

lay0 As AcadLayer 用户类型未定义是怎么回事?
页: [1]
查看完整版本: VB中设置图层为当前图层及如何设置图层颜色。