.NET

Reply
Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 1 of 9 (1,051 Views)

Plot to PDF

1051 Views, 8 Replies
02-28-2012 01:24 AM
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.PlottingServices
Imports Autodesk.AutoCAD.Geometry
Imports System.Runtime.InteropServices
Namespace PlottingApplication
    Public Class class1
        <DllImport("acad.exe", CallingConvention:=CallingConvention.Cdecl, EntryPoint:="acedTrans")> _
        Private Shared Function acedTrans(ByVal point As Double(), ByVal fromRb As IntPtr, ByVal toRb As IntPtr, ByVal disp As Integer, ByVal result As Double()) As Integer

        End Function
        <CommandMethod("winplot")> _
        Public Shared Sub WindowPlot()

            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim ed As Editor = doc.Editor
            Dim db As Database = doc.Database
            Dim ppo As New PromptPointOptions(vbLf & "Select first corner of plot area: ")
            ppo.AllowNone = False

            Dim ppr As PromptPointResult = ed.GetPoint(ppo)
            If ppr.Status <> PromptStatus.OK Then
                Return
            End If

            Dim first As Point3d = ppr.Value
            Dim pco As New PromptCornerOptions(vbLf & "Select second corner of plot area: ", first)
            ppr = ed.GetCorner(pco)
            If ppr.Status <> PromptStatus.OK Then
                Return
            End If

            Dim second As Point3d = ppr.Value

            ' Transform from UCS to DCS
            Dim rbFrom As New ResultBuffer(New TypedValue(5003, 1)), rbTo As New ResultBuffer(New TypedValue(5003, 2))
            Dim firres As Double() = New Double() {0, 0, 0}
            Dim secres As Double() = New Double() {0, 0, 0}

            ' Transform the first point...
            acedTrans(first.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres)
            ' ... and the second
            acedTrans(second.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, secres)
            ' We can safely drop the Z-coord at this stage
            Dim window As New Extents2d(firres(0), firres(1), secres(0), secres(1))
            Dim tr As Transaction = db.TransactionManager.StartTransaction()
            Using tr

                ' We'll be plotting the current layout

                Dim btr As BlockTableRecord = DirectCast(tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead), BlockTableRecord)
                Dim lo As Layout = DirectCast(tr.GetObject(btr.LayoutId, OpenMode.ForRead), Layout)
                ' We need a PlotInfo object

                ' linked to the layout

                Dim pi As New PlotInfo()
                pi.Layout = btr.LayoutId
                ' 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.SetPlotWindowArea(ps, window)
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window)
                psv.SetUseStandardScale(ps, True)
                psv.SetStdScaleType(ps, StdScaleType.ScaleToFit)
                psv.SetPlotCentered(ps, True)
                ' We'll use the standard DWF PC3, as
                ' for today we're just plotting to file
                psv.SetPlotConfigurationName(ps, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)")
                ' 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)
                ' A PlotEngine does the actual plotting

                ' (can also create one for Preview)
                If PlotFactory.ProcessPlotState = ProcessPlotState.NotPlotting Then
                    Dim pe As PlotEngine = PlotFactory.CreatePublishEngine()
                    Using pe
                        ' Create a Progress Dialog to provide info
                        ' and allow thej user to cancel
                        Dim ppd As New PlotProgressDialog(False, 1, True)
                        Using ppd
                            ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress")
                            ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job")
                            ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet")
                            ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress")
                            ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress")
                            ppd.LowerPlotProgressRange = 0
                            ppd.UpperPlotProgressRange = 100
                            ppd.PlotProgressPos = 0
                            ' Let's start the plot, at last

                            ppd.OnBeginPlot()

                            ppd.IsVisible = True
                            pe.BeginPlot(ppd, Nothing)
                            ' We'll be plotting a single document
                            ' Let's plot to file
                            pe.BeginDocument(pi, doc.Name, Nothing, 1, True, "c:\test-output")

                            ' Which contains a single sheet
                            ppd.OnBeginSheet()
                            ppd.LowerSheetProgressRange = 0
                            ppd.UpperSheetProgressRange = 100
                            ppd.SheetProgressPos = 0

                            Dim ppi As New PlotPageInfo()
                            pe.BeginPage(ppi, pi, True, Nothing)
                            pe.BeginGenerateGraphics(Nothing)
                            pe.EndGenerateGraphics(Nothing)
                            ' Finish the sheet
                            pe.EndPage(Nothing)
                            ppd.SheetProgressPos = 100
                            ppd.OnEndSheet()
                            ' Finish the document
                            pe.EndDocument(Nothing)
                            ' And finish the plot
                            ppd.PlotProgressPos = 100
                            ppd.OnEndPlot()
                            pe.EndPlot(Nothing)
                        End Using
                    End Using
                Else
                    ed.WriteMessage(vbLf & "Another plot is in progress.")
                End If
            End Using
        End Sub
    End Class
End Namespace

 I need to create a DLL which asks to select the required area in drawing to convert to PDF.
I have seen the smaple in Kean Walmsley site but ia m getting error near the below line,

 ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress")

"set_plotmsgstring is not a member of autodesk.autocad.plottingservices.plotprogressdialog"

I have added refernece of acdbmgd.dll and acmgd.

I am using VIsual sutdio 2008 and autocad 2007.

Could anyone pelase help me out from this issue?

THank you.

Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 2 of 9 (1,024 Views)

Re: Plot to PDF

02-28-2012 07:57 AM in reply to: muthineni

ppd.set_PlotMsgString(PlotMessageIndex.DialogTitl​e, "Custom Plot Progress")

Where did you find the above?  It should be

ppd.PlotMsgString(PlotMessageIndex.DialogTitl​e, "Custom Plot Progress")


Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 3 of 9 (1,006 Views)

Re: Plot to PDF

02-28-2012 08:10 PM in reply to: muthineni
Thank you so much. Now it is working if i give, ppd.PlotMsgString(PlotMessageIndex.DialogTitle)= "Custom Plot Progress" But i am not able to plot to PDF, some file is getting created a .dwf. I am new to Autocad .NET, can anyone tell me how to proceed further? Thank you.
Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 4 of 9 (985 Views)

Re: Plot to PDF

02-29-2012 07:59 AM in reply to: muthineni

You need to change this line to the pc3 file you want to use:

psv.SetPlotConfigurationName(ps, "DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)")

 

I suggest "DWG To PDF.pc3" for starters.

 

There are several examples of plot code in this forum and this: http://through-the-interface.typepad.com/through_the_interface/plotting/

 

Scroll down to the "Plotting a window from Autocad using .NET".

Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 5 of 9 (971 Views)

Re: Plot to PDF

02-29-2012 08:06 PM in reply to: fieldguy
Thank you so much for the reply. Now the code is working fine. But now i need to change the Plot Style table and drawing orientation to (Portrait). THank you.
Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 6 of 9 (949 Views)

Re: Plot to PDF

03-01-2012 08:09 AM in reply to: muthineni

I see where you got your example from.  Good work!

 

psv.SetPlotRotation(ps, PlotRotation.Degrees000) is landscape.  Intellisense will provide the options.  You probably want PlotRotation.Degrees090.

Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 7 of 9 (947 Views)

Re: Plot to PDF

03-01-2012 08:16 AM in reply to: muthineni

Forgot the style sheet.  You can use a try/catch to make sure the CTB file is found.

 

psv.SetCurrentStyleSheet(ps, "CTB Filename").  "None" is represented by

psv.SetCurrentStyleSheet(ps, "")

 

Try

  psv.SetCurrentStyleSheet(ps, ctbfile)

Catch ex AsException

  'create a message or a log entry - CTB not found

  'set it to none if you want

  psv.SetCurrentStyleSheet(ps,"") 

EndTry

Valued Contributor
muthineni
Posts: 73
Registered: ‎10-10-2011
Message 8 of 9 (928 Views)

Re: Plot to PDF

03-02-2012 03:57 AM in reply to: fieldguy
the plot which i have given exists in the system. then also it is showing the below error.First time when i run the program it worked and from second time it is not at all working. I tried with different drawings also. Application does not support just-in-time (JIT) debugging. See the end of this message for details. ************** Exception Text ************** System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Autodesk.AutoCAD.Runtime.Exception: eInvalidInput at Autodesk.AutoCAD.DatabaseServices.PlotSettingsValidator.SetCurrentStyleSheet(PlotSettings plotSet, String styleSheetName) at ClassLibrary2.PlottingApplication.SimplePlottingCommands.WindowPlot() in D:\Hochtief Project\PROJECT\Lusail\Test\AUTOCAD_VISIO\Program Files\Plot to PDF\ClassLibrary2\Class1.vb:line 172 --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at AcMgCommandClass.InvokeWorker(AcMgCommandClass* , MethodInfo mi, Object commandObject, Boolean bLispFunction) at AcMgCommandClass.Invoke(AcMgCommandClass* , gcroot:reflection::methodinfo>* mi, Boolean bLispFunction) at Autodesk.AutoCAD.Runtime.TargetInvocationSEHExceptionFilter.InvokeWorker() at Autodesk.AutoCAD.Runtime.ExceptionFilter.Invoke() ************** Loaded Assemblies ************** mscorlib Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll ---------------------------------------- acdbmgd Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AcdbMgd.DLL ---------------------------------------- msvcm80 Assembly Version: 8.0.50727.4053 Win32 Version: 8.00.50727.4053 CodeBase: file:///C:/WINDOWS/WinSxS/x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.4053_x-ww_e6967989/msvcm80.dll ---------------------------------------- System Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll ---------------------------------------- System.Xml Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll ---------------------------------------- System.Drawing Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll ---------------------------------------- System.Windows.Forms Assembly Version: 2.0.0.0 Win32 Version: 2.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll ---------------------------------------- acmgd Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/acmgd.DLL ---------------------------------------- AecDtlDb50 Assembly Version: 5.0.272.0 Win32 Version: 5, 0, 272, 0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AecDtlDb50.DLL ---------------------------------------- AecDtlDbUI Assembly Version: 5.0.272.0 Win32 Version: 5.0.272.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AecDtlDbUI.DLL ---------------------------------------- AecDtlDbLib Assembly Version: 5.0.272.0 Win32 Version: 5.0.272.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AecDtlDbLib.DLL ---------------------------------------- AcDxUi Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AcDxUi.DLL ---------------------------------------- AcDx Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AcDx.DLL ---------------------------------------- AcDxUi.resources Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/en-US/AcDxUi.resources.DLL ---------------------------------------- AcMgdShared Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AcMgdShared.DLL ---------------------------------------- AcLayer Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/AcLayer.DLL ---------------------------------------- AcLayer.resources Assembly Version: 17.0.54.0 Win32 Version: 17.0.54.0 CodeBase: file:///C:/Program%20Files/Autodesk%20Architectural%20Desktop%202007/en-US/AcLayer.resources.DLL ---------------------------------------- ClassLibrary2 Assembly Version: 1.0.0.0 Win32 Version: 1.0.0.0 CodeBase: file:///D:/Hochtief%20Project/PROJECT/Lusail/Test/AUTOCAD_VISIO/Program%20Files/Plot%20to%20PDF/ClassLibrary2/bin/Debug/ClassLibrary2.dll ---------------------------------------- Microsoft.VisualBasic Assembly Version: 8.0.0.0 Win32 Version: 8.0.50727.3053 (netfxsp.050727-3000) CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll ---------------------------------------- ************** JIT Debugging ************** Application does not support Windows Forms just-in-time (JIT) debugging. Contact the application author for more information.:reflection::methodinfo>
Valued Mentor
fieldguy
Posts: 367
Registered: ‎03-31-2005
Message 9 of 9 (914 Views)

Re: Plot to PDF

03-02-2012 07:59 AM in reply to: muthineni

Did you put setcurrentstylesheet in a try/catch?  You get an explantation of what went wrong in ex.message.

 

You'll have to post your code - I can look it over on the weekend. 

 

There is a mention of that issue (looks the same to me) in the comments section of this kean post: http://through-the-interface.typepad.com/through_the_interface/2007/10/previewing-and-.html

 

You have to scroll down to near the bottom - see the Comments from Joseph Garret.  My plotting app has an "imports system.collections.specialized" statement but that was done a long time ago.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community