.NET

Reply
New Member
eyalcn
Posts: 2
Registered: ‎04-17-2014
Message 1 of 4 (173 Views)

AutoCAD crashes after completing side Database Operation

173 Views, 3 Replies
04-23-2014 02:21 PM

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

 

 

 

 

 

ADN Support Specialist
Balaji_Ram
Posts: 666
Registered: ‎03-21-2011
Message 2 of 4 (79 Views)

Re: AutoCAD crashes after completing side Database Operation

05-07-2014 02:57 AM 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

New Member
eyalcn
Posts: 2
Registered: ‎04-17-2014
Message 3 of 4 (67 Views)

Re: AutoCAD crashes after completing side Database Operation

05-07-2014 10:10 AM 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.

 

 

ADN Support Specialist
Balaji_Ram
Posts: 666
Registered: ‎03-21-2011
Message 4 of 4 (56 Views)

Re: AutoCAD crashes after completing side Database Operation

05-07-2014 10:17 PM 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community