从辅助数据库中删除布局
有什么方法可以从数据库中删除布局吗?使用名为dictionary的布局而不是layoutManager?我一直在使用下面的代码,但它并没有删除布局本身...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
**** Hidden Message ***** 好的,我刚刚在这个位置找到了_Gile的答案https://forums.autodesk.com/t5/net/remove-layout/td-p/5824050?nobounce.我没有考虑过将工作数据库更改为外部绘图... 由于某种原因,删除布局似乎会修改其余布局中的视口...??
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
页:
[1]