Message 1 of 9
Plot to PDF
Not applicable
02-28-2012
01:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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.