TheSwamp
Code Red => .NET => Topic started by: djee on May 10, 2017, 12:39:25 PM
-
Is there any way to delete layouts from a sidedatabase? Using the Layout named dictionary instead of the layoutManager? I've been using the below code but it's not deleting the layout itself...
Public Shared Sub DeleteTab(ByVal MyFileCollection As MyFiles)
For Each AutoCadFile In MyFileCollection
Using ExistDatabase As New Database(False, True)
ExistDatabase.ReadDwgFile(AutoCadFile.SelectedFilePath, FileOpenMode.OpenForReadAndAllShare, False, Nothing)
ExistDatabase.CloseInput(True)
Using AcTrans As Transaction = ExistDatabase.TransactionManager.StartTransaction
Dim MyLayouts As DBDictionary = AcTrans.GetObject(ExistDatabase.LayoutDictionaryId, OpenMode.ForRead)
' Step through each named layout and Model
For Each item As DBDictionaryEntry In MyLayouts
If item.Key = "English_Metric" Then
Dim MyItem As DBObject = AcTrans.GetObject(item.Value, OpenMode.ForWrite)
MyItem.Erase(True)
End If
Next
ExistDatabase.SaveAs(AutoCadFile.SelectedFilePath, DwgVersion.Current)
AcTrans.Commit()
End Using
End Using
Next
End Sub
-
Ok, I've just found this answer from _Gile at this location https://forums.autodesk.com/t5/net/remove-layout/td-p/5824050?nobounce (https://forums.autodesk.com/t5/net/remove-layout/td-p/5824050?nobounce). I did not though about changing the working database to the external drawing...
-
For some reason, deleting layouts seems to modify the viewports in my remaining layouts...??
Public Shared Sub DeleteTab(ByVal MyFileCollection As MyFiles, ByVal LayoutName As String)
Dim currentDatabase As Database = HostApplicationServices.WorkingDatabase
For Each AutoCadFile In MyFileCollection
Try
Using targetDatabase As New Database(False, True)
targetDatabase.ReadDwgFile(AutoCadFile.SelectedFilePath, System.IO.FileShare.ReadWrite, False, Nothing)
HostApplicationServices.WorkingDatabase = targetDatabase
Using tr As Transaction = targetDatabase.TransactionManager.StartTransaction
Dim lm As LayoutManager = LayoutManager.Current
lm.DeleteLayout(LayoutName)
targetDatabase.SaveAs(AutoCadFile.SelectedFilePath, DwgVersion.Current)
targetDatabase.CloseInput(True)
End Using
End Using
Finally
HostApplicationServices.WorkingDatabase = currentDatabase
End Try
Next
End Sub