老大,为什么我以下的代码会提示”未找到主键"?
为什么我以下的代码会提示”未找到主键"?也没有创建新层环境:ACAD2004
Sub aaa()
Dim a As AcadText
Dim p As Variant
p = ThisDrawing.Utility.GetPoint(, "pack a point")
Set a = ThisDrawing.ModelSpace.AddText("新年好", p, 1)
a.Layer = CreateLayer("123")
ThisDrawing.Regen acActiveViewport
End Sub
Public Function CreateLayer(ssLayerName As String) As AcadLayer
Set CreateLayer = ThisDrawing.Layers(ssLayerName)
If Err Then
Err.Clear
Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
End If
End Function 没有添加错误转向语句,怎么能够处理错误。
Public Function CreateLayer(ssLayerName As String) As AcadLayer
on error resume next
Set CreateLayer = ThisDrawing.Layers(ssLayerName)
If Err Then
Err.Clear
Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
End If
End Function
我重写了更改图层的函数,问题得以解决!
Sub aaa()
Dim a As AcadText
Dim p As Variant
p = ThisDrawing.Utility.GetPoint(, "pack a point")
Set a = ThisDrawing.ModelSpace.AddText("新年好", p, 1)
a.Layer = CreateLayer("456").Name
ThisDrawing.Regen acActiveViewport
End Sub
Public Function CreateLayer(ssLayerName As String) As AcadLayer
Dim i As Integer
For i = 0 To ThisDrawing.Layers.Count - 1
If ThisDrawing.Layers.Item(i).Name = ssLayerName Then
CreateLayer = ThisDrawing.Layers(ssLayerName)
Exit For
Else
Set CreateLayer = ThisDrawing.Layers.Add(ssLayerName)
Exit For
End If
Next i
End Function 明老大的函数更为简洁,佩服佩服.
------------------------------------------------
努力努力,再加把劲 简单明了,我编的程序更复杂
页:
[1]