- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Having trouble with a bit of printing code if the community would be kind enought to offer some help. I have looked at ViewPrinter sample but A: struggle to read that much C# and B: think its more about replicating the revit UI for each print.
What I'm doing is looking through a list of sheets and exporting to DWG, DWF and hopefully printing to PDF. I want to determine the sheet size at runtime and adjust the print settings to suite. This works well for the DWF method.
So here is a snippet. There is a simplified UI (a single page in a wizard) where some print settings are selected. Then for each sheet I call this method. Most things work. My chosen printer is used and the sheet is printed to the correct place but my print settings are not saving so the PDF is generated using the selected driver but with the wrong page size, colour settings, etc
Private Sub ExportPDF(ByVal ExportFileName As String, ByRef thisdoc As Document, ByRef sheet As ViewSheet)
Try
'configure filename path for final PDF save location
Dim sFullPath As String = Path.Combine(sbIssuePath.ToString, ExportFileName)
'get the sizes with from the titleblock instances
'method called to get these values from sheet
pMgr = thisdoc.PrintManager
pMgr.PrintRange = Autodesk.Revit.DB.PrintRange.Select
pMgr.SelectNewPrintDriver(PDFPRINTERNAME)
pMgr.PrintToFile = True
pMgr.PrintToFileName = sFullPath
pSetup = pMgr.PrintSetup
pParams = pSetup.CurrentPrintSetting.PrintParameters
pParams.ZoomType = ZoomType.Zoom
pParams.Zoom = 100
If Width > Height Then
pParams.PageOrientation = PageOrientationType.Landscape
Else
pParams.PageOrientation = PageOrientationType.Portrait
End If
pParams.PaperPlacement = PaperPlacementType.Center
pParams.ColorDepth = CType(Me.cboPDFColors.SelectedItem, ColorDepthType)
pParams.RasterQuality = CType(Me.cboPDFRasterQuality.SelectedItem, RasterQualityType)
pParams.HiddenLineViews = HiddenLineViewsType.VectorProcessing
pParams.ViewLinksinBlue = Me.chkPDFViewLinksInBlue.CheckState
pParams.HideReforWorkPlanes = Me.chkPDFHideRefWorkPlanes.CheckState
pParams.HideUnreferencedViewTags = Me.chkPDFHideUnreferenceViewTags.CheckState
pParams.HideCropBoundaries = Me.chkPDFHideCropBoundaries.CheckState
pParams.HideScopeBoxes = Me.chkPDFHideScopeBox.CheckState
pParams.ReplaceHalftoneWithThinLines = Me.chkPDFHalftone.CheckState
pParams.MaskCoincidentLines = Me.chkPDFCoincidentLines.CheckState
Dim PaperSize As String = GetPapersize(Width, Height)
For Each ps As Autodesk.Revit.DB.PaperSize In pMgr.PaperSizes
If ps.Name.Equals(PaperSize) Then
pParams.PaperSize = ps
Exit For
End If
Next
pMgr.Apply()
'Try
' oPM.ViewSheetSetting.SaveAs("transmittal")
'Catch ex As Exception
' 'do nothing and move on
'End Try
Try
pSetup.SaveAs("transmittal")
'oPM.PrintSetup.SaveAs("transmittal")
Catch ex As Exception
'do nothing and move on
End Try
pMgr.SubmitPrint(sheet)
'Try
' oPM.ViewSheetSetting.Delete()
'Catch ex As Exception
' 'do nothing and move on
'End Try
'Try
' oPM.PrintSetup.Delete()
'Catch ex As Exception
' 'do nothing and move on
'End Try
Catch ex As Exception
TaskDialog.Show("There has been an error generating the PDF file " & ExportFileName & "." & Environment.NewLine & "Please manually print the PDF using the Revit print command." & Environment.NewLine & ex.ToString, MsgBoxStyle.Information, "Error creating PDF")
Finally
End Try
End Sub
Solved! Go to Solution.