Exemple #1
0
        private static PrintSetting LoadRevitPrintSetting(
            Document doc,
            string size,
            PrintManager pm,
            string printerName,
            bool forceRaster,
            ExportLog log)
        {
            log.AddMessage(Resources.MessageAttemptingToLoadRevitPrintSettings + size);
            PrintSetting ps = GetPrintSettingByName(doc, size, forceRaster);

            if (ps == null)
            {
                log.AddError(null, Resources.ErrorRetrievingRevitPrintSettingsFAILED);
                return(null);
            }

            log.AddMessage(Resources.MessageUsingPrinter + printerName);
            if (!SetPrinterByName(doc, printerName, pm))
            {
                log.AddError(null, Resources.MessageCannotSetPrinter + printerName);
                return(null);
            }

            return(ps);
        }
Exemple #2
0
        ////[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
        public static bool PrintToDevice(
            Document doc,
            string size,
            PrintManager pm,
            string printerName,
            bool forceRaster,
            ExportLog log)
        {
            if (pm == null)
            {
                return(false);
            }

            PrintSetting ps = LoadRevitPrintSetting(doc, size, pm, printerName, forceRaster, log);

            if (ps == null)
            {
                return(false);
            }

            var t = new Transaction(doc, Resources.ApplyPrintSettings);

            t.Start();
            try {
                if (ps.IsValidObject)
                {
                    pm.PrintSetup.CurrentPrintSetting = ps;
                }
                else
                {
                    if (log != null)
                    {
                        log.AddWarning(null, Resources.WarningPrintSetupReadOnly);
                    }
                }
                pm.PrintRange = PrintRange.Current;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.PaperPlacement = PaperPlacementType.Margins;
                pm.PrintSetup.InSession.PrintParameters.PaperPlacement           = PaperPlacementType.Margins;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.MarginType     = MarginType.UserDefined;
                pm.PrintSetup.InSession.PrintParameters.MarginType = MarginType.UserDefined;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.UserDefinedMarginX = 0;
                pm.PrintSetup.InSession.PrintParameters.UserDefinedMarginX           = 0;
                pm.PrintSetup.CurrentPrintSetting.PrintParameters.UserDefinedMarginY = 0;
                pm.PrintSetup.InSession.PrintParameters.UserDefinedMarginY           = 0;
                pm.PrintToFile = false;
                pm.Apply();
                t.Commit();
                return(true);
            } catch (Exception ex) {
                System.Diagnostics.Debug.Print(ex.Message);
                if (log != null)
                {
                    log.AddError(null, ex.ToString());
                }
                t.RollBack();
                return(false);
            }
        }