# Reading dynamo script via PowerBI / Power Query

**URL:** <https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558>\
**Category:** Lists-Logic\
**Tags:** excel, dynamo\
**Created:** [December 20, 2023, 4:27am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558 "2023-12-20T04:27:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonlkw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jasonlkw/32/191737_2.png) [@jasonlkw](https://forum.dynamobim.com/u/jasonlkw)\
**Post date:** [December 20, 2023, 4:27am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558/1 "2023-12-20T04:27:32Z")

</div>

Hi there gurus,

Trying to ask if there is a way to read the dynamo scripts properly.  
I am currently using powerBI / excel to query and transform the data to check for duplicates in the Id and Uuid.  
Not really sure if there is a solution here but I just thought I should post this in to try my luck.  
Image below on the structure of the data.  
(redacted info for privacy)

 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/e/4/e4208068d5ce5d81b02ba997722b3aaa04f135e0.png)  
i have managed to somewhat get this to work slightly but trying to find a more optimized solution.  
 ![image](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/8/78408118dfe52d28400a8e23a3adcde23474f599.png)

Hope this perks the interest of any data scientists out there!

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 20, 2023, 6:29am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558/2 "2023-12-20T06:29:38Z")

</div>

A .dyn is a json formatted string, so if you read the text with Dynamo (ReadText) you can then invert the text data to a dictionary by using the json Deserialize node, and from there you can query the file’s properties as desired.

---

<div class="post-metadata">

**Author:** ![Mike.Buttery](https://avatars.discourse-cdn.com/v4/letter/m/b19c9b/32.png) [@Mike.Buttery](https://forum.dynamobim.com/u/Mike.Buttery)\
**Post date:** [December 20, 2023, 9:53am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558/3 "2023-12-20T09:53:18Z")

</div>

Minimal code example

```python
# CPython3
import json
from pathlib import Path

directory = Path(IN[0]).glob("*.dyn")

output = []
for file in directory:
    with open(file) as f:
        try:
            data = json.load(f)
            output.append(data["Uuid"])
        except:
            output.append(str(f))

OUT = output

```

---

<div class="post-metadata">

**Author:** ![jasonlkw](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jasonlkw/32/191737_2.png) [@jasonlkw](https://forum.dynamobim.com/u/jasonlkw)\
**Post date:** [December 25, 2023, 4:42am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558/4 "2023-12-25T04:42:37Z")

</div>

Did a bit of experimentation so… it seems to work if i read the file via json.  
Sharing two solutions here that I have found from the advice above.  
First is the Sandbox method. Unfortunately, I couldn’t get the python script to work from Mike’s code.

 ![JsonData Reader](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/b/2bcd116eeb797eb65598789c137aa6c3776122ed.png)

I believe through dynamo it’ll be a bit more interesting when I downloaded a 2018 package that still works by @alvpickmans  
Kinda opens up a bit of variety for dynamo solutions… Does this mean that I will be able to add certain group of nodes to multiple dyn scripts? Hmmm food for thought.  
 ![JsonData nodes](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/c/2c65f96e5324fe27a2932f5bbe98b5a4206ddce5.png)

The second method, this is a transposed data with hidden Name on PowerBI.  
It does make it nicer and easier to read so I will approach the json with this method instead.

 ![JsonData Reader PowerBI](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/2/a/2ad10115c859d0285f9715429d84ef5198b6fed6.png)

Thus, the more suitable answer is by @jacob.small🙂

Thanks and merry christmas!

---

<div class="post-metadata">

**Author:** ![jacob.small](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/jacob.small/32/161030_2.png) [@jacob.small](https://forum.dynamobim.com/u/jacob.small)\
**Post date:** [December 25, 2023, 11:47am UTC](https://forum.dynamobim.com/t/reading-dynamo-script-via-powerbi-power-query/96558/5 "2023-12-25T11:47:33Z")

</div>

> [@jasonlkw](#):
>
> Does this mean that I will be able to add certain group of nodes to multiple dyn scripts?

Yes, that is doable.

Or swap nodes for non-deprecated versions in bulk. Change the Python engine. Alter scripts. Etc.

If you’d like to check out some examples of stuff like that, check out this [post](https://forum.dynamobim.com/t/updating-python-node-in-multiple-scripts/82637/15) where I outline some tools I presented at BiLT a few years back. It has some Python code to bulk edit Dynamo graphs at scale, as well as some code to prep for automated testing thereof.
