# Create binding programatically

**URL:** <https://forum.inductiveautomation.com/t/create-binding-programatically/33360>\
**Category:** Ignition\
**Created:** [February 27, 2020, 7:01am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360 "2020-02-27T07:01:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [February 27, 2020, 7:01am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/1 "2020-02-27T07:01:26Z")

</div>

Hi!  
How to set binding via scripts?  
I need markers have to change its colors when something happens (Alarm for example)  
I know how to set binding via hands, but I need to do it via script! Please help me ASAP 🙂

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [March 2, 2020, 9:13am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/2 "2020-03-02T09:13:59Z")

</div>

ok guys)  
I did it by myself)  
If someone has the same trouble as I did, so I can tell You how I did it 😉

---

<div class="post-metadata">

**Author:** ![func](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@func](https://forum.inductiveautomation.com/u/func)\
**Post date:** [March 23, 2020, 1:05pm UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/3 "2020-03-23T13:05:15Z")

</div>

Hey israc, I have the same issue where I am trying to set binding via script, but am not successful. Can you please share how you set a binding via script? I am interested in setting a tag binding via script. Thanks

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [March 23, 2020, 9:37pm UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/4 "2020-03-23T21:37:22Z")

</div>

Hi,  
If You want some actions when a new alarm comes, then create a new expression tag (select active alarms by function _system.alarm.queryStatus_). Then make a Tag Event Script on this tag when value changes its state. In this script call the Gateway Script, which _(as I did: I created a new memory boolean tag)_ sets a Boolean tag to **true** , then go to perspective and check if this Boolean tag is **true** , then run script, which goes through all your markers and sets on desired marker color to red (if a New alarm appeared) and set this tag to **false**

The idea is:  
New Alarm —\> Gateway Script —\> Boolean Tag = True —\> Perpsective: run script —\> set Boolean tag to False

Hope it helps You 🤗

---

<div class="post-metadata">

**Author:** ![func](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@func](https://forum.inductiveautomation.com/u/func)\
**Post date:** [March 24, 2020, 12:40am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/5 "2020-03-24T00:40:42Z")

</div>

Thanks for the info. But, I was actually more interested in programmatically setting up a tag binding in Python code. I am trying to populate a table with data that changes (based on tags) and some of the cells need to be bound to the tag that it reads the value from. I have a script on the onStartup function of the table which loads data from a dataset and populates the table with it. However, I need a way to set up the bindings on the values in the table that update. Thanks

---

<div class="post-metadata">

**Author:** ![iscrac](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/iscrac/32/49757_2.png) [@iscrac](https://forum.inductiveautomation.com/u/iscrac)\
**Post date:** [March 24, 2020, 6:50am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/6 "2020-03-24T06:50:30Z")

</div>

Yes. I was interested in this possibility also, but the best solution for me was to update states when something happens (tag change/new alarm etc).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 24, 2020, 3:26pm UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/7 "2020-03-24T15:26:44Z")

</div>

The short version is basically that you can’t - there’s no way to dynamically create bindings in a running Perspective session. If you need dynamic project _resource_ creation, technically you can do that from the filesystem in 8.0, since Perspective resources are just JSON files - but, you’re entirely on your own in terms of discovering the format and creating valid views.

Long term, it’s possible we’ll expose a more first-class way to create dynamic views - perhaps something akin to Webdev’s Python resource handlers, but no guarantees.

Regardless, it’s probably that dynamically creating bindings isn’t the only solution to your problem; just as @iscrac was able to work around his issue with a different solution. From what you describe, you could have a single expression structure binding bound to each of your tag values. Then add a transform that will extract each value from the pair and dynamically construct the data to display on the table; something akin to this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/fc9c30c29a3d7101d6d1c99e1d66dc69736043b4.png)

(Using an expression structure binding, you don’t have to set up any polling; the expression structure binding will be automatically notified of any changes to the subscribed tags.)

---

<div class="post-metadata">

**Author:** ![func](https://avatars.discourse-cdn.com/v4/letter/f/a587f6/32.png) [@func](https://forum.inductiveautomation.com/u/func)\
**Post date:** [March 26, 2020, 3:18am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/8 "2020-03-26T03:18:06Z")

</div>

Thanks for the response and the information. I ended up building some code outside of Perspective to generate some JSON which I could then just copy and paste back into Perspective. The only lament is, if the data set changes, I will need to regenerate the JSON and copy and paste it back into Perspective. Luckily, this data set will likely never change.

---

<div class="post-metadata">

**Author:** ![r.p](https://avatars.discourse-cdn.com/v4/letter/r/71e660/32.png) [@r.p](https://forum.inductiveautomation.com/u/r.p)\
**Post date:** [September 6, 2021, 10:46am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/9 "2021-09-06T10:46:40Z")

</div>

> [@paul-griffith](#):
>
> Long term, it’s possible we’ll expose a more first-class way to create dynamic views - perhaps something akin to Webdev’s Python resource handlers, but no guarantees.

Any update on allowing programatic binding of values via scripting? we need to add markers in a map component where each marker icon color must change based on a binding which reads the tag status via modbus.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [September 7, 2021, 8:00am UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/10 "2021-09-07T08:00:42Z")

</div>

@nminchin gave some pointers on how to achieve that:

> [@Editing or Creating a Perspective View via Script](https://forum.inductiveautomation.com/t/editing-or-creating-a-perspective-view-via-script/50511):
>
> In case this helps anyone, here’s how you can modify (or create) a Perspective View (or any non-binary resource really) via script. You can call this from any gateway scope, including from a Perspective Button action. Note: the gateway only checks for file updates to resources every 5mins, so you won’t see changes in your client until then, but they will come through automatically. projectName = '' # e.g. 'AwesomeProject' viewPath = '' # e.g. 'Testing/View to Modify' from com.inductiveautomat…

I think this could help you

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [September 7, 2021, 3:17pm UTC](https://forum.inductiveautomation.com/t/create-binding-programatically/33360/11 "2021-09-07T15:17:17Z")

</div>

The short answer is no.  
The feature I described would also not be ‘programmatic binding of values via scripting’, really. That’s a whole different kettle of fish. What I’m describing is a kind of ‘server-side rendering’ for views, where a Python method is called when visiting a page and returns the definition of a view.

That’s also not a confirmed feature by any means; it’s just an idea we had kicking around the office. As @pascal.fragnoud mentioned, if it’s possible to “precompute” these bindings then that’s going to be both more performant and easier to work with…plus it works _now_, not at some vague future time.
