Announcement

Collapse
No announcement yet.

Printing Events

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Printing Events

    I'm trying to print colour and greyscale pdf's to different folders. My code runs fine from separate commands however when run in the same command only1 pdf is created I assume because revit is busy printing as it works if interrupted via a taskdialog... I've tried setting a global IsPrinting variable in ViewPrinting (T) & ViewPrinted (F) events with no luck. Any tips here? Happy to post code if it helps... Thanks. 

    #2
    Well, it would help to see the code and look at what you're doing
    Martijn de Riet
    Professional Revit Consultant | Revit API Developer
    MdR Advies
    Planta1 Revit Online Consulting

    Comment


      #3
      This is what I have so far I think I need to be using the PDFCreator com object / events to tell when the file is saved however may need to use a timer as in the PDFCreator sample... Seems trick but think im close...

      command...

      Code:
      [Transaction(TransactionMode.Manual)]
          [Regeneration(RegenerationOption.Manual)]
          public class Print : IExternalCommand
          {
              public Result Execute(
                ExternalCommandData commandData,
                ref string message,
                ElementSet elements)
              {
       
                  Utils.PrintPDF(Utils.Document.ActiveView, false);
      
      
                  while (Utils.ReadyState)
                  {
                      Utils.PrintPDF(Utils.Document.ActiveView, true);
                      break; 
                  }
      
                  return Result.Succeeded;
              }
          }


      main print routine
      Code:
      public static void PrintPDF(View view, bool colour)
              {
                  if (PrintManager == null)
                  {
                      PrintManager = Document.PrintManager;
                      PrintManager.PrintRange = PrintRange.Current;
                  }
                 
      
                  string folder = "Colour";
                  if (!colour) folder = "Greyscale";
                  folder = Path.Combine(DocumentPath(), @"Export\PDF", folder);
      
                  if (view.ViewType != ViewType.DrawingSheet)
                  {
                      TaskDialog.Show("PrintPDF", "ViewType != DrawingSheet");
                      return;
                  }
      
                  var sheet = (ViewSheet)view;
                  string file = sheet.SheetNumber + "-" + sheet.Name;
      
                  SetPDFCreator(folder, file);
                  if (!SetPrintSettings(colour ? "PDFCreator A1 - CLR" : "PDFCreator A1 - GSC"))
                  {
                      TaskDialog.Show("PrintPDF", "Unable to set Print Settings");
                      return;
                  }
      
                  string fullpath = Path.Combine(folder, file) + ".pdf";
      
                  PrintManager.PrintToFile = true;
                  PrintManager.PrintToFileName = fullpath;
                  PrintManager.Apply();
      
                  if (File.Exists(fullpath)) File.Delete(fullpath);
      
                  if (!File.Exists(fullpath))
                  {
                      ReadyState = false;
                      bool ok = PrintManager.SubmitPrint(view);
                      
      
                      if (!ok){
                          TaskDialog.Show("PrintPDF", fullpath + " DID NOT PRINT!");
                          return;
                      }
                  }
      
              }


      Code:
      public static bool SetPrintSettings(string name)
              {
                  foreach (Element ps in Document.PrintSettings)
                  {
                      if (ps.Name == name)
                      {
                          if (PrintManager.PrintSetup.CurrentPrintSetting != (IPrintSetting) ps)
                          {
                              var trans = new Transaction(Document);
                              trans.Start("SetPrintSettings");
                              PrintManager.PrintSetup.CurrentPrintSetting = (IPrintSetting) ps;
                              trans.Commit();
                              return true;
                          }
                          return true;
                      }
                  }
      
                  return false;
              }

      can do this with comm object...

      Code:
      public static void SetPDFCreator(string folder, string file)
              {
                      RegistryKey pKey = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("PDFCreator").OpenSubKey("Program", true);
                      pKey.SetValue("AutosaveDirectory", folder);
                      pKey.SetValue("AutosaveFilename", file);
                      pKey.Close();
                  }
              }



      this seems to get called before PDFCreator has actually saved the file I think...
      Code:
      void ViewPrinted(object sender, ViewPrintedEventArgs e)
              {
                  Utils.IsPrinting = false;
              }
      
              void ViewPrinting(object sender, ViewPrintingEventArgs e)
              {
                  Utils.IsPrinting = true;
              }

      Comment

      Related Topics

      Collapse

      Working...
      X