Message 1 of 16
Create PDF File from some Layouts only

Not applicable
04-01-2016
01:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
hello everybody
get an fatal error when to try to plot ,mulitiple layouts in multiple files
i detect the format of the drawing and make from there my plot to pdf
<CommandMethod("PUB1")> _ Public Shared Sub Publish1() Dim openfdail As New OpenFileDialog("Select Drawings", Nothing, "dwg; dwf; *", "selfile", OpenFileDialog.OpenFileDialogFlags.AllowMultiple) Dim dr1 As System.Windows.Forms.DialogResult = openfdail.ShowDialog() If dr1 = System.Windows.Forms.DialogResult.OK Then Dim filenames() As String = openfdail.GetFilenames Dim file As String Dim filename As String = String.Empty Dim plotdir As String = "c:\plot\" Dim formaat As String = String.Empty ' Get the current document and database, and start a transaction Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim ed As Editor = acDoc.Editor Dim oldDb As Database = HostApplicationServices.WorkingDatabase For Each file In filenames filename = System.IO.Path.GetFileNameWithoutExtension(file) 'Check if drawing is a reference file if so dont plot If UCase(Mid(filename, 8, 1)) <> "R" Then Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("BACKGROUNDPLOT", 0) Using db As New Database(False, True) db.ReadDwgFile(file, FileOpenMode.OpenForReadAndAllShare, False, Nothing) db.CloseInput(True) HostApplicationServices.WorkingDatabase = db Using acTrans As Transaction = db.TransactionManager.StartTransaction() Try Dim ldic As DBDictionary = CType(acTrans.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite), DBDictionary) For Each entr As DictionaryEntry In ldic Dim lo As Layout = CType(acTrans.GetObject(entr.Value, OpenMode.ForWrite), Layout) If InStr(UCase(lo.LayoutName), "MODEL") = 0 Then If getform(acDoc, lo.LayoutName, db, ed) <> "LEEG" Or getform(acDoc, lo.LayoutName, db, ed) <> "ONBEKEND" Then LayoutManager.Current.CurrentLayout = lo.LayoutName filename = plotdir & System.IO.Path.GetFileNameWithoutExtension(file) & "." & lo.LayoutName & ".pdf" MsgBox(filename & " : " & LayoutManager.Current.CurrentLayout) MsgBox(db.OriginalFileName) plot(lo, db, acDoc, filename, file, ed) End If End If Next Catch ex As System.Exception ed.WriteMessage(ex.ToString()) End Try End Using End Using End If HostApplicationServices.WorkingDatabase = oldDb Next End If End Sub Public Shared Sub plot(ByVal lo As Layout, ByVal db As Database, ByVal acdoc As Document, ByVal filename As String, ByVal file As String, ByVal ed As Editor) Dim formaat As String = String.Empty ' Get the PlotInfo from the layout Using acPlInfo As New PlotInfo() acPlInfo.Layout = lo.ObjectId ' Get a copy of the PlotSettings from the layout Using acPlSet As New PlotSettings(lo.ModelType) acPlSet.CopyFrom(lo) ' Update the PlotSettings object Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current ' Set the plot type acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents) ' Set the plot scale acPlSetVdr.SetUseStandardScale(acPlSet, True) acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.ScaleToFit) ' Center the plot acPlSetVdr.SetPlotCentered(acPlSet, True) acPlInfo.OverrideSettings = acPlSet ' Specify if plot styles should be displayed on the layout acPlSet.ShowPlotStyles = True acPlSetVdr.RefreshLists(acPlSet) ' Set the plot style 'acPlSetVdr.SetCurrentStyleSheet(acPlSet, "acad.ctb") acPlSetVdr.SetCurrentStyleSheet(acPlSet, "Zwart (kleur onderhoek).ctb") formaat = getform(acdoc, lo.LayoutName, db, ed) ' Set the plot device to use acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", formaat) ' Set the plot info as an override since it will ' not be saved back to the layout acPlInfo.OverrideSettings = acPlSet ' Validate the plot info Using acPlInfoVdr As New PlotInfoValidator() acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled acPlInfoVdr.Validate(acPlInfo) ' Check to see if a plot is already in progress If PlotFactory.ProcessPlotState = ProcessPlotState.NotPlotting Then Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine() ' Track the plot progress with a Progress dialog Using acPlProgDlg As New PlotProgressDialog(False, 1, True) Using (acPlProgDlg) ' Define the status messages to display ' when plotting starts acPlProgDlg.PlotMsgString(PlotMessageIndex.DialogTitle) = _ "Plot Progress" acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = _ "Cancel Job" acPlProgDlg.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = _ "Cancel Sheet" acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = _ "Sheet Set Progress" acPlProgDlg.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = _ "Sheet Progress" ' Set the plot progress range acPlProgDlg.LowerPlotProgressRange = 0 acPlProgDlg.UpperPlotProgressRange = 100 acPlProgDlg.PlotProgressPos = 0 ' Display the Progress dialog acPlProgDlg.OnBeginPlot() acPlProgDlg.IsVisible = True ' Start to plot the layout acPlEng.BeginPlot(acPlProgDlg, Nothing) ' Define the plot output ' Define the plot output acPlEng.BeginDocument(acPlInfo, _ acdoc.Name, _ Nothing, _ 1, _ True, _ filename) ' Display information about the current plot '' Display information about the current plot acPlProgDlg.PlotMsgString(PlotMessageIndex.Status) = _ "Plotting: " & file & _ " - " & lo.LayoutName ' Set the sheet progress range acPlProgDlg.OnBeginSheet() acPlProgDlg.LowerSheetProgressRange = 0 acPlProgDlg.UpperSheetProgressRange = 100 acPlProgDlg.SheetProgressPos = 0 ' Plot the first sheet/layout Using acPlPageInfo As New PlotPageInfo() acPlEng.BeginPage(acPlPageInfo, acPlInfo, True, Nothing) End Using acPlEng.BeginGenerateGraphics(Nothing) acPlEng.EndGenerateGraphics(Nothing) ' Finish plotting the sheet/layout acPlEng.EndPage(Nothing) acPlProgDlg.SheetProgressPos = 100 acPlProgDlg.OnEndSheet() ' Finish plotting the document acPlEng.EndDocument(Nothing) ' Finish the plot acPlProgDlg.PlotProgressPos = 100 acPlProgDlg.OnEndPlot() acPlEng.EndPlot(Nothing) End Using End Using End Using End If End Using End Using End Using End Sub
Shared Function getform(ByVal acdoc As Document, ByVal layout As String, ByVal db As Database, ByVal ed As Editor) As String Dim formaat As String = String.Empty Dim acTypValondnew(17) As TypedValue acTypValondnew.SetValue(New TypedValue(DxfCode.Operator, "<And"), 0) acTypValondnew.SetValue(New TypedValue(DxfCode.Start, "INSERT"), 1) acTypValondnew.SetValue(New TypedValue(DxfCode.Operator, "<or"), 2) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF0a0"), 3) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF1a0"), 4) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF2a0"), 5) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF0a1"), 6) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF1a1"), 7) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF0a2"), 8) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF0a3"), 9) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF0a4"), 10) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF3a4"), 11) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF4a4"), 12) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF5a4"), 13) acTypValondnew.SetValue(New TypedValue(DxfCode.BlockName, "HTCAF6a4"), 14) acTypValondnew.SetValue(New TypedValue(DxfCode.Operator, "or>"), 15) acTypValondnew.SetValue(New TypedValue(DxfCode.LayoutName, layout), 16) acTypValondnew.SetValue(New TypedValue(DxfCode.Operator, "And>"), 17) Dim acSelFtrondnew As SelectionFilter = New SelectionFilter(acTypValondnew) Dim acSSPromptondnew As PromptSelectionResult acSSPromptondnew = ed.SelectAll(acSelFtrondnew) If acSSPromptondnew.Status = PromptStatus.OK Then Dim acSSet As SelectionSet = acSSPromptondnew.Value() Using actrans As Transaction = db.TransactionManager.StartTransaction() For Each acSSObj As SelectedObject In acSSet Dim blkref As BlockReference = actrans.GetObject(acSSObj.ObjectId, OpenMode.ForRead) Select Case blkref.Name Case "HTCAF0a0" formaat = "ISO_full_bleed_A0_(841.00_x_1189.00_MM)" Case "HTCAF1a0" formaat = "ISO_full_bleed_1A0_(841.00_x_1568.00_MM)" Case "HTCAF2a0" formaat = "ISO_full_bleed_2A0_(841.00_x_1758.00_MM)" Case "HTCAF0a1" formaat = "ISO_full_bleed_A1_(841.00_x_594.00_MM)" Case "HTCAF1a1" formaat = "ISO_full_bleed_1A1_(1189.00_x_594.00_MM)" Case "HTCAF0a2" formaat = "ISO_full_bleed_A2_(594.00_x_420.00_MM)" Case "HTCAF0a3" formaat = "ISO_full_bleed_A3_(420.00_x_297.00_MM)" Case "HTCAF0a4" formaat = "ISO_full_bleed_A4_(210.00_x_297.00_MM)" Case "HTCAF3a4" formaat = "ISO_full_bleed_3A4_(594.00_x_297.00_MM)" Case "HTCAF4a4" formaat = "ISO_full_bleed_4A4_(841.00_x_297.00_MM)" Case "HTCAF5a4" formaat = "ISO_full_bleed_5A4_(1050.00_x_297.00_MM)" Case "HTCAF6a4" formaat = "ISO_full_bleed_6A4_(1260.00_x_297.00_MM)" Case Else formaat = "ONBEKEND" End Select Next End Using Else formaat = "LEEG" End If Return formaat End Function