# Image not responding + if statement query

**URL:** <https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587>\
**Category:** Ignition\
**Tags:** vision\
**Created:** [November 7, 2023, 11:50am UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587 "2023-11-07T11:50:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Why\_Me](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Why\_Me](https://forum.inductiveautomation.com/u/Why_Me)\
**Post date:** [November 7, 2023, 11:50am UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/1 "2023-11-07T11:50:32Z")

</div>

Can someone tell me why this code isnt causing the image to move? It just doesnt respond at all. Its scripted within propertyChange within the image itself.

I have custom properties set up:

origX - Int  
origY - Int  
trigger - Bool

all it should be doing is moving the image from its orginal position to those coordinates then back.

```auto
component = event.source.parent.getComponent('Image')
origX = component.x
origY = component.y
 
system.gui.transform(
    component,
    93, 466,
    duration=3000,
    callback=lambda: system.gui.transform(
        component,
        origX, origY,
        duration=3000,
        acceleration=system.gui.ACCL_FAST_TO_SLOW
    )
)

```

the if statement im not sure how to complete properly, I want to set the trigger property to 1 when the component reaches the x coordinate of 93 then set trigger back to 0 when it goes back to its original position. trigger is a property used to fire something else on the screen.

```auto

if component.x == 93:
	event.source.trigger = 1 
elif component.x == event.source.origX:
	event.source.trigger = 0

```

---

<div class="post-metadata">

**Author:** ![Why\_Me](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Why\_Me](https://forum.inductiveautomation.com/u/Why_Me)\
**Post date:** [November 7, 2023, 12:47pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/2 "2023-11-07T12:47:35Z")

</div>

i got it to run, but the image flickers back and forward constantly and never completes the cycle

---

<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:** [November 7, 2023, 1:01pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/3 "2023-11-07T13:01:04Z")

</div>

> [@Why\_Me](#):
>
> propertyChange within the image itself.

You need to filter on the property name, otherwise it will trigger on ANY property change.  
Something like

```python
if event.propertyName == 'the_property_you_want_to_monitor':
    do_the_thing

```

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 7, 2023, 1:07pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/4 "2023-11-07T13:07:02Z")

</div>

- The thing triggering the transform should be what you filter for.
- Set up a few functions you can wrap in an invokeLater

Here's a window for you to play with.  
[test\_Transform\_2023-11-07\_0755.zip](https://forum.inductiveautomation.com/uploads/short-url/6RqvcNk0LiMA1MwAzrOrWDfhEhc.zip) (4.4 KB)

Script on the button:

```python
def invoke():
	component = event.source.parent.getComponent('Image')

	def setState(stateIn):
		component.state = stateIn
		
	def setMoveSet(x, y, state1, state2):
		setState(state1)
		system.gui.transform(component, 
							 x, 
							 y, 
							 duration=1000,
							 acceleration=system.gui.ACCL_EASE,
							 callback = lambda state=state2 : setState(state)
							)		
		
	origX = component.x
	origY = component.y
	
	setState(1)	
	system.gui.transform(component, 
						 100, 
						 origY, 
						 duration=1000,
						 acceleration=system.gui.ACCL_EASE,
						 callback = lambda x=origX, y=origY: setMoveSet(x,
						                               y,
						                               2,
						                               0)
						)
						
system.util.invokeLater(invoke)

```

---

<div class="post-metadata">

**Author:** ![Why\_Me](https://avatars.discourse-cdn.com/v4/letter/w/b4bc9f/32.png) [@Why\_Me](https://forum.inductiveautomation.com/u/Why_Me)\
**Post date:** [November 7, 2023, 1:39pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/5 "2023-11-07T13:39:07Z")

</div>

Hi Jordan, that works beautifully!

why does this work and using transform doesnt? what is invokelater for?

Please correctly assume im an idiot if you manage to describe this and pitch at that level

---

<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:** [November 7, 2023, 1:43pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/6 "2023-11-07T13:43:03Z")

</div>

> [@Why\_Me](#):
>
> why does this work and using transform doesnt? what is invokelater for?

It also uses a transform. The difference is that this is triggered by a button, while you were using a property change script.  
The property change script will work, as long as you filter correctly on the property name. What was happening in your attempt is that since the script was triggered by ANY change on ANY property, it was constantly re-triggering and thus resetting positions, which caused the flicker you experienced.  
I think.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 7, 2023, 2:57pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/7 "2023-11-07T14:57:46Z")

</div>

Pascal is correct on why your script isn't quite working as expected. Using a filter is vital when using a propertyChange script.

invokeLater() is used to run your stuff in a background thread. Running it in the forground will run it in the GUI thread, so nothing in the GUI will update untill it's all over.

Also note that, instead of monitoring when I reached the end of a transform with an 'if' statement, I used a different function in the callback, and used _that_ function to set the state.

If you were to use this in the propertyChange script of the image I would add another custom property (runAnimation, for example) and use that as the filter.

```python
if event.propertyName == 'runAnimation' and event.newValue == True:
	def invoke():
		component = event.source.parent.getComponent('Image')
	
		def setState(stateIn):
			component.state = stateIn
		
		def reset():
			# Reset back to default values and turn off the runAnimation trigger.
			setState(0)
			component.runAnimation = False
			
			
		def setMoveSet(x, y, state1):
			setState(state1)
			system.gui.transform(component, 
								 x, 
								 y, 
								 duration=1000,
								 acceleration=system.gui.ACCL_EASE,
								 callback = lambda : reset()
								)		
			
		origX = component.x
		origY = component.y
		
		setState(1)	
		system.gui.transform(component, 
							 100, 
							 origY, 
							 duration=1000,
							 acceleration=system.gui.ACCL_EASE,
							 callback = lambda x=origX, y=origY: setMoveSet(x,
							                               y,
							                               2)
							)
	#event.source.runAnimation = False					
	system.util.invokeLater(invoke)

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 7, 2023, 3:54pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/8 "2023-11-07T15:54:21Z")

</div>

> [@JordanCClark](#):
>
> invokeLater() is used to run your stuff in a background thread.

No, it still runs in the foreground GUI thread.

Only invokeAsynchronous pushes a task to the background, but that isn't appropriate here--you are interacting with components, which is forbidden in the background.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 7, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/9 "2023-11-07T16:08:12Z")

</div>

I see this is being done in Vision, is there anyway to do it in Perspective also?

---

<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:** [November 7, 2023, 4:08pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/10 "2023-11-07T16:08:57Z")

</div>

Animation in the web environment works completely differently.

To do something _like_ what's in this post, you "just":

1. Move the position of an element from somewhere to somewhere else.
2. Have a CSS animation connected to the element. It will automatically smoothly move the element.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [November 7, 2023, 4:11pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/11 "2023-11-07T16:11:05Z")

</div>

LOL, "just".

Interesting. I will do it and report back.

---

<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:** [November 7, 2023, 4:11pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/12 "2023-11-07T16:11:46Z")

</div>

Consider starting from the View Canvas component, which does some of the legwork for you:  
[https://docs.inductiveautomation.com/display/DOC81/Perspective+-+View+Canvas](https://docs.inductiveautomation.com/display/DOC81/Perspective+-+View+Canvas)

---

<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:** [November 7, 2023, 5:11pm UTC](https://forum.inductiveautomation.com/t/image-not-responding-if-statement-query/81587/13 "2023-11-07T17:11:15Z")

</div>

Assuming a coordinate container, add a `transition` to its styles. Then when you change a css property (such as x and y), it will transition smoothly.  
Google "css transition" for the syntax and options.  
There are other ways, but I believe this is the easiest and simplest one for a basic animation like this one.
