PrinterManager PrintSetup do not apply settings

PrinterManager PrintSetup do not apply settings

Anonymous
Not applicable
3,974 Views
7 Replies
Message 1 of 8

PrinterManager PrintSetup do not apply settings

Anonymous
Not applicable

Hi.

 

I creatint Revit Addin and need print pdf files. I Use PDFCreator virtual printer. And faced with problem when i set parameters to print manager, for example :

printer.SelectNewPrintDriver(printerNames.FirstOrDefault(g=>g.Contains("PDFCreator")));
printer.PrintToFileName = sPath+fileName;
printer.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = a4Ps;
printer.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Landscape;
printer.PrintSetup.InSession.PrintParameters.PageOrientation = PageOrientationType.Landscape;
printer.Apply();

 when i call SubmitPrint a get pdf with Portrait orientation. All parameters get from print dialog. If i print from print dialog (Ctrl+P) and check Landscape orientation,scale 100% and Center position. Everythig printed correct. And after that i can use ,y PDFCreator from code and they printed correct too. 

I suppese that Apply() method didn't work correctly. My PArameters didn't save and passed to PDFCreator from macros.

Does anybody get such problems?

 

Thanks in advance.

 

P.S.Sorry for bad english.

 

0 Likes
3,975 Views
7 Replies
Replies (7)
Message 2 of 8

saikat
Autodesk
Autodesk

Hi

 

We did have some other API user mention that the Print API settings did not affect the output. We had brought this behavior to the Dev Team's attention then. Your post here seems to mention the same behavior as well.

 



Saikat Bhattacharya
Senior Manager - Technology Consulting
0 Likes
Message 3 of 8

Anonymous
Not applicable

Is there any workaround? I need to print correct from macros.

0 Likes
Message 4 of 8

akira.kudo
Alumni
Alumni

You can use PrintSetup.Save() or SaveAs() method this case like code below.(See also attached jpg) They can be called to make Revit remembering the print setup changes.

 

If the current Print setup is “In-Session”, this cannot be saved by Save().

You can save it to your own print setup, or save as to a new print setup.

 

<code_begin>

namespace RevitAddin1

{

    [Transaction(TransactionMode.Manual)]

    public class Command : IExternalCommand

    {

        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, 

            ref string message, Autodesk.Revit.DB.ElementSet elements)

        {

            // Filter all printable views in current document and print them,

            // the print will raise events registered in controlled application.

            // After run this external command please refer to log files under folder of this assembly.

            Document document = commandData.Application.ActiveUIDocument.Document;

            UIDocument uidocument = commandData.Application.ActiveUIDocument;

 

            using (Transaction tx = new Transaction(document))

            {

                tx.Start("Transaction Name");

 

                PrintManager pm = document.PrintManager;

                pm.SelectNewPrintDriver("CutePDF writer");

                pm.PrintRange = PrintRange.Current;

                pm.CombinedFile = true;

                pm.PrintToFile = true;

                pm.PrintSetup.CurrentPrintSetting.PrintParameters.PageOrientation = PageOrientationType.Portrait;

                pm.PrintSetup.SaveAs("test");

                pm.Apply();

 

                tx.Commit();

            }

 

            //

            // return succeed by default

            return Autodesk.Revit.UI.Result.Succeeded;

        }

    }

}

<code_end>

 

Hope this helps,





Akira Kudo

Developer Technical Services

Autodesk Developer Network


0 Likes
Message 5 of 8

aricke59
Enthusiast
Enthusiast

This seems to still be the case with Revit 2015.

 

The only way you can save your In-Session print settings, e.g., so that it could be accessible via the normal Revit print dialog, is to do a saveas. This has to be one, out of many, of the least intuitive things in the printmanager.

 

Note that once you have done the saveas, you can then delete the newly saved printsetup.

0 Likes
Message 6 of 8

Extraneous
Advisor
Advisor

@akira.kudo Revit 2017, are there any fixes? This code does not work: set to shades of gray, printed as color. The same bug in the SDK Sample ViewPrinter (if you select "setup - <in-session>" and "black lines", color is printed anyway). "Save" or "save as" is not suitable, because I want to print without opening a transaction.

public void StartPrint()
{
	Document doc = this.ActiveUIDocument.Document;
	List<ViewSheet> sheets = new FilteredElementCollector(doc)
		.OfClass(typeof(ViewSheet))
		.Cast<ViewSheet>()
		.ToList();

	foreach (ViewSheet sheet in sheets)
	{
		Document curDoc = sheet.Document;
		PrintManager pManager = curDoc.PrintManager;
		pManager.SelectNewPrintDriver("PDFCreator");
		pManager.PrintRange = PrintRange.Current;
		pManager.Apply();

		pManager.PrintSetup.CurrentPrintSetting = pManager.PrintSetup.InSession;
		PrintParameters pps = pManager.PrintSetup.CurrentPrintSetting.PrintParameters;
		pps.PaperPlacement = PaperPlacementType.Center;
		pps.ZoomType = ZoomType.FitToPage;
		pps.ColorDepth = ColorDepthType.GrayScale;
		pManager.Apply();

		pManager.SubmitPrint(sheet); //print in colors, no grayscales
	}
}

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

0 Likes
Message 7 of 8

Archigrafix_Norge
Advocate
Advocate

The SDK example (viewprinter) is suppose to mimic the Print Dialog but it does not work when it comes to the color properties. It works fine in regards of the other properties.

 

This looks like a bug in the API and should be addressed by Autodesk. 

 

Does anybody has a workaround to produce greyscale prints?


Luis Santos

archi systems as

0 Likes
Message 8 of 8

2319837182
Explorer
Explorer

printManager.PrintSetup.Save();        //it works