Robustly loop through sheets to generate DWF files...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've got an addin under development that assists with the drawing issue process. Essentially I load the sheets in the model to a listview where sheets can be selected for issue. Then the addin loops through each and performs some actions basad on options selected by the user.
So I want to process each sheet in turn as I output files (DWG or DWF) to an issue folder and want the filenames to be written in a format that also included the revision letter.
So I select all the sheets in the active document then loop through the listivews selected items. for each listviewitem i loop through the sheets collected and check if the drawing numbers match. This process seems to work just fine when debugging.
Dim sheets As New FilteredElementCollector(doc) sheets.OfClass(GetType(ViewSheet)) For Each oItem As ListViewItem In Me.lvwSheets.CheckedItems For Each sheet As ViewSheet In sheets If oItem.Text = sheet.SheetNumber Then Dim thisdoc As Document = uidoc.Document Dim views As ViewSet = New ViewSet views.Insert(sheet) Dim sbFile As New System.Text.StringBuilder sbFile.Append(doc.ProjectInformation.Number & " - ") sbFile.Append(sheet.SheetNumber & "_") sbFile.Append(sheet.Name & "_") sbFile.Append("rev" & sheet.Parameter(BuiltInParameter.SHEET_CURRENT_REVISION).AsString) trans = New Autodesk.Revit.DB.Transaction(doc, "Export Sheets") Using trans trans.Start() If Me.chkExportDWG.Checked = True Then ExportDWG(sbFile.ToString & ".dwg", views) If Me.chkExportDWF.Checked = True Then ExportDWF(sbFile.ToString & ".dwf", GetSheetsize(sheet, doc), thisdoc, views) If Me.chkPrint.Checked = True Then PrintSheet(sheet, thisdoc) trans.Commit() End Using
pb1.Value = pb1.Value + 1 pb1.Refresh() End If Next Next
What I've dound is that on live jobs the addin occasionally crashes. I don't think its the code above as it never crashes if I don't select any export formats. The addin simply records the drawings in the drawing issue database and completes neately. I occosionally (and seemingly randomly) get crashes with the export file. An example being how I'm generated a DWF for the given sheet.
Private Sub ExportDWF(ByVal ExportFileName As String, ByRef sheetsize As ExportPaperFormat, ByRef thisdoc As Document, ByRef views As ViewSet) Try ptManager = thisdoc.PrintManager Dim ptSetup As PrintSetup = ptManager.PrintSetup Dim ptParameters As PrintParameters = ptSetup.CurrentPrintSetting.PrintParameters If ptParameters.Zoom <> 100 Then ptParameters.ZoomType = ZoomType.Zoom ptParameters.Zoom = 100 End If Try ptManager.ViewSheetSetting.SaveAs("eproject") Catch ex As Exception End Try Try ptManager.PrintSetup.SaveAs("eproject") Catch ex As Exception End Try Dim DWFExpOpt As DWFExportOptions DWFExpOpt = New DWFExportOptions With DWFExpOpt .ImageFormat = DWFImageFormat.Lossless If Me.rdoDWFDefault.Checked = True Then .ImageQuality = DWFImageQuality.Default If Me.rdoDWFLow.Checked = True Then .ImageQuality = DWFImageQuality.Low If Me.rdoDWFMedium.Checked = True Then .ImageQuality = DWFImageQuality.Medium If Me.rdoDWFHigh.Checked = True Then .ImageQuality = DWFImageQuality.High .ExportingAreas = chkDWFExportAreas.Checked .ExportObjectData = chkDWFObjectData.Checked .PaperFormat = sheetsize End With doc.Export(sbIssuePath.ToString, ExportFileName, views, DWFExpOpt) Try ptManager.ViewSheetSetting.Delete() Catch ex As Exception End Try Try ptManager.PrintSetup.Delete() Catch ex As Exception End Try Catch ex As Exception TaskDialog.Show("There has been an error processing sheet export to DWF for " & ExportFileName & Environment.NewLine & ex.ToString, MsgBoxStyle.Information, "Error processing sheets") End Try End Sub
The crash never occurs when I step through on the debugger so I'm wondering if its connected to the speed the addin is running and the sheet not completing a refresh on the screen????
Any ideas would be most welcome...