# Nav Helper system.nav.openWindowInstace

**URL:** <https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825>\
**Category:** Ignition\
**Created:** [May 8, 2010, 8:27am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825 "2010-05-08T08:27:09Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [May 8, 2010, 8:27am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/1 "2010-05-08T08:27:09Z")

</div>

Im trying to make a new module to aid in using system.nav.openWindowInstance. Im trying to prevent Bubba form opening 18 copies of the same window, with the same instance id. Here is what i have so far

[code]def checkInstance(window,instanceId):  
import system

```
instances = system.tag.getTagValue("[client]WindowInstances")
for row in range(instances.rowCount):
	if instances.getValueAt(row,"Window") == window and instances.getValueAt(row,"InstanceId") == instanceId:
		return row
return -1

```

def addInstance(window,instanceId):  
import system

```
instances = system.tag.getTagValue("[client]WindowInstances")
newRow = [window,instanceId]
system.tag.writeToTag("[client]WindowInstances",system.dataset.addRow(instances,newRow))

```

def delInstance(window,instanceId):  
import system,app.helper

```
row = helper.checkInstance(window,instanceId)
instances = system.tag.getTagValue("[client]WindowInstances")
system.tag.writeToTag("[client]WindowInstances",system.dataset.deleteRow(instances,row))

```

[/code]

Lets say it is called as follows

```auto
			if checkInstance("Transmitter",event.source.Tag) == -1:
				addInstance("Transmitter",event.source.Tag)
				import fpmi
				fpmi.nav.openWindowInstance('Transmitter', {'Tag' : event.source.Tag, 'config':event.source.config})				
				fpmi.nav.centerWindow('Transmitter')
			else:
				***code to bring instance to front***
```

In the else statement, how do I “get” the instance I want. I store a dataset of open instances in a client tag. Can we add an api reference to return some sort of ID when we use system.nav.openWindowInstance?

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [May 8, 2010, 9:33am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/2 "2010-05-08T09:33:22Z")

</div>

Made some changes, almost there, but too tired, going to bed, will post tomorrow.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [May 10, 2010, 8:25pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/3 "2010-05-10T20:25:53Z")

</div>

There is a change needed to some of the functions, so IA is adding this sometime soon… ill post back when its all said and done

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [May 19, 2010, 6:04pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/4 "2010-05-19T18:04:01Z")

</div>

The idea is that the reference to the window itself is the “id”. That is what is returned by openWindowInstance. Why isn’t this sufficient?

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [June 14, 2010, 6:33pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/5 "2010-06-14T18:33:39Z")

</div>

Ignore the previous code, we do’nt need to track instances, as we can find this at runtime. The following scripts find the window if opened, then either center it and move it to the front, or opens a new instance if need be.

Thanks for the idea Carl.

[code]def findInstance(window,instanceId):  
import system

```
for row in system.gui.getOpenedWindows():
	if row.name == window and row.getRootContainer().Tag == instanceId:
		return row
return None

```

def openInstance(window,instanceId):  
import system, app.instanceControl

```
windowInstance = app.instanceControl.findInstance(window,instanceId)
if windowInstance == None:
	windowInstance = system.nav.openWindowInstance(window,{"Tag" : instanceId})
system.nav.centerWindow(windowInstance)
windowInstance.toFront()

```

def closeInstance(window,instanceId):  
import system, app.instanceControl

```
windowInstance = app.instanceControl.findInstance(window,instanceId)
if windowInstance != None:
	system.nav.closeWindow(windowInstance)[/code]
```

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [June 14, 2010, 8:44pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/6 "2010-06-14T20:44:59Z")

</div>

Yeah, that looks just right. Thanks for taking my idea and running with it.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [July 19, 2010, 9:57pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/7 "2010-07-19T21:57:45Z")

</div>

Here is an update. Changed to allow more than one property to be passed.

[code]def findInstance(window,instanceId):  
import system

```
for row in system.gui.getOpenedWindows():
	if row.name == window and row.getRootContainer().Tag == instanceId:
		return row
return None

```

def openInstance(window,properties=None):  
import system, app.instanceControl

```
windowInstance = app.instanceControl.findInstance(window,properties['Tag'])
if windowInstance == None:
	windowInstance = system.nav.openWindowInstance(window,properties)
system.nav.centerWindow(windowInstance)
windowInstance.toFront()
windowInstance.setSelected(1)

```

def closeInstance(window,instanceId):  
import system, app.instanceControl

```
windowInstance = app.instanceControl.findInstance(window,instanceId)
if windowInstance != None:
	system.nav.closeWindow(windowInstance)[/code]

```

To open a window, your code would be as follows:

```auto
app.instanceControl.openInstance('WINDOW',{'PROP1':value1,'PROP2',value2})
```

To check to see if a certain instance is open. This will return the actual window that it finds:

```auto
app.instanceControl.findInstance('WINDOW',WINDOW_IDENTIFIER)(
```

R  
To close a window:

```auto
app.instanceControl.closeInstance('WINDOW',WINDOW_IDENTIFIER)
```

---

<div class="post-metadata">

**Author:** ![todd.be](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@todd.be](https://forum.inductiveautomation.com/u/todd.be)\
**Post date:** [November 1, 2010, 5:52pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/8 "2010-11-01T17:52:58Z")

</div>

Thanks Kyle but its still not quite right. The toFront() method is nicer than changing the layer and then changing it back but the window still does not have actual focus.

This is perhaps a minor detail but the original window still has focus even if the new window is in front. Keyboard actions (like tab) would still affect the original window and the Windows menu at the top will not actually swap back to the original window when selected as it still has focus. Using the mouse on the new window will force focus to be acquired on the new window.

---

<div class="post-metadata">

**Author:** ![ISDProj](https://avatars.discourse-cdn.com/v4/letter/i/58956e/32.png) [@ISDProj](https://forum.inductiveautomation.com/u/ISDProj)\
**Post date:** [November 1, 2010, 9:17pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/9 "2010-11-01T21:17:14Z")

</div>

This is what we do to give the front window focus (and make the whole app appear/disappear):

[code]def Iconify(Visible, WindowName=“WindowOfChoice”, KeepOnTop=0):  
#PJR 20100313  
#This Script forces the Ignition App to appear/dissapear.  
#It works for both windowed & full screen launch modes  
from java.awt import Window  
from javax.swing import SwingUtilities  
from java.awt import Frame  
import system  
allWindows = system.gui.getOpenedWindows()  
if len(allWindows)==0:  
#No Windows open? open one first  
system.nav.openWindow(WindowName)  
allWindows = system.gui.getOpenedWindows()

```
topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])
state = topWindow.getExtendedState()
if Visible:
	state &= ~Frame.ICONIFIED
	topWindow.setExtendedState(state)
	topWindow.setAlwaysOnTop(1)
	topWindow.toFront()
	if KeepOnTop==0:
		topWindow.setAlwaysOnTop(0)
else:
	state |= Frame.ICONIFIED
	topWindow.setExtendedState(state)
	topWindow.setAlwaysOnTop(0)
	topWindow.toBack()

```

[/code]

It works for Us 😃

Perhaps a combination of both would give “parameter passing” capabilities to, we didn’t need that so not included.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [November 2, 2010, 4:28pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/10 "2010-11-02T16:28:21Z")

</div>

I have modified the scripts to request focus, we needed to add windowInstance.setSelected(1)

---

<div class="post-metadata">

**Author:** ![todd.be](https://avatars.discourse-cdn.com/v4/letter/t/6f9a4e/32.png) [@todd.be](https://forum.inductiveautomation.com/u/todd.be)\
**Post date:** [November 2, 2010, 9:07pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/11 "2010-11-02T21:07:41Z")

</div>

Thanks. The window.SetSelected(1) does the trick correctly for me.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [June 1, 2017, 4:01am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/13 "2017-06-01T04:01:37Z")

</div>

Here is something quick and dirty. Replace your line 6 with the following.: Let me know how it goes.

```auto
windows = system.gui.getOpenedWindows()
targetWindowPresent = False
for window in windows:
	if window.name == "01_ValvePopup" and window.rootContainer.TagPath == event.source.Valve_udt.Meta.TagPath:
		targetWindowPresent = True
		break
if not window and targetWindowPresent:
	window = system.nav.openWindowInstance('Popup/01_ValvePopup', {'Tagpath':'sometagpath'})

 #dowindowstuff
```

---

<div class="post-metadata">

**Author:** ![choy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/choy/32/4190_2.png) [@choy](https://forum.inductiveautomation.com/u/choy)\
**Post date:** [June 1, 2017, 9:17am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/14 "2017-06-01T09:17:07Z")

</div>

Thanks Kyle\_Chase,

################################################################  
It says that AttributeError: ‘str’ object has no attribute ‘name’  
################################################################

---

<div class="post-metadata">

**Author:** ![PerryAJ](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/perryaj/32/3281_2.png) [@PerryAJ](https://forum.inductiveautomation.com/u/PerryAJ)\
**Post date:** [June 1, 2017, 3:21pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/16 "2017-06-01T15:21:47Z")

</div>

> AttributeError: 'str' object has no attribute 'name'

Is probably happening because `system.gui.getOpenWindowNames()` returns a string tuple. Try `if window == '01_ValvePopup ...` on line 10 instead of `window.name`, as window is a string not an window object.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [June 1, 2017, 4:06pm UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/17 "2017-06-01T16:06:43Z")

</div>

getOpenedWindowNames() should be getOpenedWindows(). Script has been edited above.

---

<div class="post-metadata">

**Author:** ![choy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/choy/32/4190_2.png) [@choy](https://forum.inductiveautomation.com/u/choy)\
**Post date:** [June 2, 2017, 12:59am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/18 "2017-06-02T00:59:24Z")

</div>

Thanks Perry & Kyle,

NO error using this script, but wont show the popup window.

---

<div class="post-metadata">

**Author:** ![choy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/choy/32/4190_2.png) [@choy](https://forum.inductiveautomation.com/u/choy)\
**Post date:** [June 2, 2017, 1:02am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/19 "2017-06-02T01:02:56Z")

</div>

![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/baa0a31babdcc0d8f879b039ca9619df48ea94c9.png)

---

<div class="post-metadata">

**Author:** ![choy](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/choy/32/4190_2.png) [@choy](https://forum.inductiveautomation.com/u/choy)\
**Post date:** [June 2, 2017, 6:30am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/20 "2017-06-02T06:30:24Z")

</div>

I found out that the code works if the window is already open, if not it wont call the Popup.  
What I did is i create same instance using my Original Popup Code.

---

<div class="post-metadata">

**Author:** ![Kyle\_Chase](https://avatars.discourse-cdn.com/v4/letter/k/9de0a6/32.png) [@Kyle\_Chase](https://forum.inductiveautomation.com/u/Kyle_Chase)\
**Post date:** [June 2, 2017, 7:14am UTC](https://forum.inductiveautomation.com/t/nav-helper-system-nav-openwindowinstace/1825/21 "2017-06-02T07:14:10Z")

</div>

I just edited the script, try it now.
