Print Manager, Papresize, Paper orientation

Print Manager, Papresize, Paper orientation

Anonymous
Not applicable
2,426 Views
8 Replies
Message 1 of 9

Print Manager, Papresize, Paper orientation

Anonymous
Not applicable

Hi

 

I have tried (a lot) to get the right orientation and papresize in a pdf plot

I got the right printer, the right filename

but not the right papersize and orientation, I am usingBoundingBoxUV to get the Sheetsize and from there the orientation of the sheet

that works fine 🙂

 

I have been trying with 3 different pdf printers, without luck 😞

 

My the code looke like this, in this case I am trying to print all shests starting with an "A" to be printet in A3.

 

PrintManager PrintM = OpenDoc.PrintManager;

PrintM.PrintSetup.CurrentPrintSetting = PrintM.PrintSetup.InSession;

PrintM.SelectNewPrintDriver("PDF995"); //("CutePDF Writer")("PDF995")("PDFCreator")

PrintM.PrintToFile = true;

foreach (ViewSheet vs in new FilteredElementCollector(OpenDoc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>())

{

if (vs.SheetNumber[0].ToString() != "A")

{

PDF_Name = vs.SheetNumber.Substring(0, vs.SheetNumber.Length - 3);

PrintM.PrintToFileName = DistFolder + @"\" + Department_number.AsString() + "-" + PDF_Name;

PaperSizeSet PaperSizeSet = PrintM.PaperSizes;

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

foreach (PaperSize PS in PaperSizeSet) // Finding the right papersize in the printer

{

if (PS.Name.ToString() == "A3")

{

PrintM.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize = PS;

break;

}

}

PrintM.Apply();

PrintM.SubmitPrint(vs);

}

} // end of foreach (ViewSheet vs........

 

What do I do wrong ??

 

Regards

 

Anders

 

0 Likes
Accepted solutions (1)
2,427 Views
8 Replies
Replies (8)
Message 2 of 9

Aaron.Lu
Autodesk
Autodesk
Hi Enthusiast, I did not find any problem of your code, I don't have PDF995 driver, but I tried "Foxit Reader PDF Printer", it works well.


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 9

Anonymous
Not applicable

Hi

 

I didn't have "Foxit Reader PDF Printer" but I have nov 🙂

 

But it still don't work on my computer

I doesn't make it portrait and I still can't get the right papersize

 

Do you have some special settings on the printer  ??

 

Anders

 

 

0 Likes
Message 4 of 9

Aaron.Lu
Autodesk
Autodesk

looks like you need to get a setting object, modify it, and set it back, would you like to try this?

var setting = PrintM.PrintSetup.CurrentPrintSetting;

//...
// change properties of setting objecct
//...

PrintM.PrintSetup.CurrentPrintSetting = setting;
PrintM.Apply();
PrintM.SubmitPrint(vs);

 



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 5 of 9

Anonymous
Not applicable

Hi

 

It still doesn't work.

When I restart Revit it will print all the sheets with the Papersize, I have set for the first sheet

Whitch meens that Revit have control of the printer, but in the Revit session, and not sheet by sheet

 

And the orientation is still the same 😞

and the PrintM.PrintToFileName .... give the files the right name, but not in the right folder, but in the printer default save folder

 

My code look like this, have I used "setting" in the right way or ???

 

 

PrintManager PrintM = OpenDoc.PrintManager;

PrintM.PrintSetup.CurrentPrintSetting = PrintM.PrintSetup.InSession;

InSessionPrintSetting inSessionPrintSetting = PrintM.PrintSetup.CurrentPrintSetting as InSessionPrintSetting;

PrintM.SelectNewPrintDriver("PDF995");

PrintM.PrintToFile = true;

 

var setting = PrintM.PrintSetup.CurrentPrintSetting;

 

foreach (ViewSheet vs in new FilteredElementCollector(OpenDoc).OfClass(typeof(ViewSheet)).Cast<ViewSheet>())

{

if (vs.SheetNumber[0].ToString() != "A4")

{

 

PDF_Name = vs.SheetNumber.Substring(0, vs.SheetNumber.Length - 3);

 

PrintM.PrintToFileName = DistFolder + @"\" + Association_number.AsString() + "-" + Department_number.AsString() + "-" + PDF_Name + " - Plan.";

PaperSize Printerpapersizes = PrintM.PrintSetup.CurrentPrintSetting.PrintParameters.PaperSize;

PaperSizeSet PaperSizeSet = PrintM.PaperSizes;

 

setting.PrintParameters.PageOrientation = PageOrientationType.Portrait;

foreach (PaperSize PS in PaperSizeSet)

{

 

if (PS.Name.ToString() == pps.ToString())

{

setting.PrintParameters.PaperSize = PS;

break;

}

}

PrintM.PrintSetup.CurrentPrintSetting = setting;

PrintM.Apply();

PrintM.SubmitPrint(vs);

 

}

}

 

 

Anders

0 Likes
Message 6 of 9

Aaron.Lu
Autodesk
Autodesk
Accepted solution

Thanks for checking.

 

Now I've got another extra step, that is: save the setting, then the in-session setting will be actually changed. Hope it can work.

 

    using (Transaction transaction = new Transaction(doc))
    {
        transaction.Start("save setting");
        PrintM.PrintSetup.CurrentPrintSetting = setting;
        PrintM.PrintSetup.SaveAs("newsetting");
        transaction.Commit();
    }
    PrintM.Apply();
    PrintM.SubmitPrint(vs);


Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 7 of 9

Anonymous
Not applicable

Hi

 

We are gettting close 🙂

 

Revit couldn't not delete or overwrite the saves setting, so I rolled the transaction back after printing, that worked

 

Transaction transaction = new Transaction(OpenDoc);

 

transaction.Start("save setting");

PrintM.PrintSetup.CurrentPrintSetting = setting;

PrintM.PrintSetup.SaveAs("Tempsetting");

 

PrintM.Apply();

PrintM.SubmitPrint(vs);

transaction.RollBack();

 

But I still can't get the printer to save the pdf file in the right place, Do you have any ideas to fix that ?

 

 

 

Regards

 

Anders

 

 

 

0 Likes
Message 8 of 9

Revitalizer
Advisor
Advisor

Hi,

 

"But I still can't get the printer to save the pdf file in the right place":

what about just moving the file to the correct place, after printing  ...?

 

Not a solution but a workaround.

 

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 9 of 9

Anonymous
Not applicable

Yes 🙂

 

But I have > 100 useres, I they all have to set the settings right, to be sure that the printer saved in the same place so I know where to move the file from !!

0 Likes