Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error message on save print setup: The <In-Session> print setup cannot be saved.

2 REPLIES 2
Reply
Message 1 of 3
ottosson_mathias
703 Views, 2 Replies

Error message on save print setup: The <In-Session> print setup cannot be saved.

I'm trying to write a pdf-printer with the following code:

            using (var transaction = new Transaction(doc, "Print settings"))
            {
                transaction.Start();

                try
                {
                    var printManager = doc.PrintManager;
                    var currentPrintSettings = printManager.PrintSetup.InSession;

                    printManager.SelectNewPrintDriver(printSettings.SelectedPrinter);
                    printManager.PrintToFile = true;

                    var printParams = printManager.PrintSetup.CurrentPrintSetting.PrintParameters;
                    printParams.PaperSize = GetPaperSize(printManager.PaperSizes, printSettings.SelectedPaperSize);
                    printParams.PageOrientation = GetOrientation(printSettings.SelectedOrientation);
                    printParams.ColorDepth = GetColor(printSettings.SelectedColor);
                    printParams.ZoomType = ZoomType.Zoom;
                    printParams.Zoom = Convert.ToInt32(printSettings.SelectedZoomLevel);
                    printParams.HiddenLineViews = HiddenLineViewsType.VectorProcessing;
                    printParams.PaperPlacement = PaperPlacementType.Center;
                    printParams.HideCropBoundaries = true;
                    printParams.HideReforWorkPlanes = true;
                    printParams.HideScopeBoxes = true;
                    printParams.HideUnreferencedViewTags = false;
                    printParams.MaskCoincidentLines = false;
                    printParams.ViewLinksinBlue = false;
                    printParams.ReplaceHalftoneWithThinLines = false;

                    printManager.PrintSetup.Save();

                    foreach (var sheet in elementlist)
                    {
                        var fileLocation = $@"{folderDialog.SelectedPath}\{sheet.Name}.pdf";

                        DeleteFile(fileLocation);

                        printManager.PrintToFileName = fileLocation;

                        printManager.SubmitPrint(sheet)
                    }

                    transaction.RollBack();
                }
                catch (Exception ex)
                {
                    transaction.RollBack();

                    TaskDialog.Show("Error", ex.Message);
                }

Sometimes this works, but sometimes I get the error message "The <In-Session> print setup cannot be saved.".

 

What am I doing wrong?

2 REPLIES 2
Message 2 of 3

So I found a workaround. I don't know if this is a good idea or not, maybe someone can tell me how it should be done.

 

Instead of

printManager.PrintSetup.Save();

I do this instead:

printManager.PrintSetup.SaveAs("tempSettings");

It feels a bit hacky but seems to work for now at least.

Message 3 of 3

Worked like a charm for me - thanks! 🙂 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community