Author Topic: Re-sending a publish job  (Read 933 times)

0 Members and 1 Guest are viewing this topic.

xenspidey

  • Mosquito
  • Posts: 15
Re-sending a publish job
« on: July 09, 2015, 05:22:59 PM »

This question is semi related to the topic i had posted about here awhile ago.
http://www.theswamp.org/index.php?topic=49233.msg544310#msg544310

I have everything working except for republishing the canceled publish job. line 220 (or 219, I've tried both ways) error out with "System. AccesssViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt." I've been fiddling around with this for two days, anyone have any ideas?


Code - C#: [Select]
  1. using System;
  2. using System.Timers;
  3. using System.Diagnostics;
  4. using System.Collections.Generic;
  5. using System.Windows.Forms;
  6.  
  7. using acApp = Autodesk.AutoCAD.ApplicationServices;
  8. using Autodesk.AutoCAD.Runtime;
  9. using Autodesk.AutoCAD.DatabaseServices;
  10. using Autodesk.AutoCAD.EditorInput;
  11. using Autodesk.AutoCAD.Publishing;
  12. using Autodesk.AutoCAD.PlottingServices;
  13.  
  14. namespace Acad_Startup
  15. {
  16.     public class startup : IExtensionApplication
  17.     {
  18.         public void Initialize()
  19.         {
  20.             PublishEvents m_pe = new PublishEvents();
  21.         }
  22.  
  23.         public void Terminate()
  24.         {
  25.             throw new NotImplementedException();
  26.         }
  27.     }
  28.  
  29.     public class PublishEvents
  30.     {
  31.         public PublishEvents()
  32.         {
  33.             m_bDone = false;
  34.             m_plotStatus = true;
  35.             m_plotContinue = false;
  36.             m_resend = false;
  37.             m_plotMan = new PlotReactorManager();
  38.             Execute();
  39.         }
  40.  
  41.         public static Publisher m_pubMan = acApp.Application.Publisher;
  42.         public static PlotReactorManager m_plotMan;
  43.  
  44.         private bool m_bDone;
  45.         private bool m_plotStatus;
  46.         private bool m_plotContinue;
  47.         private bool m_resend;
  48.         private DsdData m_DsdData = null;
  49.         private PlotConfig m_PlotConfig = null;
  50.         private static System.Timers.Timer mTimer;
  51.  
  52.         public void Execute()
  53.         {
  54.             if (m_bDone == false)
  55.             {
  56.                 m_bDone = true;
  57.             }
  58.  
  59.             try
  60.             {
  61.                 m_pubMan.AboutToBeginPublishing += new AboutToBeginPublishingEventHandler(callback_AboutToBeginPublish);
  62.                 m_plotMan.BeginPlot += new BeginPlotEventHandler(callback_BeginPlot);
  63.                 m_plotMan.PlotCancelled += new PlotCancelledEventHandler(callback_CancelledPlot);
  64.             }
  65.             catch (System.Exception)
  66.             {
  67.                 throw;
  68.             }
  69.         }
  70.  
  71.         void callback_CancelledPlot(object sender, EventArgs e)
  72.         {
  73.             if (m_resend == true)
  74.             {
  75.                 if (m_DsdData != null && m_PlotConfig != null)
  76.                 {
  77.                     resendPublish(m_DsdData, m_PlotConfig);
  78.                 }
  79.                 else
  80.                 {
  81.                     MessageBox.Show("null");
  82.                 }
  83.             }
  84.             m_plotContinue = false;
  85.         }
  86.  
  87.         void callback_BeginPlot(object sender, BeginPlotEventArgs e)
  88.         {
  89.             if (m_plotStatus == true) //plot continues
  90.             {
  91.                 return;
  92.             }
  93.             else if (m_plotStatus == false) //plot is cancelled
  94.             {
  95.                 m_PlotConfig = PlotConfigManager.CurrentConfig;
  96.                 if (m_resend == true)
  97.                 {
  98.                     //cancel publish if Cancel or No is selected from AboutToBeginPublish dialog              
  99.                     PlotProgress m_PlotProgress = e.PlotProgress;
  100.                     m_PlotProgress.PlotCancelStatus = PlotCancelStatus.CanceledByCancelAllButton;
  101.                     m_plotStatus = true;
  102.                 }
  103.             }
  104.         }
  105.  
  106.         void callback_AboutToBeginPublish(object sender, AboutToBeginPublishingEventArgs e)
  107.         {
  108.             if (m_plotContinue == false) //Test to see if publish collate needs to be checked. Needed if coming from resend command
  109.             {
  110.                 m_DsdData = e.DsdData.Copy();
  111.                 string sPubCol = "";
  112.                 int nPubCol = System.Convert.ToInt32(acApp.Application.GetSystemVariable("PUBLISHCOLLATE"));
  113.  
  114.                 if (nPubCol == 1)
  115.                 {
  116.                     sPubCol = "This job will be published as an individual set, is this correct?";
  117.                 }
  118.                 else if (nPubCol == 0)
  119.                 {
  120.                     sPubCol = "This job will be published as seperate sheets, is this correct?";
  121.                 }
  122.  
  123.                 DialogResult frm = MessageBox.Show(sPubCol, "Publish Collate check", MessageBoxButtons.YesNoCancel);
  124.                 if (frm == DialogResult.Yes)
  125.                 {
  126.                     m_plotStatus = true; // set flag to true which will continue plot once print is triggered
  127.                     return;
  128.                 }
  129.                 else if (frm == DialogResult.No)
  130.                 {
  131.                     m_plotStatus = false; // set flag to false which will cancel plot once print is triggered                
  132.                     m_resend = true;
  133.                     if (nPubCol == 1)
  134.                     {
  135.                         acApp.Application.SetSystemVariable("PUBLISHCOLLATE", 0);
  136.  
  137.                     }
  138.                     else if (nPubCol == 0)
  139.                     {
  140.                         acApp.Application.SetSystemVariable("PUBLISHCOLLATE", 1);
  141.                     }
  142.                 }
  143.                 else if (frm == DialogResult.Cancel)
  144.                 {
  145.                     m_plotStatus = false; // set flag to false which will cancel plot once print is triggered                    
  146.                 }
  147.             }
  148.             else
  149.             {
  150.                 MessageBox.Show("made it");
  151.             }
  152.         }
  153.  
  154.         void resendPublish(DsdData m_DsdData, PlotConfig m_PlotConfig)
  155.         {
  156.             m_plotContinue = true;
  157.             m_resend = false;
  158.  
  159.             if (System.IO.File.Exists("c:\\AutoCAD\\temp.dsd"))
  160.             {
  161.                 System.IO.File.Delete("c:\\AutoCAD\\temp.dsd");
  162.             }
  163.  
  164.             m_DsdData.WriteDsd("c:\\AutoCAD\\temp.dsd");
  165.  
  166.             if (System.IO.File.Exists("c:\\AutoCAD\\temp.pc3"))
  167.             {
  168.                 System.IO.File.Delete("c:\\AutoCAD\\temp.pc3");
  169.             }
  170.  
  171.             m_PlotConfig.SaveToPC3("c:\\AutoCAD\\temp.pc3");
  172.             Print();
  173.         }
  174.  
  175.         void Print()
  176.         {          
  177.             mTimer = new System.Timers.Timer(2000);
  178.             mTimer.Elapsed += OnTimer;
  179.             mTimer.Enabled = true;
  180.         }
  181.  
  182.         void OnTimer(object sender, ElapsedEventArgs e)
  183.         {
  184.             mTimer.Elapsed -= OnTimer;
  185.             mTimer.Enabled = false;
  186.             resend();
  187.         }
  188.  
  189.         void resend()
  190.         {
  191.             try
  192.             {
  193.                 using (DsdData dsdDataFile = new DsdData())
  194.                 {
  195.                     dsdDataFile.ReadDsd("c:\\AutoCAD\\temp.dsd");
  196.  
  197.                     int nbSheets = dsdDataFile.NoOfCopies;
  198.                     using (PlotProgressDialog progressDlg = new PlotProgressDialog(false, nbSheets, true))
  199.                     {
  200.                         progressDlg.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Plot API Progress");
  201.                         progressDlg.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
  202.                         progressDlg.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
  203.                         progressDlg.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Job Progress");
  204.                         progressDlg.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
  205.  
  206.                         progressDlg.UpperPlotProgressRange = 100;
  207.                         progressDlg.LowerPlotProgressRange = 0;
  208.  
  209.                         progressDlg.UpperSheetProgressRange = 100;
  210.                         progressDlg.LowerSheetProgressRange = 0;
  211.  
  212.                         progressDlg.IsVisible = true;
  213.  
  214.                         Autodesk.AutoCAD.Publishing.Publisher publisher = acApp.Application.Publisher;
  215.                         Autodesk.AutoCAD.PlottingServices.PlotConfigManager.SetCurrentConfig("c:\\AutoCAD\\temp.pc3");
  216.  
  217.                         try
  218.                         {
  219.                             //publisher.PublishExecute(dsdDataFile, Autodesk.AutoCAD.PlottingServices.PlotConfigManager.CurrentConfig);
  220.                             publisher.PublishDsd("c:\\AutoCAD\\temp.dsd", progressDlg);
  221.                         }
  222.                         catch (System.Exception e)
  223.                         {
  224.                             string excep = "";
  225.                             excep += e.Source.ToString();
  226.                             excep += "\n\n";
  227.                             excep += e.Message.ToString();
  228.                             MessageBox.Show(excep + "\n" + e.ToString());
  229.                         }
  230.                     }
  231.                 }
  232.             }
  233.  
  234.             catch (System.Exception ex)
  235.             {
  236.                 MessageBox.Show(ex.ToString());
  237.             }
  238.         }
  239.     }
  240. }

xenspidey

  • Mosquito
  • Posts: 15
Re: Re-sending a publish job
« Reply #1 on: August 18, 2015, 01:25:59 PM »
I normally wouldn't bump this but it's the only missing piece to this puzzle i have and it's driving me nuts. Does anyone at all have even a slight suggestion? Any way i could explain my problem better?

Thanks,