Can anyone help with some python script to look at a directory and wait until a particular file is generated before continuing?
You can use the passthrough
node (from the Clockwork package), but Iâm not sure if you find that enough.
Iâm trying to wait until a PDF is generated so I can then move its location.
Once the info is passed to the printer dynamo sees the task as done, so need a wait function to keep checking until the file actually exists
I want to essentially keep looping the node âFile.Existsâ until the result is true
Couldnât that be accomplished using a while loop in a python script? Once the âdummyâ output is passed out of the Python node you can let your Dynamo script continue (This could be done by using codeblock with the following: {waitfor,pass}[1]
This will waitfor=Dynamooutput before it passes the information in âpassâ to the next cluster of nodes in your graph.
Problem is once dynamo sends the information to the PDF driver it sees its job as done. I need to confirm that the last file being generated exists before moving on.
The loopWhile node will work fine for this:
basically checking every N milliseconds if the file exists and continuing once itâs there. However you might want to do this inside of a script or have a custom node as the loop body, so that you can keep track of how many times youâve checked so far and have a cut-off number. That way, if after 1000 checks the file is still missing and you know that the task should take no more than 5 minutes, you can forcefully break the loop.
Thanks very much. The loop while node makes a lot more sense now youâve laid it out for me
Sorry stuck again, I cant figure out how to count how many times it has looped to kill the node
Itâs a lot simpler to do this in python, but doing it with nodes is more fun. Youâll need two relatively simple custom nodes - one for the loop body and one for the continuation test. Weâll also have an extra input thatâs going to store our check count:
Our continuation test would then verify both the count and the path and continue only when both conditions are true:
And our body would just increment the count and pause Dynamoâs thread:
Youâll know the file was found if the end count is less than the max count:
while I like any topic where we talk about functional programming, loop while, or imperative code in codeblocks (so they improve) - you could also try using thread.pause for a reasonable amount of time if you know the file is generated in some other part of your graph.
I did start with a general thread pause, however most of the time PDFâs are generated very quickly so didnât want the user to have to wait for a generic pause.
But if the last PDF being created happens to be a complex sheet full of 3D views, this could take a few minutes
Thanks heaps @Dimitar_Venkov, I see where I was going wrong now. I wasnât defining the extra input for the count
This is how Iâve accomplished what @JB86 has asked about using python. Iâm new at this so sorry for the bad formatting and the unnecessary lines. I used a passthrough node to make sure the print node ran before this python node, without it the python node ran first.
import clr
clr.AddReference('RevitAPI')
from Autodesk.Revit.DB import *
from Autodesk.Revit.DB.Structure import *
clr.AddReference('RevitAPIUI')
from Autodesk.Revit.UI import *
clr.AddReference('System')
from System.Collections.Generic import List
clr.AddReference('RevitNodes')
import Revit
clr.ImportExtensions(Revit.GeometryConversion)
clr.ImportExtensions(Revit.Elements)
clr.AddReference('RevitServices')
import RevitServices
from RevitServices.Persistence import DocumentManager
from RevitServices.Transactions import TransactionManager
import os.path
from os import path
import shutil
import time
doc = DocumentManager.Instance.CurrentDBDocument
uidoc=DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument
#Preparing input from dynamo to revit
filepath = IN[0]
destination = IN[1]
result = []
x = False
j = 0
while x == False:
j += 1
for i in filepath:
result.append(path.exists(i))
if all(result) == False:
result = []
time.sleep(1)
else:
x = True
if j == 30:
break
if x == True:
y = 0
for j in filepath:
shutil.move(filepath[y], destination[y])
y += 1
#Do some action in a Transaction
#TransactionManager.Instance.EnsureInTransaction(doc)
#TransactionManager.Instance.TransactionTaskDone()
OUT = x