# Using an index from LoopWhile

**URL:** <https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395>\
**Category:** Revit\
**Tags:** dynamo, looping, export\
**Created:** [May 10, 2022, 1:49pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395 "2022-05-10T13:49:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfx](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jpfx](https://forum.dynamobim.com/u/jpfx)\
**Post date:** [May 10, 2022, 1:49pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/1 "2022-05-10T13:49:55Z")

</div>

I am trying to export a (single) familytype in a project to DWG and IFC with different parameters (width, Height) which I read from excel.

Therfore I first put the single instance in a single view and read the parameter values in a matrix (list). Then I want to loop through list, updating the parameter values from the list by index number, and export the resulting element in the view before moving to the next index.

 ![loopwhile](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/3/a/3a7812fa0edbab2468a21f13413a5c9600527348.jpeg)

I thought I finally got that Loopwhile working, but it isn’t. It is only exporting the last one (which is probably the result).

How do I get this to work driven by the loop index, without creating a cyclic loop…

---

<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:** [May 10, 2022, 2:18pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/2 "2022-05-10T14:18:31Z")

</div>

It’s hard to tell from your explanation if you’re trying to update the same parameter with multiple values and essentially save a snapshot of each value or if you only have one value for each parameter. Regardless, if you want a snapshot of each state of the updated element you’ll have to create a new transaction for each change, which will either mean using Python or splitting up your values into separate exports. The latter is probably the easiest to manage.

FYI the reason this isn’t working is due to how Dynamo executes. Dynamo already iterates through a list automatically, so `LoopWhile` really isn’t needed. Nodes tend to execute in-line so even if `LoopWhile` stepped through each item individually it would still have to complete before passing that information on to `Set_Parameters`. Once all the nodes have executed, Dynamo then commits a single transaction by default. Meaning your data gets written to your DWG all at once. As I said above, the way to get around this is to either write your own Python code to force individual transactions to the DWG or to split your initial list of data into the separate instances that you expect in the end.

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [May 10, 2022, 2:22pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/3 "2022-05-10T14:22:53Z")

</div>

hi,

i can just post a general issue:

 ![2022-05-10_16h22_28](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/4/b/4b3dce41b317cb40363df7e028fbed960693ee34.png)

```auto
i = IN[0]

OUT = []

while i < 6:
  OUT.append(i)
  i += 1
else:
  OUT.append("i is no longer less than 6")

```

---

<div class="post-metadata">

**Author:** ![jpfx](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jpfx](https://forum.dynamobim.com/u/jpfx)\
**Post date:** [May 10, 2022, 2:26pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/4 "2022-05-10T14:26:43Z")

</div>

I think you are correct. The issues seems to be I try to do it on a single intance.  
Alternatively i tried it with an index list (so each item gets its own index number). The end result is simular, except the output of “intance” in FD25\_Set\_Parameters does indeed become a list, conaining x times the same instance. That seems to be written x times as the same export file…

The reason I was trying it this way, is that previously I used to create multiple instances, create a view for each instances (where all others are hidden) and export those. However, in this case it would handle about 3500 instances, which litteraly crashes Revit ☹ . Looks like I will have to make a deep dive into python (which if havent done before)…

---

<div class="post-metadata">

**Author:** ![Draxl\_Andreas](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/draxl_andreas/32/145744_2.png) [@Draxl\_Andreas](https://forum.dynamobim.com/u/Draxl_Andreas)\
**Post date:** [May 10, 2022, 2:50pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/5 "2022-05-10T14:50:43Z")

</div>

You can also “break” your while-loop unitil a certian level. @jpfx

```auto
i = IN[0]

OUT = []

while i < 350:
  OUT.append(i)
  i += 1
  break

```

---

<div class="post-metadata">

**Author:** ![truevis](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/truevis/32/8634_2.png) [@truevis](https://forum.dynamobim.com/u/truevis)\
**Post date:** [May 10, 2022, 2:56pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/6 "2022-05-10T14:56:38Z")

</div>

> [@jpfx](#):
>
> create a view for each instances (where all others are hidden) and export those. However, in this case it would handle about 3500 instances, which litteraly crashes Revit

How about process 350 at a time?

---

<div class="post-metadata">

**Author:** ![jpfx](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@jpfx](https://forum.dynamobim.com/u/jpfx)\
**Post date:** [May 10, 2022, 3:04pm UTC](https://forum.dynamobim.com/t/using-an-index-from-loopwhile/76395/7 "2022-05-10T15:04:12Z")

</div>

Yeah, I will be splitting up the excel file to multiple sheets, then run it multiple times.  
Just hoped to get it done quicker (and in just one batch).
