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 ****************
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.
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)
FileOpenMode.OpenForReadAndWriteNoShare, True, "")
You may want to look at the attached snapshot of the error message.
Can you please try acquiring a lock on the current document or run the command in the document context by removing the "Session" flag ?
Access a broad range of knowledge to help get the most out of your products and services.
Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.
Upgrading to a 2015 product? Make sure to check these out 1st!