@Anonymous
I’m trying to export Revit sheets to images with high quality. I use a code you have already shared before:
/// <summary>
/// New code as described in Revit API discussion
/// forum thread on how to export an image from a
/// specific view using Revit API C#,
/// http://forums.autodesk.com/t5/revit-api/how-to-export-an-image-from-a-specific-view-using-revit-api-c/m-p/6424418
/// </summary>
static Result ExportToImage3( Document doc )
{
Result r = Result.Failed;
using( Transaction tx = new Transaction( doc ) )
{
tx.Start( "Export Image" );
string desktop_path = Environment.GetFolderPath(
Environment.SpecialFolder.Desktop );
View view = doc.ActiveView;
string filepath = Path.Combine( desktop_path,
view.Name );
ImageExportOptions img = new ImageExportOptions();
img.ZoomType = ZoomFitType.FitToPage;
img.PixelSize = 32;
img.ImageResolution = ImageResolution.DPI_600;
img.FitDirection = FitDirectionType.Horizontal;
img.ExportRange = ExportRange.CurrentView;
img.HLRandWFViewsFileType = ImageFileType.PNG;
img.FilePath = filepath;
img.ShadowViewsFileType = ImageFileType.PNG;
doc.ExportImage( img );
tx.RollBack();
filepath = Path.ChangeExtension(
filepath, "png" );
Process.Start( filepath );
r = Result.Succeeded;
}
return r;
}
I tried to increase the pixel size to its limits (15000) however though when I zoom in the exported image it is not with good quality and some details are not fine.
Some lines are thick and I tried to manage this from object style by setting Cut and Projection size to 1 but though the lines come thick.
Any advice?
Hi Mustafa,
Interesting!
I export images to 512 pixels and it works perfectly, but I did not go further (15000 pixels) using the code. Did you try "by hand" to check whether it works or not? (on my machine it works with 15 000 pixels "by hand")
Another question from looking at the code: what's the use of the Transaction? I think I have none when I export images.
Pixels are evil.
Can't you avoid them?
Maybe you can print to PDF instead, generating a vector format, and then convert that to pixels if needed?
Thanks @jeremytammik, I also tried vector printing to PDF, but for some reason some of the lines are printed thick though I adjusted the Object Styles and removed any view templates/filters. Any idea?
Also printing to PDF then converting to image will take a lot of time (this procedure will be applied to thousands of drawings). Can I export somehow to something like SVG or AI?
Thanks @BenoitE&A , if I tried to print manually I get the same results.
For the transaction, I think you need it if you want to export the image to a view (a view contains a snapshot of an other view).
No idea about the thick lines. That is something you might want to research on manually in the end user interface to find a solution before trying to address it programmatically.
Regarding other output formats, maybe you can find some use of the 2D custom export functionality to achieve SVG or something?
I've been digging more and I found this link from "the building coder". So I think the solution will be to try to build a custom exporter to create SVG from the 2d geometries then rasterize it.
Any other ideas 😁?
What is the actual view scale of the view being printed. Line thickness gets scaled according to this value so that may be the main reason for thick lines on such a small image.
If you don't mind annotation objects also changing in your end view then you could temporarily adjust the scale to 1:1 etc.
Without the annotation objects visible here are two images of the same view (not from exports), the top is set to 1:1000 and the bottom 1:200. The line weights are scaled in relation to paper space units so if you set to 1:1 etc then your lines end up thinner (which may carry through to images exported if you can temporarily set this before export).
There is the ThinLinesOptions class which has the static property AreThinLineEnabled.
From testing this isn't going to make much of a difference for such small images however, even at 512 image size you'd likely not see the difference.
It may be better to export at larger size and reduce the image size using system.graphics namespace or similar then you'll probably get the same kind of optimised reduction that takes place with icons in file explorer.