View Single Post
 
Old 09-10-2015, 04:37 PM
Freedom20 Freedom20 is offline Windows 10 Office 2010 64bit
Novice
 
Join Date: Sep 2015
Posts: 4
Freedom20 is on a distinguished road
Default

Thank you for the reply. However, I was not able to get the code to run.

Quote:
Originally Posted by macropod View Post
Using early binding, your code might become:
Code:
Sub Convert_dxf()
Dim AcadApp As AutoCAD.Application
Dim AcadDoc As AutoCAD.Document
Dim SS As AutoCAD.AcadSelectionSet
Set AcadApp = New AutoCAD.Application
With AcadApp
  .Visible = False
  Set AcadDoc = .Documents.Open("C:\drawing.dxf")
  With AcadDoc
    Set SS = .SelectionSets("SS")
    .Export "C:\drawing.wmf", "WMF", SS
    .Close SaveChanges:=False
  End With
  .Quit
End With
Set SS = Nothing: Set AcadDoc = Nothing: Set AcadApp = Nothing
End Sub
The code was getting hung up on the following line
Code:
Set AcadDoc = .Documents.Open("C:\drawing.dxf")


I found another solution. I placed the export code into AutoCAD and called it from Word.

For anyone who might need it, the solution I found is below.

Code in Word:
Code:
Sub Convert_dxf()
Dim AcadApp As Object
        
    On Error Resume Next
    Set AcadApp = GetObject(, "AutoCAD.Application")
    If Err.Number <> 0 Then
        Set AcadApp = CreateObject("AutoCAD.Application")
    End If
    AcadApp.Visible = False
        
    AcadApp.Documents.Open ("C:\drawing.dxf")
    AcadApp.RunMacro "Convert_drawing"
     AcadApp.ActiveDocument.Close savechanges:=False
    If AcadApp.Documents.Count = 1 Then
        AcadApp.ActiveDocument.Close savechanges:=False
        AcadApp.Quit
    End If
    Set AcadApp = Nothing
End Sub
The code in AutoCAD:
Code:
Sub Convert_drawing()
Dim SS As AcadSelectionSet
 
Set SS = ActiveDocument.SelectionSets.Add("SSet")
SS.Select acSelectionSetAll
ActiveDocument.Export "C:\drawing", "WMF", SS
Set SS = Nothing
 
End Sub
Note that if AutoCAD is left running, you might get an error stating that the selectionset already exists.
Reply With Quote