AutoCAD crashes after completing side Database Operation

AutoCAD crashes after completing side Database Operation

Anonymous
Not applicable
1,567 Views
4 Replies
Message 1 of 5

AutoCAD crashes after completing side Database Operation

Anonymous
Not applicable

The app I'm writing will eventually do some batch operation on multiple user-selected drawings

(Set DB.PSLTSCALE=1 for all Layouts in LayoutManager.Current), without opening those drawings.

For LayoutManager.Current to be available, WorkingDatabase is set to the selected database,

and being reset to the original database after the side-database operation completes.

 

All of this should work while the current Document is opened and waiting for the process to complete,

and return to regular user operation at the end.

But for some reason, after the DB.SaveAs is completed, the application crashes.

I ahve no clue whether the problem is in the file to be processed or in the code.

 

Following is a simplified code, in which the attached drawing's Database is Opened by the program for processing,

then being SavedAs, then the crash...

Any help will be kindly appreciated.

 

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Windows

Public Class TestClass
    '<CommandMethod("TestPS1M")> _     ' This has also been tested, no success...
    <CommandMethod("TestPS1M", CommandFlags.Session)> _
    Public Sub TestPS1M()
        Dim curDB As Database = HostApplicationServices.WorkingDatabase
        Dim myFilename As String = "c:\DatabaseToProcess.dwg" 'This is the attached drawing

        Using myDB As New Database(False, True)
            myDB.ReadDwgFile(myFilename,
                             FileOpenMode.OpenForReadAndWriteNoShare, True, "")
            HostApplicationServices.WorkingDatabase = myDB

            Dim curLM As LayoutManager = LayoutManager.Current
            ' Saving original active layout name
            Dim curLayoutName As String = curLM.CurrentLayout
            Using dictionaryTrans As Transaction = myDB.TransactionManager.StartTransaction
                Dim myLayoutDict As DBDictionary =
                    dictionaryTrans.GetObject(myDB.LayoutDictionaryId, OpenMode.ForRead)
                ' Iterating Layouts setting PSLTSCALE=1
                For Each myEntry As DBDictionaryEntry In myLayoutDict
                    Using layoutTrans As Transaction = myDB.TransactionManager.StartTransaction
                        curLM.CurrentLayout = myEntry.Key
                        myDB.Psltscale = 1
                        layoutTrans.Commit()
                    End Using
                Next
                ' Resetting the original active layout
                curLM.CurrentLayout = curLayoutName
                dictionaryTrans.Commit()
            End Using
            HostApplicationServices.WorkingDatabase = curDB

            myDB.SaveAs(myFilename, True, DwgVersion.Current, myDB.SecurityParameters)
        End Using

        MsgBox("Not crashed yet...")
    End Sub ' program crashes here     ****************

End Class

 

 

 

 

 

0 Likes
1,568 Views
4 Replies
Replies (4)
Message 2 of 5

Balaji_Ram
Alumni
Alumni

Sorry for the delay.

 

Can you please try opening the database as "Using myDB As New Database(False, False)"

 

This will avoid the database from being associated with the current document.

 

Regards,

Balaji



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for your reply, Balaji_Ram!

 

I have just tried "Using myDB As New Database(False, False)" as you suggested,

but got an "eNoInputFiler" error right on the next line :

 

Using myDB As New Database(False, False)
myDB.ReadDwgFile(myFilename,
FileOpenMode.OpenForReadAndWriteNoShare, True, "")

 

You may want to look at the attached snapshot of the error message.

 

Thanks again.

 

 

0 Likes
Message 4 of 5

Balaji_Ram
Alumni
Alumni

Hello,

 

Can you please try acquiring a lock on the current document or run the command in the document context by removing the "Session" flag ?

 

Regards,

Balaji

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

CADbloke
Advocate
Advocate

should that be 

Using myDB As New Database(False, True) 

as per http://adndevblog.typepad.com/autocad/2012/07/using-readdwgfile-with-net-attachxref-or-objectarx-acd...

 

That blog post solved an annoying crash for me which was similar to this.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
0 Likes