Home > other >  How can I overwrite the exported CSV file using Python in Dynamo for Revit?
How can I overwrite the exported CSV file using Python in Dynamo for Revit?

Time:04-28

This Dynamo/Python script is working great. I'm just trying to do the same but overwrite the file with the new export every time I export. I don't need to append or save any older version. Just the newest version. How can I modify the Python script to achieve this? Pic of Dynamo Script

import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

schedule = UnwrapElement(IN[0])
path = IN[1]
name = IN[2]

try:
    exp_opt = ViewScheduleExportOptions()
    schedule.Export(path, name, exp_opt)
    OUT = "Done"

except: OUT = "Failed"

CodePudding user response:

I don't see any property suggesting overwriting in the ViewScheduleExportOptions class.

So a dirty way of doing this, would be deleting the file if it already exists.

import clr
import os

clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *

schedule = UnwrapElement(IN[0])
path = IN[1]
name = IN[2]

try:
    try:
        os.remove(path)
    except OSError:
        pass

    exp_opt = ViewScheduleExportOptions()
    schedule.Export(path, name, exp_opt)
    OUT = "Done"

except: OUT = "Failed"
  • Related