C# eInvalidInput SetPlotConfigurationName new PC3

C# eInvalidInput SetPlotConfigurationName new PC3

snappyjazz
Collaborator Collaborator
324 Views
0 Replies
Message 1 of 1

C# eInvalidInput SetPlotConfigurationName new PC3

snappyjazz
Collaborator
Collaborator

Hello,
I have code to print, but it doesn't print quite right. So I created a new PC3 file to use for my print. However now I'm getting an error at the PlotSetValidator.SetPlotConfiguration line. It's a runtime error "DB.WriteLine(" (See top screenshot).

 

Without an certainty I think this might be because the media dropdown is greyed out when using this pc3 to print (See 2nd screeshot). The SetPlotConfiguration command is trying to specify media where it can't.

 

Is there a way to print with custom pc3 files where the media can't be changed?

 

snappyjazz_0-1741717548802.png

 

snappyjazz_1-1741717561527.png

 

 

namespace AutocadAddinC.EZ_Print_Commands
{
    class FitToC
    {
        // Fit drawing to C size Print Command
        public static void Emp_FitToC()
        {

            // Exit if printer is busy
            if (CadPrint.PlotFactory.ProcessPlotState != CadPrint.ProcessPlotState.NotPlotting) 
            { g_AcDoc.Editor.WriteMessage($"\nAnother plot is in progress.\\n\""); DB.WriteLine($"\nAnother plot is in progress.\n"); return; }
            // Exit if not paper space
            if (g_ActiveLayout.Layout.ModelType == true) 
            { g_AcDoc.Editor.WriteMessage($"\nThis command is setup to print from paperspace."); DB.WriteLine($"\nThis command is setup to print from paperspace.\n"); return; }
            // Get and set the BackgroundPlot system variable value
            Object backPlot = CadApp.Application.GetSystemVariable("BACKGROUNDPLOT"); CadApp.Application.SetSystemVariable("BACKGROUNDPLOT", 0);
            // Get and set the plot config system variable value
            Object SysCfg = CadApp.Application.GetSystemVariable("SYSPLOTCFG"); CadApp.Application.SetSystemVariable("SYSPLOTCFG", 1);
            //DB.WriteLine($"Updated System Variable (sysplotcfg): {CadApp.Application.GetSystemVariable("SYSPLOTCFG")}");

            CadDBS.Transaction Trans = g_AcDatBas.TransactionManager.StartTransaction();
            CadDBS.BlockTableRecord BlTblRec = (CadDBS.BlockTableRecord)Trans.GetObject(g_AcDatBas.CurrentSpaceId, CadDBS.OpenMode.ForRead);
            CadPrint.PlotInfo PlotInfo = new CadPrint.PlotInfo();
            CadDBS.PlotSettings PlSet = new CadDBS.PlotSettings(g_ActiveLayout.Layout.ModelType);
            CadDBS.PlotSettingsValidator PlSetVal = CadDBS.PlotSettingsValidator.Current;

            //try
            //{
                PlotInfo.Layout = BlTblRec.LayoutId;

                // API makes sure that the new "plotsettings" is initialized correctly.
                CadDBS.DBDictionary plSets = (CadDBS.DBDictionary)Trans.GetObject(g_AcDatBas.PlotSettingsDictionaryId, CadDBS.OpenMode.ForRead);

                // Establish plot setup name
                string PlSetName = "EZ-Print-DD_Plotter-C-Scale_To_Fit";
            //DB.WriteLine($"\n...\tPlot Style: {PlSetName}\n");

            #region copy page setup from layout
            // Create a new PlotSettings object for: 
            //    true - model space, false - named layout
            PlSet = new CadDBS.PlotSettings(g_ActiveLayout.Layout.ModelType); //<-- not used when copy and pasted
                // Use CopyFrom property of the plotsetting to initialize it on the layout
                PlSet.CopyFrom(g_ActiveLayout.Layout); // API makes sure that the new "PlotSettings" is initialized correctly, by copying the existing one.

                // Set the name of the Plot Settings (Page Setup)
                PlSet.PlotSettingsName = PlSetName;

                // Add to the plot settings dictionary (Adds to the drawing database)
                PlSet.AddToPlotSettingsDictionary(g_AcDatBas);

                // Adds the plot settings to the transaction
                Trans.AddNewlyCreatedDBObject(PlSet, true);

                // Refreshing the plot settings with plot settings validator
                PlSetVal.RefreshLists(PlSet);
            #endregion

            // Establish plotter and sheet
            //PlSetVal.SetPlotConfigurationName(PlSet, g_PP.DdPlotterC, g_PPS.DD_Arch_C);
            PlSetVal.SetPlotConfigurationName(PlSet, "SysPrint_DD_ENG_ARCH_C", "4444 458 611");
            DB.WriteLine($"\n...\tPlotter: {g_PP.DdPlotter} | Paper: {g_PPS.DD_Arch_C}\n");

            #region AutoCad Print Dialog Settings
            // Rotate 90 degrees
            //PlSetVal.SetPlotRotation(PlSet, CadDBS.PlotRotation.Degrees090);
            //PlSetVal.SetPlotRotation(PlSet, CadDBS.PlotRotation.Degrees270); // Landscape
            //PlSetVal.SetPlotRotation(PlSet, CadDBS.PlotRotation.Degrees180); // Portrait

            PlSetVal = CadDBS.PlotSettingsValidator.Current; //<-- not used when copy and pasted
                PlSet.ShowPlotStyles = true;
                PlSet.ShadePlot = CadDBS.PlotSettingsShadePlotType.AsDisplayed;
                PlSet.ShadePlotResLevel = CadDBS.ShadePlotResLevel.Normal;
                PlSet.ShadePlotCustomDpi = 300;
                PlSet.PlotHidden = false;
                PlSet.PrintLineweights = false;
                PlSet.ScaleLineweights = false;
                PlSet.DrawViewportsFirst = false;
                //PlSet.SetPaperOrientation(true); // < --Creates a match between plot settings and page setup
                //PlSet.PaperOrientation = CadDBS.PaperOrientationStates.True;
                //PlSetVal.SetPlotPaperUnits(PlSet, CadDBS.PlotPaperUnit.Inches)
                //PlSetVal.SetCustomPrintScale(PlSet, ScaleConv) //<--Used with Layout plot type
                //PlSetVal.SetPlotType(PlSet, CadDBS.PlotType.Layout)
                //PlSetVal.SetPlotWindowArea(PlSet, Layout.Limits) //<--Used with Window plot type
                //PlSetVal.SetPlotType(PlSet, CadDBS.PlotType.Window)
                PlSetVal.SetPlotType(PlSet, CadDBS.PlotType.Extents);
                PlSetVal.SetStdScaleType(PlSet, CadDBS.StdScaleType.ScaleToFit); //<-- Used with Window Plot Type. This is greyed out when using layout plot type
                PlSetVal.SetPlotCentered(PlSet, true); //<-- Center is greyed out when plot area (Type) is set to "Layout"
                //PlSetVal.SetPlotOrigin(PlSet, new CadGeo.Point2d(0, 0)); //<--overwrites the centered option if after.

                // Validate that the style exists and switch to it.
                if (PlSetVal.GetPlotStyleSheetList().Contains(g_PS.Monochrome.ToString())) { PlSetVal.SetCurrentStyleSheet(PlSet, g_PS.Monochrome.ToString()); } else { DB.WriteLine($"\nCouldn't load {g_PS.Monochrome.ToString()} style.\n"); }
                #endregion

                // Zoom to show the whole paper
                PlSetVal.SetZoomToPaperOnUpdate(PlSet, true);

                //Add these plot settings to the plot settings dictionary
                PlSet.AddToPlotSettingsDictionary(g_AcDatBas);

                // Refresh the plot settings with plot settings validator
                PlSetVal.RefreshLists(PlSet);

                // Update the plot info with the plot settings
                PlotInfo.OverrideSettings = PlSet;
                CadPrint.PlotInfoValidator PlotInfoVal = new CadPrint.PlotInfoValidator();
                PlotInfoVal.MediaMatchingPolicy = CadPrint.MatchingPolicy.MatchEnabled;
                PlotInfoVal.Validate(PlotInfo);

                // Plot the sheet
                PlotWithDialog(ref PlotInfo, ref Trans);

                g_ActiveLayout.Layout.Dispose();
                Trans.Commit();
                PlSet.Dispose();
                PlSetVal.Dispose();

                // Regenerate the document
                g_AcDoc.Editor.Regen();

                // Restore the previous value for the Backgroundplot system variable
                CadApp.Application.SetSystemVariable("BACKGROUNDPLOT", backPlot);
                // Restor the previous value for the plot config system variable
                CadApp.Application.SetSystemVariable("SYSPLOTCFG", SysCfg);

            //}
            //catch (System.Exception ex)
            //{
            //    // Restore the previous value for the Backgroundplot system variable
            //    CadApp.Application.SetSystemVariable("BACKGROUNDPLOT", backPlot);
            //    // Restor the previous value for the plot config system variable
            //    CadApp.Application.SetSystemVariable("SYSPLOTCFG", SysCfg);
            //    g_AcDoc.Editor.WriteMessage($"\nCouldn//t complete the print function.");
            //    DB.WriteLine($"Had to exit early...\n");
            //    Trans.Abort();
            //    return;
            //}

            DB.WriteLine($"\nEnded...\n");
        }
    }
}

 

 

0 Likes
325 Views
0 Replies
Replies (0)