SaveAs Rvt File InternalException

Hi fellow Revit Users,

I tried to add a simple Rvt SaveAs Function after the IFC Export Script but I encountered an InternalException that doesnt make much sense to me, because it saved the Revit File and it’s open in the background. I’m confused.

After searching since yesterday, not even the “TransactionManager.Instance.ForceCloseTransaction()” function helped me.

image

The Error is:

Python Script - RVT SAVE AS,1,“InternalException : A managed exception was thrown by Revit or by one of its external applications. bei Autodesk.Revit.DB.Document.SaveAs(String filepath, SaveAsOptions options) [’ File “””“, line 29, in \n’]”,null

The code for the Revit SaveAs Script:

import clr
import os

clr.AddReference('RevitServices')
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import Transaction, SaveAsOptions

save_path = IN[0]
file_name = IN[1]
lets_go = IN[2]
##lets_go is a boolean value that turns true when the export of the IFC Export is done

TransactionManager.Instance.ForceCloseTransaction()

doc = DocumentManager.Instance.CurrentDBDocument
sOption = SaveAsOptions()
sOption.OverwriteExistingFile = True

save_path_full = save_path + "\\"
file_name_rvt = file_name + ".rvt"

if lets_go:
    doc.SaveAs(save_path_full+file_name_rvt, sOption) ##line 29 btw

OUT = f"Modell im Datenausgang gespeichert"

I would check the path name for errors

You could also set to SaveAsOptions to overwite the existing file instead of deleting

sOption = SaveAsOptions()
sOption.OverwriteExistingFile = True
1 Like

path seems okay, added the Function, doesnt change the outcome

Tried this, also doesnt work.

if lets_go:
    try:
        doc.SaveAs(save_path_full+file_name_rvt, sOption)    
    except Exception as e:
        print(f"Revit Export fehlgeschlagen, Grund: {e}")

TransactionManager.Instance.TransactionTaskDone()

OUT = "Done"
1 Like