.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AutoCAD crashes after completing side Database Operation

4 REPLIES 4
Reply
Message 1 of 5
eyalcn
709 Views, 4 Replies

AutoCAD crashes after completing side Database Operation

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

 

 

 

 

 

4 REPLIES 4
Message 2 of 5
Balaji_Ram
in reply to: eyalcn

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

Message 3 of 5
eyalcn
in reply to: Balaji_Ram

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.

 

 

Message 4 of 5
Balaji_Ram
in reply to: eyalcn

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

Message 5 of 5
CADbloke
in reply to: Balaji_Ram

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost