Hi everybody!!
I don’t know if such post are for this forum, but I will write it anyway.
I created a hook that calculates the time difference from when a Revit document was opened until when it was closed. Everything went fine until I started to writing #comments for description.
One comment had the “Δ” symbol and I don’t know why but the script stopped working.
This code works:
import os
import math
from pyrevit import script,revit
from datetime import datetime
doc = revit.doc
time = datetime.now()
dt_f2 = time.strftime("%H-%M-%S")
# getting the project info
project_name = doc.Title
# getting the time for the doc-opened file
try:
dt_f1 = script.load_data("Project opened", this_project=True)
except:
script.exit()
before = dt_f1.split("-")
after = dt_f2.split("-")
# function converting time to seconds
def get_seconds(lst):
h = int(lst[0]) * 60 * 60
m = int(lst[1]) * 60
s = int(lst[2])
return h + m + s
# function time to string
def time_to_string(s):
unpadded = str(s).split(".")[0]
return unpadded.rjust(2,"0")
# formating the time
project_start = dt_f1
project_closed = dt_f2
# calculating the time difference
try:
elapsed = get_seconds(after) - get_seconds(before)
mins = math.floor(elapsed/60)
secs = elapsed % 60
msg = time_to_string(mins) + "mins" + time_to_string(secs) + "sec"
except:
script.exit()
data = [[project_name],[project_start],[project_closed],[msg]]
# creating the file name
init_path = r'C:\Users\vasil\Desktop'
result = "resultat_" + project_name + "_" + dt_f2 + ".csv"
csv_path = os.path.join(init_path,result)
# export the CSV
script.dump_csv(data,csv_path)de here
This doesn’t
import os
import math
from pyrevit import script,revit
from datetime import datetime
doc = revit.doc
time = datetime.now()
dt_f2 = time.strftime("%H-%M-%S")
# getting the project info
project_name = doc.Title
# getting the time for the doc-opened file
try:
dt_f1 = script.load_data("Project opened", this_project=True)
except:
script.exit()
before = dt_f1.split("-")
after = dt_f2.split("-")
# function converting time to seconds
def get_seconds(lst):
h = int(lst[0]) * 60 * 60
m = int(lst[1]) * 60
s = int(lst[2])
return h + m + s
# function time to string
def time_to_string(s):
unpadded = str(s).split(".")[0]
return unpadded.rjust(2,"0")
# formating the time
project_start = dt_f1
project_closed = dt_f2
# calculating the Δ time
try:
elapsed = get_seconds(after) - get_seconds(before)
mins = math.floor(elapsed/60)
secs = elapsed % 60
msg = time_to_string(mins) + "mins" + time_to_string(secs) + "sec"
except:
script.exit()
data = [[project_name],[project_start],[project_closed],[msg]]
# creating the file name
init_path = r'C:\Users\vasil\Desktop'
result = "resultat_" + project_name + "_" + dt_f2 + ".csv"
csv_path = os.path.join(init_path,result)
# export the CSV
script.dump_csv(data,csv_path)
Have you ever encountered such things? Does " Δ" usually interfere with the script? Are there other such kind of symbols that prevent the script to run properly?