<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Saving an external/side Database in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019157#M47890</link>
    <description>&lt;P&gt;Hi Philippe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your Reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually My question is not about accessing side database via VBA. Instead...&lt;/P&gt;&lt;P&gt;I want to run a VBA macro [VBARUN "TEST.DVB"] inside a database which is read using ReadDwgFile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check below...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Sub batchProcess()
            ' get all DWG files from a specific folder

            Dim directory As New System.IO.DirectoryInfo("C:\TEMP")
            Dim files As System.IO.FileInfo() = _
                directory.GetFiles("*.dwg")

            For Each file As System.IO.FileInfo In files
                ' generate a temp file location
                Dim tempFileName As String = _
                  System.IO.Path.GetTempFileName()


                Using db As New Database(False, True)
                    
                    db.ReadDwgFile(file.FullName, FileOpenMode.OpenForReadAndAllShare, False, Nothing)

                    Using trans As Transaction = _
                     db.TransactionManager.StartTransaction()

                        'Run a VBA MACRO / SendCommad                     
                                            
                        ' commit changes
                        trans.Commit()
                    End Using


                End Using ' dispose the database

            Next


        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Feb 2016 10:15:49 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-02-02T10:15:49Z</dc:date>
    <item>
      <title>Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/4397033#M47886</link>
      <description>&lt;P&gt;&lt;FONT size="2"&gt;Hey all,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I've been coming up with issues writing changes to an external database (one that is lazy-loaded via &lt;STRONG&gt;Database.readDwgFile()&lt;/STRONG&gt;).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;While constructing this post I decided to do a couple more tests to make sure that my setup was not working.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;What I found is that it was working!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;Regardless, I would still like to add to the .NET forums by creating some documentation in case someone else needs it.&lt;/FONT&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;When working with an external database or side database that is NOT loaded into the AutoCAD editor, I needed to save changes that were made. &amp;nbsp;Normally, I'd expect that after a transaction is commited, then the changes would reflect... &amp;nbsp;this is NOT what happened.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;So I've added this line of code in order to save the database after all changes were committed:&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;database.SaveAs(drawing.FullName, true, DwgVersion.Current, database.SecurityParameters);&lt;/PRE&gt;&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;This method works as described in ObjectARX - Managed Class Reference documentation:&lt;/FONT&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;STRONG&gt;&lt;EM&gt;Database.SaveAs Method&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;P&gt;Runs the save process on the database and writes the drawing information out to fileName. The fileName argument is taken as is. If no file extension is present, .dwg is not appended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the database executing the SaveAs() function is not the current database in the AutoCAD editor, then the thumbnail preview image is not saved to fileName.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To specify security parameters, set security that conveys your preferences.If the security is not properly initialized, the method fails. See SecurityParameters for more information on initializing this struct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If bBakAndRename is false, then no .bak file is created, a full save is always done, and if the Database being saved is the main database for a document in AutoCAD, then the document's filename will NOT change to the saved name.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;FONT size="2"&gt;Now, when I open the drawing manually, I notice the changes made by the .NET assembly.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;I also want to put up here, since it is partially relevant, that I am NOT required to&amp;nbsp;&lt;STRONG&gt;Commit the Transaction&amp;nbsp;&lt;/STRONG&gt;for changes to take effect. &amp;nbsp;This appears to be the default behavior upon the closing of a transaction. &amp;nbsp;However, if the transaction is aborted, then no changes are made.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Sep 2013 13:09:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/4397033#M47886</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-09-04T13:09:58Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/4416915#M47887</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a C# sample that illustrates how to work with ReadDwgFile: it will prompt the user to select an entity in the current drawing, then load a side database and clone the object into it. I would recommend you follow that approach when working on a side database you want to modify.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;[CommandMethod("wblockclone", CommandFlags.Session)]
static public void wblockclone()
{
    Document doc = Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    Editor ed = doc.Editor;

    PromptEntityOptions peo = new PromptEntityOptions("\nSelect entity to copy: ");

    PromptEntityResult per = ed.GetEntity(peo);

    if (per.Status != PromptStatus.OK) 
        return;

    using(DocumentLock doclock = doc.LockDocument())
    {
        ObjectIdCollection ObjectcIds = new ObjectIdCollection();
        ObjectcIds.Add(per.ObjectId);

        Database destDb = new Database(false, true);
        destDb.ReadDwgFile("c:\\Temp\\DestDrawing.dwg", System.IO.FileShare.ReadWrite, true, "");

        using (Transaction Tx = destDb.TransactionManager.StartTransaction())
        {
            BlockTable bt = Tx.GetObject(
                destDb.BlockTableId, 
                OpenMode.ForRead) as BlockTable;

            BlockTableRecord btr = Tx.GetObject(
                bt[BlockTableRecord.ModelSpace], 
                OpenMode.ForWrite) as BlockTableRecord;

            IdMapping oIdMap = new IdMapping();

            destDb.WblockCloneObjects(
                ObjectcIds, 
                btr.ObjectId, 
                oIdMap, 
                DuplicateRecordCloning.Ignore, 
                false);

            Tx.Commit();
        }

        destDb.SaveAs(destDb.Filename, DwgVersion.Current);
    }
}&lt;/PRE&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Philippe.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2013 08:56:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/4416915#M47887</guid>
      <dc:creator>philippe.leefsma</dc:creator>
      <dc:date>2013-09-11T08:56:45Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6018774#M47888</link>
      <description>&lt;P&gt;Hi Philippe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to execute a VBA routine inside a side database ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;~Ranjan&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 02:52:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6018774#M47888</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-02T02:52:12Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019143#M47889</link>
      <description>&lt;P&gt;You can use AxDbDocument to access side DB from VBA, here is a sample:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Private Sub UpdateDWGProps()
    
    Dim oApp As AcadApplication
    Set oApp = GetObject(, "AutoCAD.Application")
    
    'This is what we need to look into a drawing without opening it in the GUI
    Dim axDoc As Variant 'AxDbDocument
    Set axDoc = oApp.GetInterfaceObject("ObjectDBX.AxDbDocument.19")
    axDoc.Open ("C:\Temp\Drawing1.dwg")
    
    Dim oDwgProps As AcadSummaryInfo
    Set oDwgProps = ThisDrawing.SummaryInfo
    
    Debug.Print "-------------- Drawing Properties --------------"
    Debug.Print "  Title = " &amp;amp; oDwgProps.Title
    Debug.Print "  Subject = " &amp;amp; oDwgProps.Subject
    Debug.Print "  Author = " &amp;amp; oDwgProps.Author
    Debug.Print "  Keywords = " &amp;amp; oDwgProps.Keywords
    Debug.Print "  Comments = " &amp;amp; oDwgProps.Comments
    Debug.Print "  HyperlinkBase = " &amp;amp; oDwgProps.HyperlinkBase
    Debug.Print "  LastSavedBy = " &amp;amp; oDwgProps.LastSavedBy
    Debug.Print "  RevisionNumber = " &amp;amp; oDwgProps.RevisionNumber
          
    Dim index As Long
    Dim key As String
    Dim value As String
    
    For index = 0 To oDwgProps.NumCustomInfo - 1
    
        oDwgProps.GetCustomByIndex index, key, value
        
        'Debug.Print "  Custom prop(" &amp;amp; str(index) &amp;amp; ") = " &amp;amp; value
        
        'Set a new value
        oDwgProps.SetCustomByIndex index, key, "NewValue"
    
    Next
    
    oDwgProps.AddCustomInfo "Developer", "ADN"
    
    axDoc.SaveAs (axDoc.name)

End Sub
&lt;/PRE&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;Philippe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:07:27 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019143#M47889</guid>
      <dc:creator>philippe.leefsma</dc:creator>
      <dc:date>2016-02-02T10:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019157#M47890</link>
      <description>&lt;P&gt;Hi Philippe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your Reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually My question is not about accessing side database via VBA. Instead...&lt;/P&gt;&lt;P&gt;I want to run a VBA macro [VBARUN "TEST.DVB"] inside a database which is read using ReadDwgFile&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check below...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; Public Sub batchProcess()
            ' get all DWG files from a specific folder

            Dim directory As New System.IO.DirectoryInfo("C:\TEMP")
            Dim files As System.IO.FileInfo() = _
                directory.GetFiles("*.dwg")

            For Each file As System.IO.FileInfo In files
                ' generate a temp file location
                Dim tempFileName As String = _
                  System.IO.Path.GetTempFileName()


                Using db As New Database(False, True)
                    
                    db.ReadDwgFile(file.FullName, FileOpenMode.OpenForReadAndAllShare, False, Nothing)

                    Using trans As Transaction = _
                     db.TransactionManager.StartTransaction()

                        'Run a VBA MACRO / SendCommad                     
                                            
                        ' commit changes
                        trans.Commit()
                    End Using


                End Using ' dispose the database

            Next


        End Sub&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:15:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019157#M47890</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-02T10:15:49Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019187#M47891</link>
      <description>&lt;P&gt;I doubt it's possible, a command needs the ditor to be executed, which is only available on the currently open drawing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By trying to mix .Net and VBA code, you are going toward some convoluted workflow, a better approach would be to migrate your VBA routine to .Net and perform all operation from there. There is no feature that VBA has which cannot be achieved from the .Net API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that helps,&lt;/P&gt;
&lt;P&gt;Philippe.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:31:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019187#M47891</guid>
      <dc:creator>philippe.leefsma</dc:creator>
      <dc:date>2016-02-02T10:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019199#M47892</link>
      <description>&lt;P&gt;Okay! Understood.&lt;/P&gt;&lt;P&gt;I know i must convert the vba to .net.&lt;/P&gt;&lt;P&gt;I am thinking of a shortcut now , i.e. convert the vba code to .net but use the COM interop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example : How can&amp;nbsp;I use the below as is with .net&amp;nbsp;code pasted above&amp;nbsp;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Private Function GetLeaderCoord() As Variant
    Dim strString As String
    Dim obj As AcadBlock
    Dim obj2 As AcadEntity
    For Each obj In ThisDrawing.Blocks
                          For Each obj2 In obj
                If obj2.ObjectName = "AcDbLeader" Then
                    Dim x As AcadLeader
                    Set x = obj2
                    Dim y
                    GetLeaderCoord = x.Coordinates
                    Exit Function
                End If
                Next obj2
                      Next obj
        End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 10:42:33 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019199#M47892</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-02T10:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019228#M47893</link>
      <description>&lt;P&gt;You may take a look at our VBA to .Net migration guide:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://through-the-interface.typepad.com/through_the_interface/2010/02/updated-devtv-autocad-vba-to-vbnet-migration-basics.html" target="_self"&gt;http://through-the-interface.typepad.com/through_the_interface/2010/02/updated-devtv-autocad-vba-to-vbnet-migration-basics.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 11:04:14 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019228#M47893</guid>
      <dc:creator>philippe.leefsma</dc:creator>
      <dc:date>2016-02-02T11:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: Saving an external/side Database</title>
      <link>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019248#M47894</link>
      <description>&lt;P&gt;Okay&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2016 11:15:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/saving-an-external-side-database/m-p/6019248#M47894</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-02-02T11:15:03Z</dc:date>
    </item>
  </channel>
</rss>

