is there a way to check if single or multiple sheet(s) printing and/or export?

is there a way to check if single or multiple sheet(s) printing and/or export?

Ning_Zhou
Advocate Advocate
2,037 Views
12 Replies
Message 1 of 13

is there a way to check if single or multiple sheet(s) printing and/or export?

Ning_Zhou
Advocate
Advocate

for instance, print sheet set, see attached image

0 Likes
Accepted solutions (1)
2,038 Views
12 Replies
Replies (12)
Message 2 of 13

fdkuenneke
Enthusiast
Enthusiast
Accepted solution

This would be accessible by the Size property nested in PrintManager.

Document Doc = commandData.Application.ActiveUIDocument.Document;

if (Doc.PrintManager.ViewSheetSetting.CurrentViewSheetSet.Views.Size >1)
{
//Do Stuff
}

More information on the class can be found here. 

Let me know if this solves your question,
Frank

I'd say Revit was a chisel if it wasn't used as a hammer.
Message 3 of 13

Ning_Zhou
Advocate
Advocate

thanks Frank, works great! just wonder if there's similar stuff in exporting i.e. DWF, DWG, etc? i mean getting view/sheet set, not creating one because i use exporting event

0 Likes
Message 4 of 13

fdkuenneke
Enthusiast
Enthusiast

Assuming that...

doc.PrintManager.PrintRange = PrintRange.Select;

and that you haven't selected a set of views to print yet.

you can determine:

if (printManager.ViewSheetSetting.CurrentViewSheetSet is InSessionViewSheetSet)
            {
//Yes, printmanager contains your viewsheetset for exporting
            } 
else
{
//No, it does not contain the exporting viewsheetset
}

Which should be able to determine if the printmanager also happens to contain the viewsheetset that the Revit exporting function uses.

Keep me updated on your results, this is an assumption I had made but never explored in the Revit API so I am welcome to being corrected.

I'd say Revit was a chisel if it wasn't used as a hammer.
0 Likes
Message 5 of 13

Ning_Zhou
Advocate
Advocate

thanks Frank, you're right, it turned out that exporting event use same ViewSheetSet from PrinterManager as printing event, a bit misleading but it works, have a great weekend!

0 Likes
Message 6 of 13

Ning_Zhou
Advocate
Advocate

another question, hope it's the last one?

how to get the file name to be printed/exported within printing/exporting event? PrintManager.PrintToFileName won't work, i need to put this file name on actually printed/exported sheets, means this file name needs to be available within printing/exporting event.

0 Likes
Message 7 of 13

Ning_Zhou
Advocate
Advocate

looks like exporting event has Path available so only printing event has this issue, may be workaround?

0 Likes
Message 8 of 13

Ning_Zhou
Advocate
Advocate

to be more specific and clear: i need printed (i.e. PDF) file name in printing event

for exporting event, i can get exported (i.e. DWF) file name in args.Path

for printing event, no args.Path available, any solution or workaround?

0 Likes
Message 9 of 13

fdkuenneke
Enthusiast
Enthusiast

In this case, PrintManager.PrintToFileName is the best bet to access the file name as far as I am aware... it requires a full path, name and possibly extension (good practice to include anyways). How are you formatting your printing event which makes this parameter not an option? A snippet would help.

I'd say Revit was a chisel if it wasn't used as a hammer.
0 Likes
Message 10 of 13

Ning_Zhou
Advocate
Advocate

that's what i'm afraid too,  have to use PrintManager.PrintToFileName, BUT

 

1) i have to check "Print to file" option which is not desired, and sometimes it's grayed out!?

2) sometimes "Combined multiple selected views/sheets into a single file" is also grayed out!?

3) printed file(s) will be *.prn instead of *.pdf!?

code is just normal one, string fname = doc.PrintManager.PrintToFileName; which will be null if doc.PrintManager.PrintToFile is false, i then use fname value to modify one of my sheet (shared) parameter.

 

well, PostCommand won't solve my problem as my issue is within printing event, seems a dead end to me but still hope someone can solve it.

0 Likes
Message 11 of 13

fdkuenneke
Enthusiast
Enthusiast

1 / 2) PrintManager.PrintToFileName requires that both PrintToFile and CombinedFile are true. These options are often greyed out when the print driver already declares that it is virtual (such as Adobe PDF, which can only print to file) so that these options must be true for the driver to operate.

3) A fix for this is to specifically declare the filetype in your PrintToFileName. For example:

PrintManager pm = Doc.PrintManager;
pm.PrintToFile = true;
pm.CombinedFile = true;
// set pm print driver, etc.
pm.PrintToFileName = pm.PrintToFileName + ".pdf";
pm.Apply();

 
you can even use  string.contains(".");  in order to see if PrintToFileName is already trying to set the file to a specific file type. If so, you can truncate the file name and then set it to pdf using a similar declaration as seen above. As far as I can tell, the correct solution is either beyond what I can do to help, or what I have provided is the best solution.

Let me know if you have any further developments.

I'd say Revit was a chisel if it wasn't used as a hammer.
Message 12 of 13

Ning_Zhou
Advocate
Advocate

thanks Frank, it works!

some observations as below:

1) pm.CombinedFile = true; -> doesn't work, if i pick "separate sheets ..." in UI then it will print separate *.prn

2) some printers are OK i.e. ClarityPDF, PDF-XChange Standard, except annoying Save As dialog, any fix?

3) some printers are not OK i.e. Microsoft Print to PDF, Print Smart (mostly used in our company)

attached pls find captured images for your info., again very appreciated for your help!

 

0 Likes
Message 13 of 13

fdkuenneke
Enthusiast
Enthusiast

It is odd that combined file isn't working for you.

The SaveAs dialog is from the print driver itself. I am not familiar with the drivers you named, so they may have the option to suppress it in Printers & Scanners, [Printer Driver], Manage, Printing Preferences.

An easy way that I have used in the past would be Bullzip or CutePDF Writer. Both of these drivers are capable of being customized to suppress the dialog in addition to many other useful things.

As for your print driver errors, I suggest setting the print driver with c# like so:

try
{
doc.PrintManager.SelectNewPrintDriver = "Microsoft Print to PDF";
doc.PrintManager.Apply();
}
catch (Exception ex)
{
TaskDialog.Show("Error Setting Print Driver:", ex.Message);
}

This way you can also control which print driver is default when using your addin.

The purpose of the try catch here is to get a more specific error code that pertains to incompatible drivers so that you can fix compatibility issues. Hope this helps!

I'd say Revit was a chisel if it wasn't used as a hammer.