Message 1 of 14
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am trying to copy 3 layers from one drawing file to another drawing file. I DON'T want to open the drawing files, as this process will be applicable to at least 50 drawing files. I am using VBA. So far, I have opened the UPDATED file and copied 3 layers. When trying to use "copyObjects" to copy these 3 layers into a non-updated file, code is executing without any error, but the drawing file it NOT getting updated.
Below is my piece of code-
--Moderator edit. Changed code format to VB.
Dim newPath As String 'without layer and updated
Dim oldPath As String 'to update
Private Sub CommandButton1_Click()
UserForm1.Hide
CopyLayers newPath, oldPath
End Sub
Public Sub CopyLayers(newFile As String, oldFile As String)
Dim oDoc As New AxDbDocument
Dim nDoc As New AxDbDocument
Dim oDbx As Object 'To update
Dim nDbx As Object 'Updated
Dim olayer As AcadLayer
Dim i As Integer
Set nDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
nDbx.Open newFile
'Copying the Layers from Updated File
Dim copyLay() As Object
For Each olayer In nDbx.Layers
If UCase(olayer.Name) = "DATE1" Or UCase(olayer.Name) = "DATE2" Or UCase(olayer.Name) = "DATE3" Then
ReDim Preserve copyLay(i)
Set copyLay(i) = olayer
i = i + 1
End If
Next
MsgBox i
Dim idPairs As Variant
Dim copyObj As Variant
'Opening the File to copy the Layer i.e Opening the File To UPDATE
Set oDbx = ThisDrawing.Application.GetInterfaceObject("ObjectDBX.AxDbDocument.18")
oDbx.Open FileName:=oldFile
'Copying the Layers to oDbx File
nDbx.CopyObjects copyLay, ThisDrawing.Database.ModelSpace
'oDbx.SaveAs savPath
Set oDbx = Nothing
Set nDbx = Nothing
End Sub
Private Sub UserForm_Activate()
Dim dwgName As String
dwgName = "mech_1"
oldPath = "E:\ACE\Testing\09Dec\" & dwgName & ".dwg"
newPath = "E:\ACE\Testing\30Jan\" & dwgName & ".dwg"
End Sub
What's wrong with this piece of code?
Regards
Solved! Go to Solution.