[SOLVED] Labels with data

Hello everyone,

I have this code and before the prints, I want to show the value of the two tags (tgCanal and tgSector) in case of the tag pathCanal has a value and then show it the label lblCanalTag and lblSectorTag but is not working.

pathCanal="[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio"
pathSector="[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio"

if  pathCanal:
	system.nav.centerWindow('User Management/mensajeAlarma')

	lblCanalTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag')
	lblSectorTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag')
	
	tgCanal = system.tag.readBlocking("[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio")
	tgSector = system.tag.readBlocking("[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio")
	
	lblCanalTag=tgCanal
	lblSectorTag=tgSector
	
	print lblCanalTag
	print lblSectorTag

Some thoughts:

  1. Where is this script running? There are lots of places scripts can be run, but only a few places that can interact with vision windows.
  2. Right now your if statement on line 4 will always be true because you’re not reading the value of a tag.
  3. It’s more efficient to do all your tag reads at once.
  4. system.tag.readBlocking returns a list of QualifiedValues.
    a. To read one path, you do this:
    system.tag.readBlocking(["[default]tagFolder/tagName")[0].value
  5. Every component has properties. You can’t just write a value to a component. You have to write to the appropriate property.

If your tagpaths aren’t dynamic, maybe something like this:

pathCanal="[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio"
pathSector="[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio"

canalValue,sectorValue = system.tag.readBlocking(
	[pathCanal,pathSector]
)
if  canalValue.value:
	system.nav.centerWindow('User Management/mensajeAlarma')

	lblCanalTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag')
	lblSectorTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag')
	
	# these will only be correct if this type of component has a value property.
	# lblCanalTag.text would also be something to try.
	lblCanalTag.value=canalValue.value
	lblSectorTag.value=sectorValue.value
	
	print canalValue.value
	print sectorValue.value

Edits: @pascal.fragnoud caught some mistakes.

This will never be correct, there are no objects called tgCanal and tgSector.
Why did you duplicate the tags paths ?

I wasn't paying good enough attention. Thanks.

Assuming that lblCanalTag and lblSectorTag are actually label components, you need to assign the the tag values to the text property.

tagPaths = ['[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio','[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio']
tgCanal, tgSector = [qval.value for qval in system.tag.readBlocking(tagPaths)]

if tgCanal:
    system.nav.centerWindow('User Management/mesajeAlarma')

    system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text = tgCanal
    system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text = tgSector

However, this kind of makes me wonder why you aren’t just binding the labels to the tags?

1 Like

Thanks both, it worked