this is the code ... i hope it will help u
Code:
Private Sub button1_Click()
Dim acadDoc As AutoCAD.AcadDocument
Set acadDoc = AutoCAD.Documents.Open("C:\test.dwg")
Dim lays As AcadLayers
Dim layerObj As AcadLayer
Dim lay As AcadLayer
Dim strLayerName As String
On Error Resume Next
'Set lays = ThisDrawing.Layers
Set lays = acadDoc.Layers
'set the layer to default
ThisDrawing.ActiveLayer = lays.Item(0)
'go trough all the layers
For Each lay In lays
Set layerObj = acadDoc.Layers(lay.Name)
'listbox1 is the list with the layer names that are initialy
'listbox2 is the list with the layer names that are becoming
'ex: listbox1 contains (103, 150, 160)
' and listbox2 contains (a, b, c) 103 is becoming a .. 150 is becoming b and 160 is becoming c
'if u have ..listbox1(103, 150, 160) and listbox2 (a, a, c)
'then a error..ocurs..and is captured.. then..takes all the elements on
'then layer 150 and copy them to the layer a ..and then deletes the 150
'and so on...
'the listbox u can fill them from a txt file ...
For i = 0 To ListBox1.ListCount - 1
If layerObj.Name = ListBox1.List(i) Then
layerObj.Name = ListBox2.List(i)
If Err.Number = "-2145386405" Then
'Testselectionsetfilter is the sub that copies the information from one layer to the other
Testselectionsetfilter ListBox1.List(i), ListBox2.List(i)
acadDoc.Layers.Item(ListBox1.List(i)).Delete
End If
End If
Next i
Next lay
Private Sub Testselectionsetfilter(layer_init As String, layer_dest As String)
Dim objss As AcadSelectionSet
Dim intcodes(0) As Integer
Dim varcodevalues(0) As Variant
Dim strname As String
On Error GoTo done
strname = layer_init
If "" = strname Then Exit Sub
''create new selectionset
Set objss = ThisDrawing.SelectionSets.Add("Testselectionsetfilter")
''set the code for layer
intcodes(0) = 8
''set the value specified by user
varcodevalues(0) = strname
''filter the objects
objss.Select acSelectionSetAll, , , intcodes, varcodevalues
''highlight the selected entities
objss.Highlight True
For i = 0 To objss.Count
objss.Item(i).layer = layer_dest
Next i
done:
'' if the selection was created , delete it
If Not objss Is Nothing Then
objss.Delete
End If
End Sub
End sub
Bookmarks