After 3 flights cancelled because of the "snowmagguedon" in NYC yesterday, I was able to catch a flight earlier this morning to start my 2 weeks on the road business adventure, with the first stop being the AEC Hackathon in Chicago this weekend. Can't wait for the cool projects and mind blowing ideas that will come out this weekend.
On Wednesday I gave a presentation on View and Data API, to a group of enthusiastic, web developers and JS lovers, by doing this I became part of the Alumni group of the QueensJS meetup, such a great honor to be part of this community. The presentation had a lot of very positive feedback and I can't wait to see what will come out from these great community of developers, when they start to play with it, which I know some of them already are. Some lucky attendees got their hands on some VR Dodocases and of course our I <3 3D shirts which they were thrilled about it. It was such a great way to start the tech evangelism of this great new technology in the NYC boroughs, next ones will be BrooklynJS or ManhattanJS, will see where do I end up going first.
So lets talk about some Revit API, and what a nice case I had the chance to work on this past week, since I know many developers out there have looked for a solution like this for quite some time. Here is the breakdown of the case I mentioned.
Question: When exporting a view to dwfx we can set some options with the DWFxExportSetting, ie:
DWFXExportOptions options = new DWFXExportOptions()
{
CropBoxVisible = false,
ExportingAreas = true,
ExportObjectData = false,
ImageFormat = DWFImageFormat.Lossless,
StopOnError = false,
PortraitLayout = papersize.U < papersize.V,
PaperFormat = ExportPaperFormat.Default,
};
However, we cannot set the paper placement and zoom options which exists in the print setup dialog. These current/in-session print settings still influence our export(!), and we cannot change them from the API.
This means that for instance, large sheets (for some reason larger than A0) will be cropped when exported.
I then tried to hack around with the print manager to change the used settings, but no real luck. Something like
PrintManager pm = document.PrintManager;
PrintSetup ps = pm.PrintSetup;
PrintParameters pp = ps.CurrentPrintSetting.PrintParameters;
pp.ZoomType = ZoomType.Zoom;
pp.Zoom = 100;
pp.PaperPlacement = PaperPlacementType.Center;
ps.Save();
This will work the very first time after starting up, where I only got current settings, not subsequently with in-session settings, which I'm not allowed to save. And then the settings are not modified for the exporter..
Generally, it's kind of hard to see the point of the PrintSetup methods Save(), SaveAs(), Delete(), since there is no Load() etc.
So, how can we control these settings for our dwfx export?
I want to thank Phil Xia one of our Revit Engineers, for the guideline on solving such a trivial problem developers have encountered in the past.
Answer: Thank you so much for all your patience, I got a solution from one of our Revit Engineers, where he suggest to create a new print setup and activate it. As you will notice the setup for the PaperPlacement and the ZoomType is something that will be helpful for your solution.
Here is a sample created for you.
var doc = this.ActiveUIDocument.Document;
var newPsName = "new_printsettings5";
using (Transaction t = new Transaction
(doc, "print setting"))
{
t.Start();
// 1. create a new print settings.
var printMgr = doc.PrintManager;
printMgr.PrintSetup.CurrentPrintSetting
= printMgr.PrintSetup.InSession;
printMgr.PrintSetup.SaveAs(newPsName);
// 2. get this new print settings from document filter.
FilteredElementCollector col =
new FilteredElementCollector(doc);
col.OfClass(typeof(PrintSetting));
PrintSetting set1 = null;
foreach (PrintSetting ps in col.ToElements())
{
if (ps.Name == newPsName)
{
set1 = ps;
break;
}
}
// 3. activate it.
printMgr.PrintSetup.CurrentPrintSetting = set1;
printMgr.Apply();
// 4. modify its parameters.
printMgr.PrintSetup.CurrentPrintSetting.
PrintParameters.PaperPlacement = PaperPlacementType.Margins;
printMgr.PrintSetup.CurrentPrintSetting.
PrintParameters.ZoomType = ZoomType.Zoom;
printMgr.PrintSetup.Save();
t.Commit();
}
Please take a look at it, Let me know how it goes and also if this works for you, Cheers.
Thanks again for reading, until next time.