Author Topic: Plotting to PDF: Layer Information  (Read 2760 times)

0 Members and 1 Guest are viewing this topic.

Mithraz87

  • Guest
Plotting to PDF: Layer Information
« on: February 26, 2013, 05:43:57 PM »
I have created an external program to create PDF's automatically of opened DWG's using VB.Net. Here is some of my code, a lot of which came from Gile, Tony, Fixo, and others on TheSwamp:

Code: [Select]

        Dim doc As Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument
        Dim ed As Editor = doc.Editor
        Dim db As Database = doc.Database
        Dim tr As Transaction = db.TransactionManager.StartTransaction()

        Using tr
            Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForRead)
            Dim pi As PlotInfo = New PlotInfo()

            If PlotFactory.ProcessPlotState = ProcessPlotState.NotPlotting Then

                Dim layoutId As Autodesk.AutoCAD.DatabaseServices.ObjectId = LayoutManager.Current.GetLayoutId(LayoutManager.Current.CurrentLayout)
                Dim activeLyt As Autodesk.AutoCAD.DatabaseServices.Layout = tr.GetObject(layoutId, OpenMode.ForRead)

                pi.Layout = layoutId
                Dim ps As PlotSettings = New PlotSettings(activeLyt.ModelType)


                Dim obj As AcadObject = activeLyt.AcadObject


                ps.CopyFrom(activeLyt)
                ps.PlotSettingsName = "PDF"
                ps.ScaleLineweights = True

                Dim configStr As String = "DWG To PDF.pc3"
                Dim plotName As String = "ANSI_full_bleed_E_(34.00_x_44.00_Inches)"

                Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
                psv.SetPlotConfigurationName(ps, configStr, plotName)
                psv.RefreshLists(ps)
                psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
                psv.SetPlotPaperUnits(ps, Autodesk.AutoCAD.DatabaseServices.PlotPaperUnit.Inches)
                psv.SetPlotRotation(ps, Autodesk.AutoCAD.DatabaseServices.PlotRotation.Degrees090)
                psv.SetPlotOrigin(ps, New Autodesk.AutoCAD.Geometry.Point2d(0, 0))
                'psv.SetPlotCentered(ps, True)
                'psv.SetCanonicalMediaName(ps, "ANSI_full_bleed_E_(34.00_x_44.00_Inches)")
                psv.SetCustomPrintScale(ps, New Autodesk.AutoCAD.DatabaseServices.CustomScale(num, den))
                psv.SetStdScale(ps, (num / den))
                psv.SetUseStandardScale(ps, True)
                psv.SetCurrentStyleSheet(ps, PenTable)

                pi.OverrideSettings = ps
                Dim piv As PlotInfoValidator = New PlotInfoValidator()
                piv.MediaMatchingPolicy = MatchingPolicy.MatchDisabled
                piv.Validate(pi)

                Dim pe As PlotEngine = PlotFactory.CreatePublishEngine
                Using pe

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

                    Using ppd

                        ppd.PlotMsgString(PlotMessageIndex.DialogTitle) = "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, fileName)

                        ppd.PlotMsgString(PlotMessageIndex.Status) = "Plotting: " & doc.Name & " - " & activeLyt.LayoutName

                        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
                End Using
            End If
        End Using


My question is, how do I control Autocad's "DWG To PDF.pc3" to include layer information? I want to do this programatically rather than opening up the pc3 and changing it manually. I have the default set to not include the layer information. If this is not even possible, then just slap me and move on the next question.
I feel like I have searched everywhere for this information and have come up with nothing.

Thank for you taking the time to read and respond.

n.yuan

  • Bull Frog
  • Posts: 348
Re: Plotting to PDF: Layer Information
« Reply #1 on: February 28, 2013, 10:23:03 AM »
AFAIK, there is no APIs exposed to modify PC3.

So, if your app has to have option of including or not including layer information, you probably can manually open up the DWG To PDF.pc3 and modify its custom property (Include Layer Information), and save the pc3 with different name (such as DWG To PDF1.pc3) and deploy the pc3 to your app's users. Then your app can choose the desired pc3 to include or not include layer information. This approach surely makes the deployment more complicated and I'd avoid it if possible.