I am trying to export simple data from some of my scripts in CSV format. I added a simple test Python code to both Python and Dynamo test tools, which export the CSV. It works without any problem for the Python tool. However, when I first ran the Dynamo tool with pyRevit, running the Python tool afterward triggers the error “Revit could not complete the external command.” Am I missing something here?
This Is the code I used in both dyn and py files:
import csv
import datetime
data = [
[“Name”, “Age”, “City”],
[“Alice”, 30, “New York”],
[“Bob”, 25, “Los Angeles”],
[“Charlie”, 35, “Chicago”]
]
directory_path = r’P:\Operations\Drawing Resources\Revit\2024-All CSV files’
now = datetime.datetime.now()
timestamp = now.strftime(“%Y-%m-%d_%H-%M-%S”)
X = ‘example_variable’
file_name = f’{timestamp}_{X}.csv’
file_path = f’{directory_path}\{file_name}’
with open(file_path, mode=‘w’, newline=‘’) as file:
writer = csv.writer(file)
writer.writerows(data)