# Scripting the Z-Order of an object

**URL:** <https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106>\
**Category:** Ignition\
**Created:** [March 5, 2014, 3:17pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106 "2014-03-05T15:17:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![drumdubb](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@drumdubb](https://forum.inductiveautomation.com/u/drumdubb)\
**Post date:** [March 5, 2014, 3:17pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/1 "2014-03-05T15:17:26Z")

</div>

Is there a way to have a timer script constantly update the z-order of a specific object? I want to add a condition for one object to be hidden behind another until the condition is true. I was wanting to add 1 to the z-order of said object during this condition. I looked up that this is possible using the z-index function in java, but I’m not sure how to do it in Python within Ignition

-D ![:thumb_left:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/e26afb081ddde6df016df6ee49159cf56aaca688.gif ":thumb\_left:")

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 5, 2014, 3:52pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/2 "2014-03-05T15:52:58Z")

</div>

Well you could try calling the setComponentZOrder(Component comp, int index) method on a container to set the z-order index on a component in the container.

Example:

```auto
container = event.source.parent
container.setComponentZOrder(event.source,10)
```

---

<div class="post-metadata">

**Author:** ![drumdubb](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@drumdubb](https://forum.inductiveautomation.com/u/drumdubb)\
**Post date:** [March 5, 2014, 6:36pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/3 "2014-03-05T18:36:06Z")

</div>

I got the z-order to change thanks to your suggestion. The issue now is that when I launch the project, the z order only updates when you change the tag in designer and then save (then updating the project in the full screen). I have a timer script running on property change so I don’t think it’s a scan issue with the tag.

also : is there a way to view the z index number of an object within designer?

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 5, 2014, 7:22pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/4 "2014-03-05T19:22:50Z")

</div>

You can print out the z order index with:

```auto
container = event.source.parent
print container.getComponentZOrder(event.source)
```

I don’t understand, what do tags have to to with z order indexes on components? What tag?

---

<div class="post-metadata">

**Author:** ![drumdubb](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@drumdubb](https://forum.inductiveautomation.com/u/drumdubb)\
**Post date:** [March 5, 2014, 8:14pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/5 "2014-03-05T20:14:24Z")

</div>

Sorry, referring to my original post. I have an expression that when said tag value is below 4 to change the z index to 8. else it will change it to 9. When I manually modify this tag in the OPC tag browser, the running project does not update the z-order on the live graphics until the original project is saved within designer.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 5, 2014, 9:34pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/6 "2014-03-05T21:34:21Z")

</div>

Can you show the expression and the script that changes the z order?

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [March 5, 2014, 9:35pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/7 "2014-03-05T21:35:19Z")

</div>

Can you write a simple event script that changes the z order of a component? Does it work in the client?

---

<div class="post-metadata">

**Author:** ![drumdubb](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@drumdubb](https://forum.inductiveautomation.com/u/drumdubb)\
**Post date:** [March 5, 2014, 10:58pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/8 "2014-03-05T22:58:49Z")

</div>

I have a timer on the screen set to 100ms scan cycle.

On property change, this timer sets a custom property (int) on my object equal to the current count of the timer, cascading the property change to the object itself.

I have an on-property change script on the object :

[code]if system.tag.read(“_eicn133PLC_/Global/currentDomePosition”).value \< 4:  
container = event.source.parent  
container.setComponentZOrder(event.source,9)

else:  
container = event.source.parent  
container.setComponentZOrder(event.source,8)[/code]

---

<div class="post-metadata">

**Author:** ![James.Lorenz](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/james.lorenz/32/3290_2.png) [@James.Lorenz](https://forum.inductiveautomation.com/u/James.Lorenz)\
**Post date:** [March 6, 2014, 9:10pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/9 "2014-03-06T21:10:57Z")

</div>

See if calling repaint() fixes things:

```auto
if system.tag.read("_eicn133PLC_/Global/currentDomePosition").value < 4: 
   container = event.source.parent
   container.setComponentZOrder(event.source,9)

else:
   container = event.source.parent
   container.setComponentZOrder(event.source,8)

container.repaint()
```

---

<div class="post-metadata">

**Author:** ![drumdubb](https://avatars.discourse-cdn.com/v4/letter/d/9de053/32.png) [@drumdubb](https://forum.inductiveautomation.com/u/drumdubb)\
**Post date:** [March 10, 2014, 8:32pm UTC](https://forum.inductiveautomation.com/t/scripting-the-z-order-of-an-object/8106/10 "2014-03-10T20:32:42Z")

</div>

That worked flawlessly! Thanks! 😃
