# Python script running before passthrough is executed

**URL:** <https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233>\
**Category:** Revit\
**Created:** [April 5, 2023, 1:43pm UTC](https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233 "2023-04-05T13:43:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![technitutors](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@technitutors](https://forum.dynamobim.com/u/technitutors)\
**Post date:** [April 5, 2023, 1:43pm UTC](https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233/1 "2023-04-05T13:43:58Z")

</div>

Hi All

I have a python script which executes a macro from excel

import clr  
import time  
clr.AddReferenceByName(‘Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’)  
from Microsoft.Office.Interop import Excel  
from System.Runtime.InteropServices import Marshal  
#time.sleep(3)

dirfichier = r"C:\Users\User\Desktop\ESTIMATING SHEETS\test\test steel\Structural Steel Estimate 2023.xlsm"  
ex = Excel.ApplicationClass()  
ex.Visible = True  
ex.DisplayAlerts = False

wb = ex.Workbooks.Open(dirfichier)  
ws = wb.Worksheets[1]

# some code

# 

# time.sleep(3)

# run macro named ‘Dynamo’ in excel

ex.Application.Run(“save1”)  
wb.SaveAs(dirfichier)

if wb is not None:  
Marshal.ReleaseComObject(wb)  
if ex is not None:  
Marshal.ReleaseComObject(ex)  
wb = None  
ex = None

OUT = [0]

Now my problem is it executes BEFORE the second write to excel is created. How do I get it to execute last?

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/8/b89ed2b6836ce753454fb470e96f8f385b0d7cc8.png)

---

<div class="post-metadata">

**Author:** ![technitutors](https://avatars.discourse-cdn.com/v4/letter/t/45deac/32.png) [@technitutors](https://forum.dynamobim.com/u/technitutors)\
**Post date:** [April 5, 2023, 1:45pm UTC](https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233/2 "2023-04-05T13:45:24Z")

</div>

> [@technitutors](#):
>
> `import clr`
> 
> ```auto
> import time
> clr.AddReferenceByName(‘Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’)
> from Microsoft.Office.Interop import Excel
> from System.Runtime.InteropServices import Marshal
> #time.sleep(3)
> 
> dirfichier = r"C:\Users\User\Desktop\ESTIMATING SHEETS\test\test steel\Structural Steel Estimate 2023.xlsm"
> ex = Excel.ApplicationClass()
> ex.Visible = True
> ex.DisplayAlerts = False
> 
> wb = ex.Workbooks.Open(dirfichier)
> ws = wb.Worksheets[1]
> 
> # some code
> 
> # time.sleep(3)
> 
> # run macro named ‘Dynamo’ in excel
> 
> ex.Application.Run(“save1”)
> wb.SaveAs(dirfichier)
> 
> if wb is not None:
> Marshal.ReleaseComObject(wb)
> if ex is not None:
> Marshal.ReleaseComObject(ex)
> wb = None
> ex = None
> 
> OUT = [0]
> 
> ```

```auto

```

---

<div class="post-metadata">

**Author:** ![aaronrumple](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/aaronrumple/32/195292_2.png) [@aaronrumple](https://forum.dynamobim.com/u/aaronrumple)\
**Post date:** [April 5, 2023, 2:47pm UTC](https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233/3 "2023-04-05T14:47:10Z")

</div>

Use the WaitFor node to hold it up until you have the right input.

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [April 5, 2023, 2:53pm UTC](https://forum.dynamobim.com/t/python-script-running-before-passthrough-is-executed/88233/4 "2023-04-05T14:53:13Z")

</div>

That’s because your `PassThrough` is waiting on the first Excel node, not the python node. The `passThrough` input is what gets passed on and the `waitFor` input is what’s waiting to be execute before moving on. You don’t need a `PassThrough` or `Wait` node if the node you’re waiting on is also being passed on to the node you want to wait. A node has to have an input to execute (that’s how `Wait` nodes work) so you can typically rely on a node not executing until the node connecting into it has finished.

Also, as an FYI, please paste code as preformatted text from the _source_. Your second post is still unformatted since (I’m assuming) you copied it from the original paste, which is unformatted.
