simple PDF-Plot by vb.net

simple PDF-Plot by vb.net

jan_tappenbeck
Collaborator Collaborator
2,462 Views
10 Replies
Message 1 of 11

simple PDF-Plot by vb.net

jan_tappenbeck
Collaborator
Collaborator

hi!

 

there are several plot-examples to in web with many difficult options and so on.

 

in my layout everythink is define an only the outputfile i will change in process.

 

the autocad-function EXPORTPDF is the function i will be use manual.

 

did anybody the simple way to craeate (export) the pdf-file.

 

i only need the point when the export will be finish for may other functions.

 

in hope....

 

Jan

0 Likes
2,463 Views
10 Replies
Replies (10)
Message 2 of 11

_gile
Consultant
Consultant

Hi,

 

If everything is defined, you can script the PLOT command using the Editor.Command() method, only specfying the layout name and the file name with "" (empty string) to validate the default options.

var ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
ed.Command("_PLOT", "_No", layoutName, "", "", fileName, "_No", "_Yes");

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 11

jan_tappenbeck
Collaborator
Collaborator

Hi !

 

thanks for answer. I convert to vb.net and modify

acDocument.Editor.Command(New Object() {"_PLOT", "_No", CurrentLayout, "", "", OutputFile4PDF, "_No", "_Yes"})

i get following error

Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
   bei Autodesk.AutoCAD.EditorInput.Editor.Command(Object[] parameter)
   bei EBL.MapService.Export_PdfRaster.Generate(OutputDefinition AusgabeFormat) in C:\VSProjects\2019\EBL.MapService\EBL.MapService\cls_Export_PdfRaster.vb:Zeile 253.
           -->  ,2020-03-26 10:24:54

i did not see any mistake -  is there a possiblity to get more detail-informations?

 

Sorry - Copy and Paste of error only works by Code.

 

regards Jan

0 Likes
Message 4 of 11

_gile
Consultant
Consultant

Did you try to do it directly at the command line?

 

Command: _-plot

Detailed plot configuration? [Yes No] <No>: _No

Layout name [?] : ...

 

This way you can see which option failed.

 

PS: you do not need to explicitly build an object array for the Editor.Command() method because it accepts a ParamArray.

acDocument.Editor.Command("_PLOT", "_No", CurrentLayout, "", "", OutputFile4PDF, "_No", "_Yes")

 

PPS: scripting AutoCAD commands is much more easy with AutoLISP because you can do it step by step directly at command line:

(command "_PLOT")

(command "_PLOT" "_No")

(command "_PLOT" "_No" layoutName)

...

(command "_PLOT" "_No" layoutName "" "" fileName "_No" "_Yes")

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 11

jan_tappenbeck
Collaborator
Collaborator

hi !

 

i will be crazy...

 

my current Code is:

 _Log.Write("CommandString:= " & CommandString)
acDocument.Editor.Command(CommandString)

 

the log will be

CommandString:= "_-PLOT" "_No" "PdfRaster1000x1000" "" "_DWG To PDF_NoPreview.pc3" "P:\\KARTEN\\Sielkataster_1000_PDF\\Neu\\2575_2020-03-26.pdf" "_No" "_Yes"

OutputFile4PDF:= P:\\KARTEN\\Sielkataster_1000_PDF\\Neu\\2575_2020-03-26.pdf

**** Fehler ****
unerwarteter Fehler in EBL_MapService > Export_PdfRaster > Generate
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput
   bei Autodesk.AutoCAD.EditorInput.Editor.Command(Object[] parameter)
   bei EBL.MapService.Export_PdfRaster.Generate(OutputDefinition AusgabeFormat) in C:\VSProjects\2019\EBL.MapService\EBL.MapService\cls_Export_PdfRaster.vb:Zeile 287.
           -->  ,2020-03-26 15:55:42

 

but the plot will not create. When i send into command line the plot will be create

 

Befehl: (command "_-PLOT" "_No" "PdfRaster1000x1000" "" "_DWG To PDF_NoPreview.pc3" "P:\\KARTEN\\Sielkataster_1000_PDF\\Neu\\2575_2020-03-26.pdf" "_No" "_Yes")
_-PLOT Detaillierte Plotkonfiguration? [Ja/Nein] <Nein>: _No
Layoutnamen eingeben oder [?] <PdfRaster1000x1000>: PdfRaster1000x1000
Namen für Seiteneinrichtung eingeben <>: Ausgabegerätname eingeben oder [?] <_DWG To PDF.pc3>: _DWG To PDF_NoPreview.pc3
Dateiname angeben <Zeichnung2-PdfRaster1000x1000.pdf>: P:\KARTEN\Sielkataster_1000_PDF\Neu\2575_2020-03-26.pdf Änderungen an der Seiteneinrichtung speichern [Ja/Nein]? <N> _No Plotten fortsetzen [Ja/Nein] <J>: _Yes Tatsächlicher Plotbereich:  1040.00 breit und  1040.00 hoch
Tatsächlicher Plotbereich:  999.91 breit und  999.91 hoch

Ansichtsfenster 2 wird geplottet.

Ansichtsfenster 1 wird geplottet.

 

did someone have a idea??

 

regards Jan

0 Likes
Message 6 of 11

_gile
Consultant
Consultant

It seems to me that you do not have to escape the underscore (\) with an other underscore in VB strings.

acDocument.Editor.Command("_-PLOT" "_No" "PdfRaster1000x1000" "" "_DWG To PDF_NoPreview.pc3" "P:\KARTEN\Sielkataster_1000_PDF\Neu\2575_2020-03-26.pdf" "_No" "_Yes")

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 11

jan_tappenbeck
Collaborator
Collaborator

Hi!

no success!

 

😫

 

Jan

0 Likes
Message 8 of 11

_gile
Consultant
Consultant

Oops!...

My mistake, arguments have to be separated with commas:

acDocument.Editor.Command("_-PLOT", "_No", "PdfRaster1000x1000", "", "_DWG To PDF_NoPreview.pc3", "P:\KARTEN\Sielkataster_1000_PDF\Neu\2575_2020-03-26.pdf", "_No", "_Yes")

 

If it still don't work, you can find which argument is not valid usind using CommandAsync and run the code step by step.

C#

        [CommandMethod("TEST")]
        public async static void Test()
        {
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor;
            await ed.CommandAsync("_PLOT");
            await ed.CommandAsync("_No");
            await ed.CommandAsync("PdfRaster1000x1000");
            await ed.CommandAsync("");
            await ed.CommandAsync("_DWG To PDF_NoPreview.pc3");
            await ed.CommandAsync(@"P:\KARTEN\Sielkataster_1000_PDF\Neu\2575_2020-03-26.pdf");
            await ed.CommandAsync("_No");
            await ed.CommandAsync("_Yes");
        }

VB (convert with Telerik, not tested)

<CommandMethod("TEST")>
Public Async Shared Sub Test()
    Dim ed As Editor = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor
    Await ed.CommandAsync("_PLOT")
    Await ed.CommandAsync("_No")
    Await ed.CommandAsync("PdfRaster1000x1000")
    Await ed.CommandAsync("")
    Await ed.CommandAsync("_DWG To PDF_NoPreview.pc3")
    Await ed.CommandAsync("P:\KARTEN\Sielkataster_1000_PDF\Neu\2575_2020-03-26.pdf")
    Await ed.CommandAsync("_No")
    Await ed.CommandAsync("_Yes")
End Sub

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 11

jan_tappenbeck
Collaborator
Collaborator

hi !

 

first i was very hopefull - but the bugfix of "," was not successfull. event _-plot not _plot!

 

then i try to take the async-way. i could not start the new command and so i call like subfunction by my code.

 

when my code finish there comes a error of autocad and the applikation crashed. (attachment)

 

my eror message is:

 

 

System: 
Autodesk.AutoCAD.Runtime.Exception: eInvalidInput 
   bei Autodesk.AutoCAD.EditorInput.Editor.CommandAsync(Object[] parameter) 
   bei EBL.MapService.Export_PdfRaster.VB$StateMachine_11_Plottest.MoveNext() in C:\VSProjects\2019\EBL.MapService\EBL.MapService\cls_Export_PdfRaster.vb:Zeile 362.
--- Ende der Stapelüberwachung vom vorhergehenden Ort, an dem die Ausnahme ausgelöst wurde --- 
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
   bei Autodesk.AutoCAD.ApplicationServices.DocumentCollectionExtension.Add(DocumentCollection docCol, String templateFileName)
   bei EBL.MapService.Export_PdfRaster.Generate(OutputDefinition AusgabeFormat) in C:\VSProjects\2019\EBL.MapService\EBL.MapService\cls_Export_PdfRaster.vb:Zeile 172.

 

 

in the line of "_-plot".

logfileon is active but no information in the log-file!

 

regards Jan

0 Likes
Message 10 of 11

_gile
Consultant
Consultant

@jan_tappenbeck wrote:

 

then i try to take the async-way. i could not start the new command and so i call like subfunction by my code.


Could you elaborate about the context you're calling this code, because you cannot call Editor.Command() in application context.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 11 of 11

jan_tappenbeck
Collaborator
Collaborator

Hi!

 

at the weekend i search less in web and found several examples and by the following i get some success. know my Code Looks like.

thanks for your much time you send to find a way.

 

jan

 

 Public Sub RasterPlot(PlotFullName As String)
        ' ------ Quelle: https://www.keanw.com/2007/09/driving-a-basic.html
        _Log.WriteFuncName((New StackTrace).GetFrame(0).GetMethod.Name)
        _Log.WriteParameter("PlotFullName", PlotFullName)
        Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim tr As Transaction = db.TransactionManager.StartTransaction()

        Using tr

            Try

                Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), BlockTableRecord)
                Dim lo As Layout = CType(tr.GetObject(btr.LayoutId, Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead), Layout)
                Dim pi As PlotInfo = New PlotInfo()
                pi.Layout = btr.LayoutId
                Dim ps As PlotSettings = New PlotSettings(lo.ModelType)
                ps.CopyFrom(lo)
                Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
                'psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window) 'angepasst
                psv.SetUseStandardScale(ps, True)
                psv.SetStdScaleType(ps, StdScaleType.StdScale1To1) 'angepasst
                psv.SetPlotCentered(ps, True)

                ' HINWEIS: hier den internen Namen des Papierformates ermitteln
                ' Dim fPlot As New EBL.Acad.Plotten()
                ' Dim ListPossibleDeviceMedium As String = fPlot.GetPossibleMedia("_DWG To PDF_NoPreview.pc3")

                psv.SetPlotConfigurationName(ps, "_DWG To PDF_NoPreview.pc3", "UserDefinedMetric (1040.00 x 1040.00mm)")
                pi.OverrideSettings = ps
                Dim piv As PlotInfoValidator = New PlotInfoValidator()
                piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
                piv.Validate(pi)


                If PlotFactory.ProcessPlotState = ProcessPlotState.NotPlotting Then
                    Dim pe As PlotEngine = PlotFactory.CreatePublishEngine()

                    Using pe
                        Dim ppd As PlotProgressDialog = New PlotProgressDialog(False, 1, True)

                        Using ppd
                            ' -- mit den nachfolgenden ppd-Parametern bin ich nicht klargekommen
                            ''ppd.PlotMsgString(PlotMessageIndex.DialogTitle = "Custom Plot 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
                            ppd.OnBeginPlot()
                            ppd.IsVisible = True
                            pe.BeginPlot(ppd, Nothing)
                            pe.BeginDocument(pi, doc.Name, Nothing, 1, True, PlotFullName)
                            ppd.OnBeginSheet()
                            ppd.LowerSheetProgressRange = 0
                            ppd.UpperSheetProgressRange = 100
                            ppd.SheetProgressPos = 0
                            Dim ppi As PlotPageInfo = New PlotPageInfo()
                            pe.BeginPage(ppi, pi, True, Nothing)
                            pe.BeginGenerateGraphics(Nothing)
                            pe.EndGenerateGraphics(Nothing)
                            pe.EndPage(Nothing)
                            ppd.SheetProgressPos = 100
                            ppd.OnEndSheet()
                            pe.EndDocument(Nothing)
                            ppd.PlotProgressPos = 100
                            ppd.OnEndPlot()
                            pe.EndPlot(Nothing)
                        End Using 'ppd
                    End Using 'pe
                Else
                    ed.WriteMessage(vbLf & "Another plot is in progress.")
                    _Log.WriteAsError("Another plot is in progress!")
                End If

            Catch ex As System.Exception
                _Log.WriteAsError("Fehler bei der Plotausgabe!" & Environment.NewLine & ex.ToString)
            End Try

        End Using
    End Sub

 

 

 

 

0 Likes