<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem at publish multiple layouts in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/problem-at-publish-multiple-layouts/m-p/7877714#M26762</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need again advice from knowledge programmers &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;. I have a drawing where i defind print settings layout… then i use the function for multiple publish. I was inspired function for multiple publish here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/plot-dwg-to-pdf-for-multiple-layouts-in-c/td-p/5849145" target="_blank"&gt;function for multiple publish&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All parameters which i sett are in layouts objects but function for public use another pc3 file (AutoCAD PDF (General Documentation).pc3) - no matter which pc3 file i sett. When i published manually then all is correct. How can i force publish layouts with my pc3 file through API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.IO;
namespace AutoCAD.Command
{
    public class Commands
    {

        [CommandMethod("NewDrawing", CommandFlags.Session)]
          public static void NewDrawing()
        {
            string strTemplatePath = "acad.dwt";
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document acDoc = acDocMgr.Add(strTemplatePath);
        }




        [CommandMethod("PrintMultiSheetsPdf", CommandFlags.Session)]
        public void PrintMultiSheetsPdf()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;   //mother autocad document
                PromptResult promptResult = doc.Editor.GetString("\nEnter the parameter: ");  //hardcode user command from anothert side
                if (promptResult.Status != PromptStatus.OK)
                    return;
                if (promptResult.StringResult.Contains(";") != true)
                {
                    doc.Editor.WriteMessage($"Input parametr: {promptResult.StringResult} is invalid. Right format - (destination path;source file path).");
                    return;
                }
                string[] inputParametrs = promptResult.StringResult.Split(';');     //input parameters: destination path and source file path

                if (File.Exists(inputParametrs[1]) != true)
                {
                    doc.Editor.WriteMessage($"Source file: {inputParametrs[1]} does not exist.");
                    return;
                }

                if (!System.IO.Directory.Exists(inputParametrs[0]))
                    System.IO.Directory.CreateDirectory(inputParametrs[0]);

                bool isValidate = false;
                string PaperSize = "ISO full bleed A3 (420.00 x 297.00 MM)";
                string Plottername = "DWG To PDF.pc3";
                string PlotStyleName = "PDF files for instructions.ctb";
                CustomScale customScale = new CustomScale(1, 1);
                string PaperCode = string.Empty;
                int i = 0;
                bool UsePlotStyles = true;
                bool UseLineWeights = true;
                bool ScaleLineWeights = false;
                bool HidePaperspaceObjects = false;
                bool CenterPlot = true;
                foreach (string plotDevice in PlotSettingsValidator.Current.GetPlotDeviceList())    // check available printer, 
                {
                    if (Plottername.Trim().ToUpper() == plotDevice.Trim().ToUpper())
                    {
                        isValidate = true;
                        break;
                    }
                }
                if (isValidate == false)
                {
                    doc.Editor.WriteMessage($"Selected printer: {Plottername} is not installed on this computer. Contact your system administrator");
                    return;
                }
                using (PlotSettings acPlSet = new PlotSettings(true))    //try to find right paper value because it is no possible to set GetLocaleMediaName(this value is only show in UI)
                {
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    acPlSetVdr.SetPlotConfigurationName(acPlSet, Plottername, null);
                    foreach (string mediaName in acPlSetVdr.GetCanonicalMediaNameList(acPlSet))
                    {
                        if (PaperSize.Trim().ToUpper() == acPlSetVdr.GetLocaleMediaName(acPlSet, i).Trim().ToUpper())
                        {
                            PaperCode = mediaName;
                            break;
                        }
                        i++;
                    }
                }
                if (PaperCode == string.Empty)
                {
                    doc.Editor.WriteMessage($"Selected papersize: {PaperSize} is not available on selected printer. Contact your system administrator");
                    return;
                }
                List&amp;lt;Layout&amp;gt; layouts = new List&amp;lt;Layout&amp;gt;();
                using (Database db = new Database(false, true))
                {
                    if (Functions.IsFileAvailable(new FileInfo(inputParametrs[1])) != true)
                    {
                        doc.Editor.WriteMessage($" File: {inputParametrs[1]} is already locked by some other process.");
                        return;
                    }
                    db.ReadDwgFile(inputParametrs[1], System.IO.FileShare.ReadWrite, true, ""); // open select DWG file
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBDictionary layoutDict = (DBDictionary)db.LayoutDictionaryId.GetObject(OpenMode.ForRead);
                        foreach (DBDictionaryEntry entry in layoutDict)
                        {
                            if (entry.Key.Trim().ToUpper() != "MODEL") // set all layouts except model
                            {
                                Layout acLayout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                                using (PlotSettings currentPlSet = new PlotSettings(acLayout.ModelType))
                                {
                                    currentPlSet.CopyFrom(acLayout);
                                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                                    acPlSetVdr.SetPlotConfigurationName(currentPlSet, Plottername, PaperCode);
                                    acPlSetVdr.SetPlotPaperUnits(currentPlSet, PlotPaperUnit.Millimeters);
                                    acPlSetVdr.SetPlotWindowArea(currentPlSet, new Extents2d(10, 8.5, 430, 288.5));
                                    acPlSetVdr.SetPlotType(currentPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                                    acPlSetVdr.SetPlotCentered(currentPlSet, CenterPlot);
                                    acPlSetVdr.SetPlotRotation(currentPlSet, PlotRotation.Degrees000);
                                    acPlSetVdr.SetPlotOrigin(currentPlSet, new Point2d(0, 0));
                                    currentPlSet.ShowPlotStyles = UsePlotStyles;
                                    try { acPlSetVdr.SetCurrentStyleSheet(currentPlSet, PlotStyleName); }
                                    catch
                                    {
                                        doc.Editor.WriteMessage($"AutoCAD does not contains file - {PlotStyleName} .");
                                        return;
                                    }
                                  
                                    currentPlSet.PlotHidden = HidePaperspaceObjects;
                                    currentPlSet.PrintLineweights = UseLineWeights;
                                    currentPlSet.ScaleLineweights = ScaleLineWeights;
                                    acPlSetVdr.SetCustomPrintScale(currentPlSet, customScale);
                                    acPlSetVdr.SetZoomToPaperOnUpdate(currentPlSet, true);    // Zoom to show the whole paper
                                    acLayout.UpgradeOpen();   // Update the layout
                                    acLayout.CopyFrom(currentPlSet);
                                }
                                layouts.Add(acLayout);
                            }
                        }
                        tr.Commit();
                    }
                    try  //try to delte old file
                    {
                        if (System.IO.File.Exists(Path.ChangeExtension(inputParametrs[1], "pdf")))
                            System.IO.File.Delete(Path.ChangeExtension(inputParametrs[1], "pdf"));
                    }
                    catch
                    {
                        doc.Editor.WriteMessage($"There is no possible delete old file - {Path.ChangeExtension(inputParametrs[1], "pdf")} .");
                        return;
                    }
                    doc.Editor.Regen();
                    db.SaveAs(inputParametrs[1], DwgVersion.Current);   //save modify print settings back to layout
                }
                layouts.Sort((l1, l2) =&amp;gt; l1.TabOrder.CompareTo(l2.TabOrder)); // Sort selected layouts to right order
                MultiSheetsPdf plotter = new MultiSheetsPdf(inputParametrs[0], layouts, inputParametrs[1]); //prepare plot
                plotter.Publish();  //plot selected laouys
            }
            catch { return; }
        }
    }

}&lt;/PRE&gt;</description>
    <pubDate>Fri, 23 Mar 2018 07:55:47 GMT</pubDate>
    <dc:creator>BestFriendCZ</dc:creator>
    <dc:date>2018-03-23T07:55:47Z</dc:date>
    <item>
      <title>Problem at publish multiple layouts</title>
      <link>https://forums.autodesk.com/t5/net-forum/problem-at-publish-multiple-layouts/m-p/7877714#M26762</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I need again advice from knowledge programmers &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;. I have a drawing where i defind print settings layout… then i use the function for multiple publish. I was inspired function for multiple publish here:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/net/plot-dwg-to-pdf-for-multiple-layouts-in-c/td-p/5849145" target="_blank"&gt;function for multiple publish&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All parameters which i sett are in layouts objects but function for public use another pc3 file (AutoCAD PDF (General Documentation).pc3) - no matter which pc3 file i sett. When i published manually then all is correct. How can i force publish layouts with my pc3 file through API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.IO;
namespace AutoCAD.Command
{
    public class Commands
    {

        [CommandMethod("NewDrawing", CommandFlags.Session)]
          public static void NewDrawing()
        {
            string strTemplatePath = "acad.dwt";
            DocumentCollection acDocMgr = Application.DocumentManager;
            Document acDoc = acDocMgr.Add(strTemplatePath);
        }




        [CommandMethod("PrintMultiSheetsPdf", CommandFlags.Session)]
        public void PrintMultiSheetsPdf()
        {
            try
            {
                Document doc = Application.DocumentManager.MdiActiveDocument;   //mother autocad document
                PromptResult promptResult = doc.Editor.GetString("\nEnter the parameter: ");  //hardcode user command from anothert side
                if (promptResult.Status != PromptStatus.OK)
                    return;
                if (promptResult.StringResult.Contains(";") != true)
                {
                    doc.Editor.WriteMessage($"Input parametr: {promptResult.StringResult} is invalid. Right format - (destination path;source file path).");
                    return;
                }
                string[] inputParametrs = promptResult.StringResult.Split(';');     //input parameters: destination path and source file path

                if (File.Exists(inputParametrs[1]) != true)
                {
                    doc.Editor.WriteMessage($"Source file: {inputParametrs[1]} does not exist.");
                    return;
                }

                if (!System.IO.Directory.Exists(inputParametrs[0]))
                    System.IO.Directory.CreateDirectory(inputParametrs[0]);

                bool isValidate = false;
                string PaperSize = "ISO full bleed A3 (420.00 x 297.00 MM)";
                string Plottername = "DWG To PDF.pc3";
                string PlotStyleName = "PDF files for instructions.ctb";
                CustomScale customScale = new CustomScale(1, 1);
                string PaperCode = string.Empty;
                int i = 0;
                bool UsePlotStyles = true;
                bool UseLineWeights = true;
                bool ScaleLineWeights = false;
                bool HidePaperspaceObjects = false;
                bool CenterPlot = true;
                foreach (string plotDevice in PlotSettingsValidator.Current.GetPlotDeviceList())    // check available printer, 
                {
                    if (Plottername.Trim().ToUpper() == plotDevice.Trim().ToUpper())
                    {
                        isValidate = true;
                        break;
                    }
                }
                if (isValidate == false)
                {
                    doc.Editor.WriteMessage($"Selected printer: {Plottername} is not installed on this computer. Contact your system administrator");
                    return;
                }
                using (PlotSettings acPlSet = new PlotSettings(true))    //try to find right paper value because it is no possible to set GetLocaleMediaName(this value is only show in UI)
                {
                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                    acPlSetVdr.SetPlotConfigurationName(acPlSet, Plottername, null);
                    foreach (string mediaName in acPlSetVdr.GetCanonicalMediaNameList(acPlSet))
                    {
                        if (PaperSize.Trim().ToUpper() == acPlSetVdr.GetLocaleMediaName(acPlSet, i).Trim().ToUpper())
                        {
                            PaperCode = mediaName;
                            break;
                        }
                        i++;
                    }
                }
                if (PaperCode == string.Empty)
                {
                    doc.Editor.WriteMessage($"Selected papersize: {PaperSize} is not available on selected printer. Contact your system administrator");
                    return;
                }
                List&amp;lt;Layout&amp;gt; layouts = new List&amp;lt;Layout&amp;gt;();
                using (Database db = new Database(false, true))
                {
                    if (Functions.IsFileAvailable(new FileInfo(inputParametrs[1])) != true)
                    {
                        doc.Editor.WriteMessage($" File: {inputParametrs[1]} is already locked by some other process.");
                        return;
                    }
                    db.ReadDwgFile(inputParametrs[1], System.IO.FileShare.ReadWrite, true, ""); // open select DWG file
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        DBDictionary layoutDict = (DBDictionary)db.LayoutDictionaryId.GetObject(OpenMode.ForRead);
                        foreach (DBDictionaryEntry entry in layoutDict)
                        {
                            if (entry.Key.Trim().ToUpper() != "MODEL") // set all layouts except model
                            {
                                Layout acLayout = (Layout)tr.GetObject(entry.Value, OpenMode.ForRead);
                                using (PlotSettings currentPlSet = new PlotSettings(acLayout.ModelType))
                                {
                                    currentPlSet.CopyFrom(acLayout);
                                    PlotSettingsValidator acPlSetVdr = PlotSettingsValidator.Current;
                                    acPlSetVdr.SetPlotConfigurationName(currentPlSet, Plottername, PaperCode);
                                    acPlSetVdr.SetPlotPaperUnits(currentPlSet, PlotPaperUnit.Millimeters);
                                    acPlSetVdr.SetPlotWindowArea(currentPlSet, new Extents2d(10, 8.5, 430, 288.5));
                                    acPlSetVdr.SetPlotType(currentPlSet, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                                    acPlSetVdr.SetPlotCentered(currentPlSet, CenterPlot);
                                    acPlSetVdr.SetPlotRotation(currentPlSet, PlotRotation.Degrees000);
                                    acPlSetVdr.SetPlotOrigin(currentPlSet, new Point2d(0, 0));
                                    currentPlSet.ShowPlotStyles = UsePlotStyles;
                                    try { acPlSetVdr.SetCurrentStyleSheet(currentPlSet, PlotStyleName); }
                                    catch
                                    {
                                        doc.Editor.WriteMessage($"AutoCAD does not contains file - {PlotStyleName} .");
                                        return;
                                    }
                                  
                                    currentPlSet.PlotHidden = HidePaperspaceObjects;
                                    currentPlSet.PrintLineweights = UseLineWeights;
                                    currentPlSet.ScaleLineweights = ScaleLineWeights;
                                    acPlSetVdr.SetCustomPrintScale(currentPlSet, customScale);
                                    acPlSetVdr.SetZoomToPaperOnUpdate(currentPlSet, true);    // Zoom to show the whole paper
                                    acLayout.UpgradeOpen();   // Update the layout
                                    acLayout.CopyFrom(currentPlSet);
                                }
                                layouts.Add(acLayout);
                            }
                        }
                        tr.Commit();
                    }
                    try  //try to delte old file
                    {
                        if (System.IO.File.Exists(Path.ChangeExtension(inputParametrs[1], "pdf")))
                            System.IO.File.Delete(Path.ChangeExtension(inputParametrs[1], "pdf"));
                    }
                    catch
                    {
                        doc.Editor.WriteMessage($"There is no possible delete old file - {Path.ChangeExtension(inputParametrs[1], "pdf")} .");
                        return;
                    }
                    doc.Editor.Regen();
                    db.SaveAs(inputParametrs[1], DwgVersion.Current);   //save modify print settings back to layout
                }
                layouts.Sort((l1, l2) =&amp;gt; l1.TabOrder.CompareTo(l2.TabOrder)); // Sort selected layouts to right order
                MultiSheetsPdf plotter = new MultiSheetsPdf(inputParametrs[0], layouts, inputParametrs[1]); //prepare plot
                plotter.Publish();  //plot selected laouys
            }
            catch { return; }
        }
    }

}&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 07:55:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/problem-at-publish-multiple-layouts/m-p/7877714#M26762</guid>
      <dc:creator>BestFriendCZ</dc:creator>
      <dc:date>2018-03-23T07:55:47Z</dc:date>
    </item>
  </channel>
</rss>

