Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export 2d sheets as images with high quality

11 REPLIES 11
Reply
Message 1 of 12
Mustafa.Salaheldin
1835 Views, 11 Replies

Export 2d sheets as images with high quality

@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?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Labels (2)
11 REPLIES 11
Message 2 of 12

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.


Benoit FAVRE
CEO of etudes & automates
www.etudesetautomates.com/
Message 3 of 12

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?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 4 of 12

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?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 5 of 12

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). 


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 6 of 12

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?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 12

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 😁?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 8 of 12

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.

Message 9 of 12

Scale is 1:150 and thick lines are of the model elements not the annotations.


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 10 of 12

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).1:10001:10001:2001:200

Message 11 of 12

I'm trying to export Sheets, not views. So if I change the sclae in the view the viewport will be disalocated in the sheet.

I need to export the Sheets with thin lines, any ideas?


¯\_(ツ)_/¯
Let it work like a charm.

Mustafa Salaheldin


EESignature




Innovation and R&D Lead, AtkinsRéalis

Facebook | Twitter | LinkedIn

Message 12 of 12

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community