Export pdf file name

Hi all,

I am trying to use the PDFExportOptions and the Export methods for exporting sheet as PDF’s. When using pyrevit print() I can see the naming convention I want but once the pdf is exported the file name is Sheet + SheetName., This is my code:

for sheet, custom_name in zip(selected_sheets, custom_names):

folder_path = os.path.join(output_folder, now_str)

if not os.path.exists(folder_path):

    os.makedirs(folder_path)

try:

    sheet_ids = List\[ElementId\]()

    sheet_ids.Add(sheet.Id)

    pdf_export_options.Combine = False

    doc.Export(folder_path, sheet_ids, pdf_export_options)

    success_count += 1

except Exception as e:

    fail_count += 1

    failed_sheets.append((custom_name, str(e)))

I am using the Export Method (String, IList(ElementId), PDFExportOptions),

The naming convention I setup should be SheetNumber + Revision, but the created PDF shows Sheet + SheetName. Is like the output is completely ignoring the FileName

If anybody could help or point out some resources, I would appreciate it.

Can you share the whole code and use the fences before and after your code

The pdf file you are getting as output must has a fixed pattern of naming convection that is
“sheet-” + sheet.Name + “.pdf”

so just rename it after your export command. Define a rename method in your class that takes the outputFolder, newFilename and that sheet as argument and then rename it as you want dear.
for example I have done as:

private void RenameExportedPdf(string outputFolder, ViewSheet sheet, string newName) {

string current_name = "sheet-" + sheet.Name;

string targetPath = Path.Combine(outputFolder, newName + ".pdf");

string defaultExportPath = Path.Combine(outputFolder, current_name + ".pdf");

if (File.Exists(defaultExportPath))

{

    if (!String.Equals(defaultExportPath, targetPath, StringComparison.OrdinalIgnoreCase))

    {

        if (File.Exists(targetPath)) File.Delete(targetPath);

        File.Move(defaultExportPath, targetPath);

    }

}
}