Create PDF File from some Layouts only

Create PDF File from some Layouts only

Anonymous
Not applicable
1,248 Views
15 Replies
Message 1 of 16

Create PDF File from some Layouts only

Anonymous
Not applicable

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
0 Likes
1,249 Views
15 Replies
Replies (15)
Message 2 of 16

BKSpurgeon
Collaborator
Collaborator

Hi Jorge

 

  • where is the error breaking?
  • What is the error you are getting?

 

It's a lot of code to sift through without much idea of  what it could be - make it easy for me to help you!

 

 

regards

 

BK

 

 

Message 3 of 16

Anonymous
Not applicable

hi BKSpurgeon

 

just get a fatal error and thats it 

 

FATAL ERROR:  Unhandled Access Violation Reading 0xffb41988 Exception at dff1efa6h

 

i almost think i go wrong when i change file of the database 

 

is one of the first experience with working only the database and trying to plot all the layouts 

 

maybe i am thinking  all wrong 

 

but thank u for ur reply and sorry i cant be more help 

 

0 Likes
Message 4 of 16

Anonymous
Not applicable
Just my penny: I have no problem plotting multiple drawing, even plotting multiple layouts at once, but I've always loaded them as document, never tried to read just the db...
I'd try to load them as proper document and see if you still get the fatal error...
Message 5 of 16

BKSpurgeon
Collaborator
Collaborator

(1) Enclose the code in a try/catch command.

(2) We want the stack trace:

 

Try
{
//// put all your code here

}
catch
(MyCustomException ex) { Debug.Writeline(ex.ToString());
// we want to see what is printed out............this will show you the error line where the code breaks.

}

 

(3) Please try debugging and keep going till it breaks. could be anywhere. 

Message 6 of 16

Anonymous
Not applicable

hi all thanks for all your advice

will try it in a couple of  days and report back to you

0 Likes
Message 7 of 16

BKSpurgeon
Collaborator
Collaborator

of course you'll catch "Exception" not myCustomException - i just cut and pasted without reading too closely. and unforutnately i cannot edit my original post.

 

BK

Message 8 of 16

Anonymous
Not applicable

hi BKSpurgeon

 

thx for the advice works great 

see even debug messages from autocad coming threw

 

but was create another solution 

was fix it by creating a pagesetup for every ;layout threw the database 

and that works fine and then i make a publish of all to

and now i was try the catch exception and now it runs till the end 

i gonna try today to break it again like i did before and then debug with the try exception

and will report back if i know more 

 

but thx for the advice will use this in the future

0 Likes
Message 9 of 16

Anonymous
Not applicable

ihis is the error 

 

 first chance exception of type 'System.AccessViolationException' occurred in Unknown Module.

 

not a lot of help to me 

0 Likes
Message 10 of 16

Anonymous
Not applicable

@Anonymous wrote:

ihis is the error 

 

 first chance exception of type 'System.AccessViolationException' occurred in Unknown Module.

 

not a lot of help to me 


No, indeed not of great help! Smiley Very Happy

 

But, cannot you debug it step by step and see where actually it throws the exception?

 

Anyway, a couple of ideas to follow: is your code still similar to what you posted at the beginning? As I suggested before, I'd load the documents as proper Document objects, without loading just the Database with ReadDWG().

And since you have to switch documents, I'd define the command with the 'CommandFlags.Session' attribute and then locking/unlocking the documents you load.

 

That way I know for sure it'd work, since it's the architecture I've been using for a while...

Message 11 of 16

Anonymous
Not applicable

hi mcicognani

will try that but i know it will work

even i not have tried it

here it is and by all means i am no specialist

and i was suppecting this from the beginning

and i think has something to do with closing and opening of the database

and it tries to allocate memory where it has no permission or something like that

and then i changed the exception in System.AccessViolationException to catch

that is what it said cant  write or no permision etc.

because i saw u could filter on exception in the debug menu of visual studio

changed the program omg tried to close the database like it should be

dispose of the plotsettings

dispose transaction

dispose of the layoutmanager

tried a lot

and now my unexperience comes in when i try  to debug the script

and i allready got the same result with adding to every layout a pagesetup and

making a publish of the files

but i just want to know why and how and what i did wrong

well get back with code for opening and closing the files and then plotting them

0 Likes
Message 12 of 16

Anonymous
Not applicable

like i promised 

 

the code opening ans closing drawing and switching between the layouts and then printing 

works fine 

except i cant set my PlotPaperUnit not to milimeters stay on stupid inches grrrrrrrrrrrrrrrrrrrrrrrr

 

here is the code but i dont see what is gonna help me with the databases 

 

 

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Colors
Imports Autodesk.AutoCAD.Windows
Imports Autodesk.AutoCAD.PlottingServices

Public Class dbtest
<CommandMethod("PUB", CommandFlags.Session)> _
Public Shared Sub Publish()
Try
Dim file As String
Dim filename As String = String.Empty
Dim plotdir As String = "c:\plot\"
Dim formaat As String = String.Empty
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 filenames() As String = openfdail.GetFilenames()
Dim acdocmgr As DocumentCollection = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager
Dim acDoc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
For Each file In filenames
acDoc = DocumentCollectionExtension.Open(acdocmgr, file, False)
Dim db As Database = acDoc.Database
Dim aced As Editor = acDoc.Editor
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument = acDoc
Using acLckDoc As DocumentLock = acDoc.LockDocument()
Using actrans As Transaction = db.TransactionManager.StartTransaction()
Dim ldic As DBDictionary = CType(actrans.GetObject(db.LayoutDictionaryId, OpenMode.ForRead), DBDictionary)
For Each entr As DictionaryEntry In ldic
Dim lo As Layout = CType(actrans.GetObject(entr.Value, OpenMode.ForWrite), Layout)
filename = plotdir & System.IO.Path.GetFileNameWithoutExtension(file) & "." & lo.LayoutName & ".pdf"
LayoutManager.Current.CurrentLayout = lo.LayoutName
Try
formaat = getform(acDoc, lo.LayoutName, db, aced)
plot(lo, db, filename, file, formaat, aced)
Catch ex As System.Exception
aced.WriteMessage(ex.ToString())
End Try
Next
actrans.Dispose()
End Using
End Using
DocumentExtension.CloseAndDiscard(acDoc)
Next
End If
Catch ex As System.Exception
Debug.Print(ex.ToString())
End Try

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
Public Shared Sub plot(ByRef lo As Layout, ByRef db As Database, ByVal filename As String, ByVal file As String, ByVal formaat As String, ByVal ed As Editor)
Dim CurVar As Object
'Get the BACKGROUNDPLOT SYSTEM VARIABLE
CurVar = Application.GetSystemVariable("BackGroundPlot")
'SET BACKGROUNDPLOT SYSTEM VARIABLE TO ZERO
Application.SetSystemVariable("BackGroundPlot", 0)
'' Get the PlotInfo from the layout
Dim acPlInfo As PlotInfo = New PlotInfo()
acPlInfo.Layout = lo.ObjectId

'' Set the PlotSettings object
Dim acPlSetVdr As PlotSettingsValidator = PlotSettingsValidator.Current

'' Get a PlotSettings from the layout
Dim acPlSet As PlotSettings = New PlotSettings(lo.ModelType)
acPlSet.CopyFrom(lo)

acPlSetVdr.RefreshLists(acPlSet)
acPlSetVdr.SetPlotType(acPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
'' Set the plot scale
acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters)
acPlSetVdr.SetUseStandardScale(acPlSet, True)
acPlSetVdr.SetStdScaleType(acPlSet, StdScaleType.StdScale1To1)
'acPlSet.ScaleLineweights = True
''set the style
acPlSetVdr.SetCurrentStyleSheet(acPlSet, "Zwart (kleur onderhoek).ctb")
'' Center the plot
acPlSetVdr.SetPlotCentered(acPlSet, True)
''set the rotation
'acPlSetVdr.SetPlotRotation(acPlSet, Rotation) 'Rotations is passed through the function
'' Set the plot device to use
acPlSetVdr.SetPlotConfigurationName(acPlSet, "DWG To PDF.pc3", formaat)

'' Set the plot info as an override
acPlInfo.OverrideSettings = acPlSet
acPlSetVdr.RefreshLists(acPlSet)

'' Validate the plot info
Dim acPlInfoVdr As PlotInfoValidator = New PlotInfoValidator()
acPlInfoVdr.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
acPlInfoVdr.Validate(acPlInfo)
acPlSetVdr.SetZoomToPaperOnUpdate(acPlSet, True)
lo.CopyFrom(acPlSet)
'' Check whether a plot job is in progress
If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting Then
Using acPlEng As PlotEngine = PlotFactory.CreatePublishEngine()

'' Track the plot progress with a Progress dialog
Dim acPlProgDlg As PlotProgressDialog = 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)

acPlEng.BeginDocument(acPlInfo, _
file, _
Nothing, _
1, _
True, _
filename)

'' 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
Dim acPlPageInfo As PlotPageInfo = New PlotPageInfo()
acPlEng.BeginPage(acPlPageInfo, _
acPlInfo, _
True, _
Nothing)

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 If
'REVERT BACK TO THE ORIGINAL BACKGROUNDPLOT SYSTEM VARIABLE
Application.SetSystemVariable("BackGroundPlot", CurVar)
End Sub
End Class

 

0 Likes
Message 13 of 16

Anonymous
Not applicable

Should be in the PlotSettingsValidator:

 

psv.SetPlotPaperUnits(ps, PlotPaperUnit.Millimeters);

EDIT:

No, sorry, seen you already did it...

 

What's the units of the drawings itself? Inches? If so, you just have to take into account and adjust the PlotScale factor... 

 

EDIT2:

Look, someone else had the same issue:

 

http://forums.autodesk.com/t5/net/plotsettingsvalidator-setplotpaperunits/m-p/6025017/highlight/true...

Message 14 of 16

Anonymous
Not applicable

i know 

 

 acPlSetVdr.SetPlotPaperUnits(acPlSet, PlotPaperUnit.Millimeters)

i was put in my code and still keeps inches but will look online if i can find what i am doing wrong

but like i told u works when u open and close the drawing and switch the layouts and plot them 

 

but for the database version still the same problem 

 

 

0 Likes
Message 15 of 16

Anonymous
Not applicable

Hi Jorge.

 

Forgetting to commit a Transaction?

0 Likes
Message 16 of 16

Anonymous
Not applicable

hi mtb task

 

why should i commit if i do a override of the plotsettings 

and i want to know what is wrong with plotpaperunits

but we are drifting away from the real problem 

 

why i get a fata error when i try to the sme when i only open the database

 

i just want to plot and make no futther changes 

0 Likes