# Windows name/path from expression

**URL:** <https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168>\
**Category:** Ignition\
**Created:** [December 3, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168 "2020-12-03T12:56:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 12:56pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/1 "2020-12-03T12:56:10Z")

</div>

I don’t find any ways to show the windows path or name in runtime:

what I “want” is show the windows path in a little label

Does someone have advice?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 1:22pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/2 "2020-12-03T13:22:05Z")

</div>

You can use a tag binding. This line works as an expression too.

```auto
{[System]Client/User/CurrentWindow}

```

Note that this only works when you switch main windows. I think if you open a popup window, it will still show the main window’s name and not the popup name. You might can get creative if the system tag doesn’t work by using

```auto
system.gui.getOpenedWindowNames()

```

[system.gui.getOpenedWindowNames - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)](https://docs.inductiveautomation.com/display/DOC81/system.gui.getOpenedWindowNames)

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 2:13pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/3 "2020-12-03T14:13:08Z")

</div>

What you say is very clear… but is not what I looking for…

I can’t believe that no exist a way to know the path of a window.

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 2:18pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/4 "2020-12-03T14:18:34Z")

</div>

Can you give an example of your window path, and what you expect to see displayed in the label?

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 2:29pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/5 "2020-12-03T14:29:20Z")

</div>

something like that:

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/8/c8753a12442976aca0af83fac024beb14cba0603.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [December 3, 2020, 2:37pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/6 "2020-12-03T14:37:44Z")

</div>

If you have a direct reference to the window you can use path.

```auto
w = system.gui.getWindow("Old windows/Pop_ItemEntry")
print w.path

```

prints “Old windows/Pop\_ItemEntry” for me. So you probably want to do this on a window startup script.

It seems to me in visionWindowOpened, you could do the following

```auto
windowPath = event.source.path
myComponent.text = windowPath

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 2:44pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/7 "2020-12-03T14:44:46Z")

</div>

That seems to be a work around, but you would have to add this script to every single popup window. It would be a lot nicer if the window had a path property by default.

I would set the popup Title property to your path

```auto
system.gui.getParentWindow(event).getComponentForPath('_parent').title = event.source.path

```

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 2:47pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/8 "2020-12-03T14:47:48Z")

</div>

mmm … like you say sure work but for do that i need to:

already know the path  
make same script code.

suppose that: you want create a simple label to show the path (like in my pic) and copy that in all your windows how to do? no ways?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 2:58pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/9 "2020-12-03T14:58:59Z")

</div>

this will do it. Just paste this code in a label’s propertyChange event script

```auto
if event.propertyName == 'componentRunning':
	event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path

```

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 3:07pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/10 "2020-12-03T15:07:04Z")

</div>

> [@dkhayes117](#):
>
> if event.propertyName == 'componentRunning': event.source.text = system.gui.getParentWindow(event).getComponentForPath('\_parent').path

Work fine thanks

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 3:11pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/11 "2020-12-03T15:11:35Z")

</div>

errata corride:  
work almost fine … but when the you close the windows generate the alarm …

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 3:40pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/12 "2020-12-03T15:40:39Z")

</div>

It is probably trying to fire when you close the window as well as when it is opened. It cannot get the window path if the window is already closed, so wrap this up in a try except block.

```auto
if event.propertyName == 'componentRunning':
	try:
		event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
	except:
		pass

```

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 3:47pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/13 "2020-12-03T15:47:30Z")

</div>

I modify your idea like that … same advice?

```auto
if event.propertyName == 'componentRunning' and event.newValue == 1:
  try:	
    event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
  except:
    pass

```

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [December 3, 2020, 3:50pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/14 "2020-12-03T15:50:59Z")

</div>

You shouldn’t need the `event.newValue` part unless it is part of other functionality you want. The try except will handle the error message by itself

---

<div class="post-metadata">

**Author:** ![schenk](https://avatars.discourse-cdn.com/v4/letter/s/6bbea6/32.png) [@schenk](https://forum.inductiveautomation.com/u/schenk)\
**Post date:** [December 3, 2020, 4:07pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/15 "2020-12-03T16:07:12Z")

</div>

You should also consider putting this into a template. Then if you decide you want to change the font, border, background, etc, you only have to change it once for the project(s).

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 3, 2020, 5:28pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/16 "2020-12-03T17:28:14Z")

</div>

After the discussion i make a simple template

> **[Ignition Exchange](https://inductiveautomation.com/exchange/2109/overview)**
>
> Discover, share, and download community made Ignition resources in collaboration with your organization or the Ignition community.

hope can help

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [December 3, 2020, 6:26pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/17 "2020-12-03T18:26:20Z")

</div>

If it’s a Java error you have to `except` the Java error too. Try:

```auto
import java
if event.propertyName == 'componentRunning' and event.newValue == 1:
  try:	
    event.source.text = system.gui.getParentWindow(event).getComponentForPath('_parent').path
  except:
    pass
  except java.lang.Exception:
    pass

```

---

<div class="post-metadata">

**Author:** ![stra](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/stra/32/23678_2.png) [@stra](https://forum.inductiveautomation.com/u/stra)\
**Post date:** [December 4, 2020, 7:15am UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/18 "2020-12-04T07:15:54Z")

</div>

> [@chasondeshotel](#):
>
> except java.lang.Exception: pass

I'm no very expert in python but the sense of put one more control in the "try" is not clear:  
"except:" is the default answer to the issue; if we put one more same the default what change?  
Can you explain to me the advantage?

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [December 4, 2020, 7:45am UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/19 "2020-12-04T07:45:56Z")

</div>

The default `except` will _not_ capture Java errors and if any Java errors occur, you’ll still get an exception without the additional `except` statement

---

<div class="post-metadata">

**Author:** ![chasondeshotel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/chasondeshotel/32/20032_2.png) [@chasondeshotel](https://forum.inductiveautomation.com/u/chasondeshotel)\
**Post date:** [December 8, 2020, 9:21pm UTC](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168/20 "2020-12-08T21:21:27Z")

</div>

This is a quirk of Jython

But… did this change in 8? I was typing up an example and noticed `except: pass` catches both Python and Java errors

However, `except Exception, e` only catches Python errors in which case you have to add the extra except block for Java errors

It’s entirely possible I never realized this because I seldom handle exceptions without doing something with the error message

[Next page](https://forum.inductiveautomation.com/t/windows-name-path-from-expression/41168.md?page=2)
