
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am attempting to use VB .NET to loop through a set of DWG files and rename the first layout tab in each.
I started using the following code:
http://help.autodesk.com/view/ACD/2015/ENU/?guid=GUID-5FA86EF3-DEFD-4256-BB1C-56DAC32BD868
Using this, plus the AcSmSheetSetMgr I can loop through each DWG file in a sheet set without issue. I am then able to determine the first layout tab using the following code:
Dim sheet As AcSmSheet = item
acExDb = New Database(False, True)
acExDb.ReadDwgFile(sheet.GetLayout().GetFileName(), FileOpenMode.OpenForReadAndAllShare, True, "")
ed.WriteMessage("PROCESSING LAYOUT FOR SHEET: " + sheet.GetName().ToString() + " Filename: " + sheet.GetLayout().GetFileName() + vbCrLf)
Dim previousActiveDocument As Document = Application.DocumentManager.MdiActiveDocument
Dim layout As AcSmAcDbLayoutReference = sheet.GetLayout()
Dim sheetFileName As String = layout.GetFileName() 'the dwg
Dim dwgDoc As Document = Application.DocumentManager.Open(sheet.GetLayout().GetFileName())
Dim dwgDB As Database = dwgDoc.Database
Dim LayoutMgr As LayoutManager = LayoutManager.Current
Using dwgDoc.LockDocument()
Using acTrans As Transaction = dwgDB.TransactionManager.StartTransaction()
Dim lays As DBDictionary = acTrans.GetObject(dwgDB.LayoutDictionaryId, OpenMode.ForWrite) ' OpenMode.ForRead
dwgDoc.Editor.WriteMessage(vbCrLf & "Layouts:")
Dim isFirst As Boolean = True
For Each dbEntryItem As DBDictionaryEntry In lays
If Not dbEntryItem.Key = "Model" Then
If isFirst = True Then
LayoutMgr.RenameLayout(dbEntryItem.Key, sheet.GetName().ToString())
isFirst = False
End If
End If
Next
acTrans.Commit()
acTrans.Dispose()
End Using
End Using
dwgDB.Dispose()
'save it
dwgDoc.Database.SaveAs(sheetFileName, DwgVersion.Current)
'then close it
dwgDoc.CloseAndDiscard()
Application.DocumentManager.MdiActiveDocument = previousActiveDocument
Basically, using this code I can rename layout tabs, however this opens the DWG, then updates the layout tab, then saves/closes the DWG. I am trying to perform this function in a loop for up to several hundred drawings, and as such this runs incredibly slowly and isn't really an ideal solution. Is there a way to update the first layout tab without using the currently active document? It appears the RenameLayout function in the LayerManager requires the DWG in question to be open.
Thanks
Solved! Go to Solution.