Here is another case handled by Joe Ye regarding the DWF output filename generated by the ImportExport Revit SDK sample. We already presented another related case of his regarding the DWG export filename.
Question: This problem is similar to the ViewPrinter problem where the program automatically names the output file. Please tell me how I can trap the naming of DWF output file so I can either send it to a temp folder or rename it by moving to a new folder. The problem seems to be when you create a DWF with multiple sheets in it – the program will append a dash suffix "-" at the end.
Answer: Yes, if we export to DWF in merge mode, a suffix will be added to the end of the file name. The problem is that the API does not provide full access to directly and completely control the output file name. The solution is that we can export the DWF file to a temp folder, and then copy and rename the file to the desired destination folder. For exporting a 2D DWF file, the code to change is in Export2DDWFData.cs. I changed it as follows:
public override bool Export() { bool exported = false; base.Export(); //parameter : ViewSet views ViewSet views = new ViewSet(); if( m_currentViewOnly ) { views.Insert( m_activeDoc.ActiveView ); } else { views = m_selectViewsData.SelectedViews; } // Export DWFx if( m_exportFormat == ExportFormat.DWFx2D ) { DWFX2DExportOptions options = new DWFX2DExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; if( m_exportMergeFiles == false ) { string strTempFolder = "C:/tmp"; exported = m_activeDoc.Export( strTempFolder, m_exportFileName, views, options ); File.Copy( strTempFolder + "/" + m_exportFileName + "-.DWFx", m_exportFolder + "/" + m_exportFileName + ".DWFx" ); } else { exported = m_activeDoc.Export( m_exportFolder, m_exportFileName, views, options ); } } // Export DWF else { DWF2DExportOptions options = new DWF2DExportOptions(); options.ExportObjectData = m_exportObjectData; options.ExportingAreas = m_exportAreas; options.MergedViews = m_exportMergeFiles; options.ImageFormat = m_dwfImageFormat; options.ImageQuality = m_dwfImageQuality; if( m_exportMergeFiles == false ) { string strTempFolder = "C:/tmp"; exported = m_activeDoc.Export( strTempFolder, m_exportFileName, views, options ); File.Copy( strTempFolder + "/" + m_exportFileName + "-.DWF", m_exportFolder + "/" + m_exportFileName + ".DWF" ); } else { exported = m_activeDoc.Export( m_exportFolder, m_exportFileName, views, options ); } } return exported; }
You could also optionally delete the intermediate file after copying it, or use File.Move instead of File.Copy.
I tested this solution, and it works well for me. Please make analogous changes for the other file formats, if you need them.
Many thanks to Joe for handling this case!
By the way, this is a pretty common issue that was also addressed by Rod Howarth in his AU presentation. He uses a similar approach in his PLT utility, which batch plots to PDF, DWG, DWF and paper, to trap the output generated by the Revit API call and rename the files to suit his requirements. One part of the solution that he suggests is to print out the sheets one at a time to retain more complete control over the renaming and sorting.