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.
ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress")
Where did you find the above? It should be
ppd.PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress")
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".
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.
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
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.
Can't find what you're looking for? Ask the community or share your knowledge.