请教各位高手一个简单的问题
我想对某个图层中的对象进行操作运行for each ent in thisdrawing.layer(i)时提示出错 对象不对
请问我该如何更改呢?
谢先 图层中是没有对象的。
你必须使用带过滤器的选择集来选择指定图层下的对象,然后再对这些对象进行操作。 这是一个转换对象图层的程序,你看看吧:
Sub ChgLayer()
On Error Resume Next
Dim Ent As AcadEntity
Dim Pnt As Variant
ThisDrawing.Utility.GetEntity Ent, Pnt, vbCrLf & "选择所要改变图层的对象:"
Dim LayName As String
LayName = Ent.Layer
ThisDrawing.Utility.Prompt vbCrLf & "你选择转换的图层名称是" & LayName
Dim NewLayerName As String
Dim lay As AcadLayer
Do
NewLayerName = ThisDrawing.Utility.GetString(0, vbCrLf & "输入要转换到的图层名:")
Set lay = ThisDrawing.Layers(NewLayerName)
If Err Then
Err.Clear
ThisDrawing.Utility.Prompt vbCrLf & "该名称的图层不存在,请重新输入"
Else
Exit Do
End If
Loop
Dim FType(0) As Integer
Dim FData(0) As Variant
FType(0) = 8
FData(0) = LayName
Dim ss As AcadSelectionSet
Set ss = CreatSSet
ss.Select acSelectionSetAll, , , FType, FData
Dim i As Integer
For i = 0 To ss.Count - 1
ss(i).Layer = NewLayerName
Next i
End Sub
Function CreatSSet()
Dim ss As AcadSelectionSet
On Error Resume Next
Set ss = ThisDrawing.SelectionSets.Add("mccad")
If Err Then
Err.Clear
Set ss = ThisDrawing.SelectionSets("mccad")
ss.Clear
End If
Set CreatSSet = ss
End Function
谢谢斑竹
页:
[1]