# Toggle Data Dam

**URL:** <https://discourse.mcneel.com/t/toggle-data-dam/190183>\
**Category:** Grasshopper\
**Tags:** windows\
**Created:** [August 27, 2024, 5:43pm UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183 "2024-08-27T17:43:06Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanlundberg77](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/nathanlundberg77/32/713373_2.png) [@nathanlundberg77](https://discourse.mcneel.com/u/nathanlundberg77)\
**Post date:** [August 27, 2024, 5:43pm UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/1 "2024-08-27T17:43:06Z")

</div>

Hello,

I may be beating a dead horse here but I’ve been looking into a way to, essentially, toggle a data dam on/off. I want to be able to change input data on a component without changing the existing output data until it is toggled. Once toggled, the new data is output once and remembered until the component is toggled again… so on a so forth. This means _no resending_ the same existing data when the input is changed, no sending nulls, no nothing that would trigger a re-computation of the script down the stream.

This does not work with data streams, cull patterns, record, or anything else in native grasshopper. Data dam works perfectly except you have to press the component so this doesn’t work well on larger scripts (time consuming), doesn’t work in the grasshopper remote panel, or in [HumanUI](https://www.food4rhino.com/en/app/human-ui). I’m very interested in using this for all three of these situations. The other thing is that data dam remembers saved information when you re-open the file, I don’t not care about that function much.  
This thread mentions data dams having some memory issue:

> [@Going large: advice/resources for optimising](https://discourse.mcneel.com/t/going-large-advice-resources-for-optimising/86202/6):
>
> Hi @jeremy5, There is one thing you need to take note when using data dams. Even if they are set to Never they are calculated when you open (re-open) a gh definition. This leads to a long wait (depending on the definition). Along with data dams I use a python script with a Togglethat my wire goes through before entering the data dam. This script sets the output of my ghpython, respectively the input of the datadam to Null. I turn this off when saving the gh file. I use this wherever I have a…

This thread mentions using metahopper in combination with data dam but in my testing it is very glitchly and unreliable:  
[https://www.grasshopper3d.com/forum/topics/set-store-and-refresh-an-input-remote-data-dam?id=2985220%3ATopic%3A1505696&page=2#comments](https://www.grasshopper3d.com/forum/topics/set-store-and-refresh-an-input-remote-data-dam?id=2985220%3ATopic%3A1505696&page=2#comments)

I’ve looked through many threads and done some testing of my own to find a solution. I’ve tested tricks with metahopper, C#, and native grasshopper and **only one method works… kinda.**

Here is the test gh file:  
[Special\_Gates.gh](https://discourse.mcneel.com/uploads/short-url/2XqbakRA1V61BLlBLEU8iuXTwjD.gh) (17.7 KB)

 ![2024-08-27 10_34_59-Grasshopper - Special_Gates_](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/1/c/41c469be90b577ad4d4d4633031950f0c5c786c4.png)

- **Native grasshopper: (failure)** Using a cull pattern/stream etc, sends out nulls/repeated data which cause a recalculation
- **Metahopper: (failure)** Works but will randomly seem to reset and release a new set of data, causing a recalculation, you can see in the screen shot how the panel has a red time on it because it keeps receiving data, scary as it can quickly escalate to huge amounts. The screenshot shows one way to connect objects in methopper, the other way doesn’t require the wires to be connected but the issues remain the same
- **C# (method 1): (failure)** Appears to work until you see it it is secretly releasing nulls [WISH : Data dam with trigger input - #3 by Mahdiyar](https://discourse.mcneel.com/t/wish-data-dam-with-trigger-input/120926/3)
- **C# (method 2): (semi-success)** This is the only one that I think works but it is a pain to setup for multiple inputs and it seems a bit hacky as it seems to allow loops/break grasshopper logic. For this one to work you need to connect the top Data component into the ID which will (no idea why) not keep the wire. Then the C# component will update the Data with received data once triggered. C# also unreferences the geometry (not super important).

Here is an interesting response from David Rutten but the trails seems the end there: [How to trigger updates down only selected outputs of component? - #3 by DavidRutten](https://discourse.mcneel.com/t/how-to-trigger-updates-down-only-selected-outputs-of-component/68441/3)

Other threads:

> [@WISH : Data dam with trigger input](https://discourse.mcneel.com/t/wish-data-dam-with-trigger-input/120926):
>
> I want some parts of my definition to allow a new flow of data only upon a certain trigger. The data dam would be perfect for this, but it’s one of those silly components that requires a button to be pressed on the component. I managed to hacke it with Metahopper, following [this post](https://www.grasshopper3d.com/forum/topics/data-dam-in-runtime). [Trigger for data dam.gh](https://discourse.mcneel.com/uploads/short-url/aIghBqLEzqAgzFREJFZdhcqkkMp.gh) (14.2 KB) I really wish this component had a proper input for triggering.

[https://www.grasshopper3d.com/forum/topics/data-dam-in-runtime](https://www.grasshopper3d.com/forum/topics/data-dam-in-runtime)  
[https://www.grasshopper3d.com/forum/topics/data-dam-on-off-switch](https://www.grasshopper3d.com/forum/topics/data-dam-on-off-switch)  
[https://www.grasshopper3d.com/forum/topics/set-store-and-refresh-an-input-remote-data-dam](https://www.grasshopper3d.com/forum/topics/set-store-and-refresh-an-input-remote-data-dam)  
[https://www.grasshopper3d.com/forum/topics/data-dam-in-remote-control-panel](https://www.grasshopper3d.com/forum/topics/data-dam-in-remote-control-panel)

> [@Data dam toggle/trigger](https://discourse.mcneel.com/t/data-dam-toggle-trigger/83158):
>
> I’m using the kinect component project owl, it constantly reads the kinect and outputs new point cloud, but I only need new data when I need it, so I’m using a data dam and it works great. But the problem is i have to click the data damn manually, I’m wondering if it’s possible to trigger it with code/components. For example, I’m reading an integer value from a file, and if the file is equal to a specific value, new data is let thru the data damn. I see that there’s a timer for data damn, but…

I thank anyone for any help/advice on the matter. If any McNeel empolyee see this, having this function directly in grasshopper would be EXTREMELY useful and I can see from the many threads around the community that I am not the only one with this desire.

---

<div class="post-metadata">

**Author:** ![victorlin](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/victorlin/32/661383_2.png) [@victorlin](https://discourse.mcneel.com/u/victorlin)\
**Post date:** [August 28, 2024, 3:56am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/2 "2024-08-28T03:56:12Z")

</div>

In the last post you reference, you’ll see that i found the solution using scripts.  
If you don’t want to script it yourself, I made a plugin that includes this function  
look for `melanoplus` in package manager  
in the plugin, use the component `Idempotent`  
[Components · lin-ycv/Melanoplus Wiki (github.com)](https://github.com/lin-ycv/Melanoplus/wiki/components)

---

<div class="post-metadata">

**Author:** ![Quan\_Li](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/quan_li/32/679256_2.png) [@Quan\_Li](https://discourse.mcneel.com/u/Quan_Li)\
**Post date:** [August 28, 2024, 11:15pm UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/3 "2024-08-28T23:15:18Z")

</div>

See here, it uses the one from Heteroptera

> [@Beauty of not organic Multipipe](https://discourse.mcneel.com/t/beauty-of-not-organic-multipipe/176735):
>
> [Beauty of not organic Multipipe v5.gh](https://discourse.mcneel.com/uploads/short-url/bieiv4wev9Uo7ESyspUof7SVAYn.gh) (28.4 KB) All geometries can be transformed into printable mesh or closed BREP easily. [[Beauty of not organic Multipipe] ](https://www.youtube.com/watch?v=ZuqckThQgRM)

 ![Screenshot_2024-08-29-07-15-31-751_com.microsoft.emmx-edit](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/a/8/4/a8463cdc49df7e131f2265f23cb978934e3e2416.jpeg)

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [August 29, 2024, 7:17am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/5 "2024-08-29T07:17:24Z")

</div>

It looks like one just needs to expire a data dam to pass data through it (i.e. simply recomputing a definition will also work). Here’s a quick GhPython script that appears to work as expected. I usually target specific components on canvas via their `NickName` when using this coding pattern (i.e. iterating all components on canvas by type, followed by nick name). But it doesn’t seem possible to edit this directly on data dams, so here I’m targeting by names of the first input parameter instead:

  
[240829\_TransferDataDams\_02.gh](https://discourse.mcneel.com/uploads/short-url/qcnSz7EJ78sKOCf93MpxEV4fH2I.gh) (9.7 KB)

**Edit:** Removed previous post/definitions for clarity.

---

<div class="post-metadata">

**Author:** ![nathanlundberg77](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/nathanlundberg77/32/713373_2.png) [@nathanlundberg77](https://discourse.mcneel.com/u/nathanlundberg77)\
**Post date:** [October 23, 2024, 10:21pm UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/6 "2024-10-23T22:21:54Z")

</div>

Hi Anders, this solution works perfectly. Simple to implement, no plugins, works great. Thank you.

I do have one more question though, maybe you could help me with it. When you start a grasshopper script, data dams instantly pass through whatever data is connected to them. This isn’t ideal as I would rather have it run when I press the button that you setup above. I’m wondering if there’s a way to instantly disable the data dams at the beginning of the script, and then enable them only once I press the button.

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [October 24, 2024, 6:48am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/7 "2024-10-24T06:48:19Z")

</div>

> [@nathanlundberg77](#):
>
> When you start a grasshopper script, data dams instantly pass through whatever data is connected to them.

Hmm, I never actually noticed that. I wonder if that’s the intended behaviour, feels like a bug,

> [@nathanlundberg77](#):
>
> I’m wondering if there’s a way to instantly disable the data dams at the beginning of the script, and then enable them only once I press the button.

Here’s a quick hacky workaround, where we lock/disable the targeted data dams on the first canvas run, and then unlock/enable them again when the transfer button is pushed. This requires that the GhPython must compute first, which is solved here by sending it the back with Ctrl + B (see [this great article](https://james-ramsden.com/tag/draw-order/)):

 ![2024-10-24 08_34_36-Grasshopper - 240829_TransferDataDams_02_](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/f/2/4f2f2945add606c97868e98e13d687d26c3abae0.png)  

  
[241024\_TransferDataDams\_00.gh](https://discourse.mcneel.com/uploads/short-url/ptvXUB59h8bm6YUWPIIq5pSGD0Q.gh) (8.9 KB)

**Edit:** Unlocking the dams appear to raise an expiration error when you first run the script. You can choose to ignore those warning and it should work as expected, but obviously we should code that out. I’ll have a look when I get a moment.

---

<div class="post-metadata">

**Author:** ![AndersDeleuran](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/andersdeleuran/32/476683_2.png) [@AndersDeleuran](https://discourse.mcneel.com/u/AndersDeleuran)\
**Post date:** [October 24, 2024, 7:24am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/8 "2024-10-24T07:24:31Z")

</div>

> [@AndersDeleuran](#):
>
> … but obviously we should code that out. I’ll have a look when I get a moment.

I don’t like how these functions operate on globals variables (not sure if the scheduling callback function can take input parameters), but this appears to work without raising any errors and such:

 ![2024-10-24 09_21_15-Grasshopper - 241024_TransferDataDams_00(1)](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/4/3/9/43980f701cc1b5b4582394928a37b9a321a8dd44.png)  
[241024\_TransferDataDams\_01.gh](https://discourse.mcneel.com/uploads/short-url/6wThRWctc4zFMgtXXDA13uArexy.gh) (9.5 KB)

---

<div class="post-metadata">

**Author:** ![Gorkagire](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gorkagire/32/659239_2.png) [@Gorkagire](https://discourse.mcneel.com/u/Gorkagire)\
**Post date:** [June 10, 2025, 1:30am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/9 "2025-06-10T01:30:27Z")

</div>

This super useful Anders, I’m using it in combination with UI so these can be triggered form outside the canvas, would it be tweaked so that it enables disables \*Flase/True anything by it’s nick name (not it’s input name) thanks once again, I love your work using nicknames!

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/5/7/7/5779f055d5f5a80e7c695c4f6e914ea9591d0a6e.png)

---

<div class="post-metadata">

**Author:** ![Gorkagire](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/gorkagire/32/659239_2.png) [@Gorkagire](https://discourse.mcneel.com/u/Gorkagire)\
**Post date:** [June 10, 2025, 2:20am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/10 "2025-06-10T02:20:26Z")

</div>

done here it is:

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/d/2/7d2b86a387fcb6e7f8d0fd94c6443d22ab6d39d6.jpeg)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/4X/7/6/4/76471e9ba36c3bd53dbf1c8e7df37331a9a57f6f.png)

[250610\_Batch ENABLE-DISABLE components by NM.gh](https://discourse.mcneel.com/uploads/short-url/v4PEL8yHqBLQA83cEKtjkjVpVC8.gh) (6.1 KB)

---

<div class="post-metadata">

**Author:** ![Piotr](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/piotr/32/635473_2.png) [@Piotr](https://discourse.mcneel.com/u/Piotr)\
**Post date:** [March 11, 2026, 11:35am UTC](https://discourse.mcneel.com/t/toggle-data-dam/190183/11 "2026-03-11T11:35:45Z")

</div>

V9

I am experiencing series of crashes.

[RhinoCrashDump.gh](https://discourse.mcneel.com/uploads/short-url/2FEfheRdAmCV5j0ZPAA14BRkefp.gh) (37.0 KB)

First time use is OK, update causes crash.
