Oh yes that being in an active action problem is a deal breaker.
So i think that chapter is closed for now, will see if someone in my company wants to do further testing of the python script, but in the end it`s not a real problemsolver.
Anyway, it was a fun project! Thank you for all your help jacob! 
Here the full code:
import io
import csv
import time
import clr
clr.AddReference("RevitAPI")
clr.AddReference('DynamoRevitDS')
clr.AddReference("RevitAPIUI")
import Dynamo
clr.AddReference('DSCoreNodes')
from Autodesk.Revit.UI import TaskDialog, TaskDialogCommonButtons, TaskDialogResult, TaskDialogCommandLinkId, TaskDialogIcon
import Autodesk
from Autodesk.Revit.DB import *
clr.AddReference("RevitServices")
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
from datetime import datetime
doc = DocumentManager.Instance.CurrentDBDocument
def QLOG_New_Entry():
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
dynamoFileName = currentWorkspace.FileName
dynamoRevit = Dynamo.Applications.DynamoRevit()
currentWorkspace = dynamoRevit.RevitDynamoModel.CurrentWorkspace
dynamoFileName = currentWorkspace.FileName
app = DocumentManager.Instance.CurrentUIApplication.Application
User = app.Username
now = datetime.now()
dateformat = "%d.%m.%Y"
timeformat = "%X"
Date = now.strftime(dateformat)
Time = now.strftime(timeformat)
CentralFilePath_dfs = BasicFileInfo.Extract(doc.PathName).CentralPath
CentralFilePath = "P:\\"+(CentralFilePath_dfs.split("\\dfs\\")[1])
FileNameList = CentralFilePath.Split("\\")
FileNameListLength = len(FileNameList)
FileName = FileNameList [FileNameListLength-1]
ProjectList = FileName.Split("_")
Projectnumber = ProjectList[0]
QLOG_New_Entry = Projectnumber+"\t"+User+"\t"+Date+"\t"+Time+"\t"+dynamoFileName
return QLOG_New_Entry
def Read_SLOG():
with io.open(SlogFilePath,"r", encoding = "utf-16(LE)") as SlogFile:
SLOG = SlogFile.read().splitlines()
return SLOG
def Read_QLOG():
with io.open(QlogFilePath,"r", encoding = "utf-8") as Qlogfile:
QLOG = Qlogfile.read().splitlines()
return QLOG
def Write_QLOG_Entry():
with io.open(QlogFilePath,"w", encoding="UTF8", newline='') as Qlogfile:
for Qlog in QLOG_New:
writer = csv.writer(Qlogfile,delimiter="'")
writer.writerow([Qlog])
def UserMessage():
taskDialog = TaskDialog("Test1")
taskDialog.MainInstruction = "User currently syncing"#"Ein Benutzer synchronisiert gerade."
taskDialog.MainContent = "Want to get queued in the sync line?"#"In Synchronisations-Warteschlange einreihen?"
taskDialog.TitleAutoPrefix = False
taskDialog.MainIcon = TaskDialogIcon.TaskDialogIconInformation
taskDialog.CommonButtons = TaskDialogCommonButtons.Cancel | TaskDialogCommonButtons.Yes
taskDialog.FooterText = "Help"
return taskDialog.Show()
def Sync():
try:
tOptions = TransactWithCentralOptions()
rOptions = RelinquishOptions(False)
rOptions.StandardWorksets = True
rOptions.ViewWorksets = True
rOptions.FamilyWorksets = True
rOptions.UserWorksets = True
rOptions.CheckedOutElements = True
sOptions = SynchronizeWithCentralOptions()
sOptions.SetRelinquishOptions(rOptions)
sOptions.Compact = False
sOptions.SaveLocalBefore = True
sOptions.SaveLocalAfter = True
sOptions.Comment = ""
TransactionManager.Instance.ForceCloseTransaction()
doc.SynchronizeWithCentral(tOptions, sOptions)
return "Sync Successful"
except:
return "Sync did not work"
CentralFilePath_dfs = BasicFileInfo.Extract(doc.PathName).CentralPath
CentralFilePath = "P:\\"+(CentralFilePath_dfs.split("\\dfs\\")[1])
FileNameList = CentralFilePath.Split("\\")
FileNameListLength = len(FileNameList)
FileName = FileNameList [FileNameListLength-1]
SlogFileName = FileName.Replace("rvt","slog")
ProjectList = FileName.Split("_")
Projectnumber = ProjectList[0]
SlogFileFolder = CentralFilePath.Replace(".rvt","_backup")
SlogFilePath = SlogFileFolder+"\\"+SlogFileName
QlogFilePath = "......................"
SLOG = Read_SLOG()
QLOG = Read_QLOG()
SLOG_LastItemIndex = len(SLOG)-1
SLOG.reverse()
for qlog in QLOG:
if Projectnumber in qlog:
QLOG_LastItem = qlog
QLOG_LastUser = QLOG_LastItem.split("\t")[1]
QLOG_New = QLOG
QLOG_New_Entry = QLOG_New_Entry()
QLOG_New.append(QLOG_New_Entry)
Write_QLOG_Entry()
for slog in SLOG:
if "user="+"\""+ QLOG_LastUser +"\"" in slog:
SessionUserIndex = SLOG.index(slog)
SessionUserLine = SLOG[SessionUserIndex]
SessionIdOfLastQLOGUser = SLOG[SessionUserIndex+1][:9]
for slog in SLOG:
if SessionIdOfLastQLOGUser in slog:
SessionIndex=SLOG.index(slog)
LastUser = SLOG[SessionIndex-1].split('"')[1::2][0]
SLOG.reverse()
for slog in SLOG:
if "STC" in slog:
Last_STC_Line = slog
if Last_STC_Line[-4:] == "<STC":
SyncActive = False
else:
SyncActive = True
if SyncActive is False:
syncresult = Sync()
LastSTCofSession = "none"
bool = "none"
Session_STC_List=[]
if SyncActive is True:
UserResult = UserMessage()
if UserResult == TaskDialogResult.Yes:
timeout = time.time() + 240 #seconds
bool = True
while bool == True:
time.sleep(0.5) # sleep for 500 milliseconds
if time.time() > timeout:
syncresult="timeout"
break
with io.open(SlogFilePath,"r", encoding = "utf-16(LE)") as SlogFile:
SLOG = SlogFile.read().splitlines()
SLOG_Sublist = SLOG[SLOG_LastItemIndex:]
for slog in SLOG_Sublist:
if SessionIdOfLastQLOGUser in slog:
if "STC" in slog:
LastSTCofSession = slog
Session_STC_List.append(slog)
if LastSTCofSession[-4:] == "<STC":
bool = False
else:
bool = True
else:
outlist.append("Canceled by User")
else:
OUT = "fail"
if bool is False:
syncresult = Sync()
TaskDialog.Show("Results", syncresult)
dict = {"QLOG_LastItem": QLOG_LastItem, "QLOG_New_Entry":QLOG_New_Entry, "SessionUserLine":SessionUserLine,"SessionIdOfLastQLOGUser":SessionIdOfLastQLOGUser, "LastUser":LastUser,"SyncActive":SyncActive,"bool":bool,"LastSTCofSession":LastSTCofSession,"syncresult":syncresult,"Session_STC_List":Session_STC_List}
OUT = dict
Edit:
Again a failed STC entry because of closing revit:
$ccd7e64b 2022-10-20 22:54:10.386 >STC
$ccd7e64b 2022-10-20 22:54:10.427 >STC:RL
$ccd7e64b 2022-10-20 22:54:10.666 .STC:RL:LockRoot RW locked
$ccd7e64b 2022-10-20 22:54:10.709 >STC:RL:HC
$ccd7e64b 2022-10-20 22:54:10.865 .STC:RL:HC:LockUsers R locked
$ccd7e64b 2022-10-20 22:54:11.551 .STC:RL:HC:LockUsers R unlocked
$ccd7e64b 2022-10-20 22:54:11.686 <STC:RL:HC
$ccd7e64b 2022-10-20 22:54:11.793 .STC:RL:CFV central=2478
$319fb657 2022-10-20 23:04:55.771 .LockUsers R locked
I will change my code to only check the last 10 minutes of the SLOG, so failed entries will not mess um everything.