这是一个转换对象图层的程序,你看看吧:
- 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
|