- 积分
- 2250
- 明经币
- 个
- 注册时间
- 2009-5-15
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
楼主 |
发表于 2011-3-25 07:56:11
|
显示全部楼层
- Private Shared Function MultiplePlotOrPreview(ByVal pe As PlotEngine, ByVal isPreview As Boolean, ByVal layoutSet As ObjectIdCollection, ByVal layoutNumIfPreview As Integer, ByVal filename As String) As PreviewEndPlotStatus
- Dim doc As Document = Application.DocumentManager.MdiActiveDocument
- Dim ed As Editor = doc.Editor
- Dim db As Database = doc.Database
- Dim ret As PreviewEndPlotStatus = PreviewEndPlotStatus.Cancel
- Dim layoutsToPlot As ObjectIdCollection
- If isPreview AndAlso layoutNumIfPreview >= 0 Then
- ' Preview is really pre-sheet, so we reduce the
- ' sheet collection to contain the one we want
- layoutsToPlot = New ObjectIdCollection()
- layoutsToPlot.Add(layoutSet(layoutNumIfPreview))
- Else
- ' If we're plotting we need all the sheets,
- ' so copy the ObjectIds across
- Dim ids As ObjectId() = New ObjectId(layoutSet.Count - 1) {}
- layoutSet.CopyTo(ids, 0)
- layoutsToPlot = New ObjectIdCollection(ids)
- End If
- Dim tr As Transaction = db.TransactionManager.StartTransaction()
- Using tr
- ' Create a Progress Dialog to provide info
- ' and allow thej user to cancel
- Dim ppd As New PlotProgressDialog(isPreview, layoutsToPlot.Count, True)
- Using ppd
- Dim numSheet As Integer = 1
- For Each btrId As ObjectId In layoutsToPlot
- Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord)
- Dim lo As Layout = DirectCast(tr.GetObject(btr.LayoutId, OpenMode.ForRead), Layout)
- ' We need a PlotSettings object
- ' based on the layout settings
- ' which we then customize
- Dim ps As New PlotSettings(lo.ModelType)
- ps.CopyFrom(lo)
- ' The PlotSettingsValidator helps
- ' create a valid PlotSettings object
- Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
- ' We'll plot the extents, centered and
- ' scaled to fit
- psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
- psv.SetUseStandardScale(ps, True)
- psv.SetStdScaleType(ps, StdScaleType.ScaleToFit)
- psv.SetPlotCentered(ps, True)
- ' We'll use the standard DWFx PC3, as
- ' this supports multiple sheets
- psv.SetPlotConfigurationName(ps, "DWFx ePlot (XPS Compatible).pc3", "ANSI_A_(8.50_x_11.00_Inches)")
- ' We need a PlotInfo object
- ' linked to the layout
- Dim pi As New PlotInfo()
- pi.Layout = btr.LayoutId
- ' Make the layout we're plotting current
- LayoutManager.Current.CurrentLayout = lo.LayoutName
- ' We need to link the PlotInfo to the
- ' PlotSettings and then validate it
- pi.OverrideSettings = ps
- Dim piv As New PlotInfoValidator()
- piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
- piv.Validate(pi)
- ' We set the sheet name per sheet
- ppd.PlotMsgString(PlotMessageIndex.SheetName) = (doc.Name.Substring(doc.Name.LastIndexOf("") + 1) & " - ") + lo.LayoutName
- If numSheet = 1 Then
- ' All other messages get set once
- ppd.PlotMsgString(PlotMessageIndex.DialogTitle) = "Custom Preview Progress"
- ppd.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = "Cancel Job"
- ppd.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "Cancel Sheet"
- ppd.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = "Sheet Set Progress"
- ppd.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = "Sheet Progress"
- ppd.LowerPlotProgressRange = 0
- ppd.UpperPlotProgressRange = 100
- ppd.PlotProgressPos = 0
- ' Let's start the plot/preview, at last
- ppd.OnBeginPlot()
- ppd.IsVisible = True
- pe.BeginPlot(ppd, Nothing)
- ' We'll be plotting a single document
- pe.BeginDocument(pi, doc.Name, Nothing, 1, Not isPreview, filename)
- End If
- ' Which may contains multiple sheets
- ppd.LowerSheetProgressRange = 0
- ppd.UpperSheetProgressRange = 100
- ppd.SheetProgressPos = 0
- Dim ppi As New PlotPageInfo()
- pe.BeginPage(ppi, pi, (numSheet = layoutsToPlot.Count), Nothing)
- ppd.OnBeginSheet()
- pe.BeginGenerateGraphics(Nothing)
- ppd.SheetProgressPos = 50
- pe.EndGenerateGraphics(Nothing)
- ' Finish the sheet
- Dim pepi As New PreviewEndPlotInfo()
- pe.EndPage(pepi)
- ret = pepi.Status
- ppd.SheetProgressPos = 100
- ppd.OnEndSheet()
- numSheet += 1
- ' Update the overall progress
- ppd.PlotProgressPos += (100 / layoutsToPlot.Count)
- Next
- ' Finish the document
- pe.EndDocument(Nothing)
- ' And finish the plot
- ppd.PlotProgressPos = 100
- ppd.OnEndPlot()
- pe.EndPlot(Nothing)
- End Using
- End Using
- Return ret
- End Function
|
|