Announcements
Welcome to the Revit Ideas Board! Before posting, please read the helpful tips here. Thank you for your Ideas!
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export PDF overwrite existing file - API method missing

Export PDF overwrite existing file - API method missing

Revit throws an File Access Exception when exporting a pdf and the file already exists.

There is no API method for handling the file overwrite. 

 

Revit_JRtmTQzdC5.png

 

Please include this functionality also in the API

 

7 Comments
kimberly.fuhrman
Autodesk

Hi, @a.bejenaru ,

 

We are also investigating this with our API team. I will let you know if this is considered a bug.

 

Thank you!

Kimberly

a.bejenaru
Enthusiast

In case I'm doing something wrong coding here is the code snippet that I'm using for the pdf export.

using (Transaction t = new Transaction(doc, "Mario Tools: Export Sheets to PDF"))
                {
                    // start the transaction
                    t.Start();

                    // create DWG export options
                    PDFExportOptions exportOptions = new PDFExportOptions();
                    //gets size from title block
                    exportOptions.PaperFormat = ExportPaperFormat.Default;
                    exportOptions.ColorDepth = ColorDepthType.Color;
                    exportOptions.Combine = thisForm.checkBoxCombine.Checked;
                    exportOptions.FileName = fileName; //only works if Combine is True
                    exportOptions.ExportQuality = PDFExportQualityType.DPI600;
                    exportOptions.HideCropBoundaries = true;
                    exportOptions.HideReferencePlane = true;
                    exportOptions.HideScopeBoxes = true;
                    exportOptions.HideUnreferencedViewTags = true;
                    exportOptions.MaskCoincidentLines = true;
                    //Don't think of this as a "continue" but rather as a silent mode
                    exportOptions.StopOnError = true;
                    ////Make sure to not use these settings as they don't work if 'Default' size is used above
                    //exportOptions.PaperPlacement = PaperPlacementType.LowerLeft;
                    ////Make sure to not use these settings as they don't work if 'Default' size is used above
                    //exportOptions.ZoomType = ZoomType.Zoom;
                    ////Make sure to not use these settings as they don't work if 'Default' size is used above
                    //exportOptions.ZoomPercentage = 100;
                    exportOptions.ViewLinksInBlue = false;

                    //Get all sheets to export
                    // create a list to hold the sheets
                    List<ElementId> sheetsToExportIds = (from View eachview in selectedViewSet.Views select eachview.Id).ToList();

                    // export
                    try
                    {
                        doc.Export(path, sheetsToExportIds, exportOptions);
                        summary += "- OK: Files exported correctly to <" + path+ ">." + Environment.NewLine;
                    }
                    catch (FileAccessException e)
                    {
                        summary += "- FAIL: The File already exists/The File is already open/No ovewrite option is available in th API for now." + Environment.NewLine;
                        summary += "- FAIL: Exception: " + e.Message + Environment.NewLine;
                        summary += "- FAIL: Exception: " + e.StackTrace + Environment.NewLine;
                    }
                    catch (Exception e)
                    {
                        summary += "- FAIL: Failed at Export Command" + Environment.NewLine + Environment.NewLine;
                        summary += "- FAIL: Exception: " + e.Message + Environment.NewLine;
                        summary += "- FAIL: Exception: " + e.StackTrace + Environment.NewLine;
                    }

                    t.Commit();
                }
kimberly.fuhrman
Autodesk

@a.bejenaru ,

 

Thank you for sharing this! I will keep you posted.

 

Kimberly

kimberly.fuhrman
Autodesk

@a.bejenaru , we're going to leave this one as a new feature request, but know that it is being looked at as a possible bug. I will let you know if anything changes!

 

Kimberly

Sean_Page
Collaborator

Does the FileAccessException kinda do what your asking? No, it doesn't overwrite for you, but if you handle the exception as delete and then save?

a.bejenaru
Enthusiast

This could work although,if I'm not wrong FileAccessException may be due to other reasons also, right?

Sean_Page
Collaborator

Yes, it could also be because the files is in use, which I would presume is why the API method does not attempt to overwrite, but provides the exception.

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

Submit Idea  

Autodesk Design & Make Report


Autodesk Design & Make Report