Open DWG save as DXF with API VB.NET or C#

florian_wenzel
Advocate
Advocate

Open DWG save as DXF with API VB.NET or C#

florian_wenzel
Advocate
Advocate

Hi,

 

i need some Help.

I try to Open Each .DWG File in a Folder(Directory)

 

 

 

Save Document as .DXF

 

 

Thanks for any Suggestion

0 Likes
Reply
Accepted solutions (1)
1,359 Views
3 Replies
Replies (3)

florian_wenzel
Advocate
Advocate

Hi,

 

Why i get Error:

 

 

 

 

    <CommandMethod("OpenDrawingDWG", CommandFlags.Session)>
    Public Sub OpenDrawingDWG()
        Dim strFileName As String = "C:\AutoCad_API\CAD\20221024\Folder_A\Test_ver2018_b.dwg"
        Dim strFileNameSave As String = "C:\AutoCad_API\CAD\20221024\Folder_A\Test_ver2018_b.dxf"


        Dim acDocMgr As DocumentCollection = Application.DocumentManager

        DocumentCollectionExtension.Open(acDocMgr, strFileName, False)

        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim strDWGName As String = acDoc.Name

        MsgBox("strFileNameSave = " & strFileNameSave)

        acDoc.Database.DxfOut(strFileNameSave, 16, DwgVersion.Current)



    End Sub

 

 

 

 

Error:

florian_wenzel_0-1666615132398.png

 

 

Second Code:

 

    <CommandMethod("OpenDrawingDWG", CommandFlags.Session)>
    Public Sub OpenDrawingDWG()
        Dim strFileName As String = "C:\AutoCad_API\CAD\20221024\Folder_A\Test_ver2018_b.dwg"
        Dim strFileNameSave As String = "C:\AutoCad_API\CAD\20221024\Folder_A\Test_ver2018_b.dxf"


        Dim acDocMgr As DocumentCollection = Application.DocumentManager

        DocumentCollectionExtension.Open(acDocMgr, strFileName, False)

        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument


        acDoc.Database.SaveAs(strFileNameSave, True, DwgVersion.AC1027, acDoc.Database.SecurityParameters)



    End Sub

 

 

Save File as DXF, but the File is Empty 

When i try to open the File, than i get Blackscreen and Text " Press Enter to go Forward" but the File is Empty 

 

 

Thanks for Any Suggestion! 

0 Likes

_gile
Mentor
Mentor
Accepted solution

Hi,

 

You should use a 'side database' (i.e. open the dwg in memory) instead of opening the dwg in the editor.

Here's an exemple:

        private static void SaveAsDxf(string dwgName)
        {
            using (var db = new Database(false, true))
            {
                db.ReadDwgFile(dwgName, FileOpenMode.OpenForReadAndAllShare, true, null);
                string dxfName = System.IO.Path.ChangeExtension(dwgName, "dxf");
                db.DxfOut(dxfName, 16, true);
            }
        }


Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

florian_wenzel
Advocate
Advocate

Hi,

Thanks for Solution

Thanks for Help

 

0 Likes