# Revit Array to String

**URL:** <https://forum.dynamobim.com/t/revit-array-to-string/27506>\
**Category:** Uncategorized\
**Created:** [October 22, 2018, 3:25pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506 "2018-10-22T15:25:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![cchapel](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@cchapel](https://forum.dynamobim.com/u/cchapel)\
**Post date:** [October 22, 2018, 3:25pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/1 "2018-10-22T15:25:10Z")

</div>

I need to get from the list in the Watch window (see images) to a List like this:

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751744’,’612’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751744’,’794693’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751744’,’2077197’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751744’,’2081627’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751795,’612’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751795,’794693’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751795,’2077197’)

INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES (‘751795,’2081627’)

 ![Dynamo%20Array](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/a/f/af5c02e83309f9e7717e4a2f781de0571e882e1a.jpeg)

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [October 22, 2018, 3:28pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/2 "2018-10-22T15:28:44Z")

</div>

Is the final output supposed to be a string ? I think the easiest way would be through a Python node (i.e. loop thourgh the list in the left to create the (‘A’,‘B’) part and then just add to it the initial part by hand).

---

<div class="post-metadata">

**Author:** ![cchapel](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@cchapel](https://forum.dynamobim.com/u/cchapel)\
**Post date:** [October 22, 2018, 3:36pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/3 "2018-10-22T15:36:36Z")

</div>

Yes, the final output should be a string. However, I am brand new to Dynamo with no Python experience. Any examples I could follow?

Thanks!

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [October 22, 2018, 3:58pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/4 "2018-10-22T15:58:31Z")

</div>

Try to learn some Python with what you can find online, that will be useful during your Dynamo journey 🙂

 ![Capture](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/0/b/0b4c9d8becf5f0cdcba6021368ae0647bcd0cc55.png)

 ![2018-10-22%2017_58_43-Python%20Script](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/7/6/76b13e8cb8f7d5a4e2ee7a71c857313fca7d7597.png)

```
numbers = IN[0]

result = []

for i in range(len(numbers)):
    for j in range(len(numbers[i][1])):
        result.append("INSERT INTO tblRevitInstancesMaterials (RevitInstanceID, MaterialID) VALUES ('"+str(numbers[i][0])+"',"+str(numbers[i][1][j])+"')");

OUT = result
```

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [October 22, 2018, 4:07pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/5 "2018-10-22T16:07:59Z")

</div>

Hey, sorry for the dumb question, could you spell out to me what exactly the numbers[i][1] bit is doing?

I get that it is defining the length of the range, but not how it does it!

Thanks 🙂

Mark

---

<div class="post-metadata">

**Author:** ![cchapel](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@cchapel](https://forum.dynamobim.com/u/cchapel)\
**Post date:** [October 22, 2018, 4:13pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/6 "2018-10-22T16:13:34Z")

</div>

Thanks! This is exactly what I needed. Seems like Python will be very useful!

Just have to figure out why I am getting this warning:

Warning: IronPythonEvaluator.EvaluateIronPythonScript operation failed.  
unexpected token ‘;’

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [October 22, 2018, 4:14pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/7 "2018-10-22T16:14:34Z")

</div>

Probably a typo, check that you are doing a : after the ))

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [October 22, 2018, 4:15pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/8 "2018-10-22T16:15:03Z")

</div>

Hi Mark 🙂

`range(len(numbers))` gives the length of the overall list @L4 (in my example 2 --\> `range(2) = [0,1]`).

`range(len(numbers[i][1]))` gives the length of the last layer of sublists. Here, I loop through the entire list @L4, then each sublist @L2 : the [1] part is only here because of the unique structure of the list @L4. Here, the length of the last sublists are 4 and 4.

I don’t know if that’s clear enough 😕

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [October 22, 2018, 4:15pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/9 "2018-10-22T16:15:56Z")

</div>

Yeah sorry, as @Mark.Ackerley said, it was a typo (EDIT : two typos actually). I corrected the script. Please refer to the screenshot of the script, it is correct.

---

<div class="post-metadata">

**Author:** ![cchapel](https://avatars.discourse-cdn.com/v4/letter/c/49beb7/32.png) [@cchapel](https://forum.dynamobim.com/u/cchapel)\
**Post date:** [October 22, 2018, 4:22pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/10 "2018-10-22T16:22:14Z")

</div>

Awesome! Thanks!

---

<div class="post-metadata">

**Author:** ![Mark.Ackerley](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/mark.ackerley/32/79310_2.png) [@Mark.Ackerley](https://forum.dynamobim.com/u/Mark.Ackerley)\
**Post date:** [October 22, 2018, 4:22pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/11 "2018-10-22T16:22:25Z")

</div>

So you are able to use ‘1’ because @ level 2, the item is always at position 1… however you don’t know how many items there might be @ level 4 so you need to use [i] to iterate through them all? I would never have realised that they were in that order…! Thanks!

---

<div class="post-metadata">

**Author:** ![mellouze](https://avatars.discourse-cdn.com/v4/letter/m/e47774/32.png) [@mellouze](https://forum.dynamobim.com/u/mellouze)\
**Post date:** [October 22, 2018, 4:27pm UTC](https://forum.dynamobim.com/t/revit-array-to-string/27506/12 "2018-10-22T16:27:55Z")

</div>

> [@Mark.Ackerley](#):
>
> So you are able to use ‘1’ because @ level 2, there is only ‘1’ item… however you don’t know how many items there might be @ level 4 so you need to use [i] to iterate through them all?

Exactly !

`i` refers to the index of the items at @L3, so `i` must be between 0 and the length of the big list @L4.  
Then, we know for sure about the structure of each sublist @L3, so we can use `[0]` and `[1]`.  
Finally, we don’t know how many items there are in each sublist @L2, so `j` refers to those indexs.

Note that `numbers[i][0][j]` does not appear in the script, as `numbers[i][0]` is a int and not a list, so `numbers[i][0][j]` does not make any sense for Python.
