Advance Button

I have a window named Ammonia Air Unit.

It displays the information and controls the cooler units in the factory. There are 18 air units.

The window is populated with information from a table that I index off of a column named EA.

I created a dynamic property called Air_Unit that allows me to get the data for an object by making the the where clause “Where EA = Air_Unit”.

I created another dynamic property called “Air_Unit_Quantity”. I set this to the number of air units I have. As I will be adding units as they expand, I should only have to change this value and I will be able to scroll sequencially through the units. That’s the theory anyway. And when I write that down the words stay on the page. It sounds good when you say it real fast, too.

I placed a button in the root container and tied the following code into the actionperformed event of the button.

value = ‘{$.Air_Unit}’
IF value == ‘{$.Air_Unit_Quantity}’:
value = 1
ELSE: value = ‘{$.Air_Unit} + 1’
event.source.parent.setPropertyValue(‘Air_Unit’, value)

I get the following error:

Unable to register action actionPerformed
Parse Error:
Traceback (innermost last):
(no code object) at line 0
SyntaxError:(“invalid syntax’,(”,2,4, “IF value == ‘{$.Air_Unit_Quantity}’:”))

Hey, you’re very close! However, there’s 2 main problems:

  1. The cause of this error: commands are case sensitive, and your “IF” needs to be lower case.

  2. Operationally: Jython scripts don’t just “plug-in” value references like expressions… so though you were keen to pick up that syntax (which I think is used internally by those handy helpers), that’s not going to work out like you want…

The solution is to use getPropertyValue.

Try out something like: (oh, btw, if you use the CODE button here on the forum it’ll leave your formatting intact)

value = event.source.parent.getPropertyValue('Air_Unit')
qty = event.source.parent.getPropertyValue('Air_Unit_Quantity')
if value==qty:
	value=1
else:
	value=qty+1
event.source.parent.setPropertyValue('Air_Unit', value)

Hope that helps… didn’t have much time to work on this, but I think that should do it!

Keep on truckin,

That helped.

The only thing is the line value=qty + 1 would give me a value of 19 every time. So I changed that to value=value + 1.

When I ran it though, the air_unit property was getting set to 1 and wouldn’t move off 1.

I then realized the value of “Air_Unit_Quantity” was at zero.

I went to the global even scripts and under startup put the line:

event.source.parent.setPropertyValue(‘Air_Unit_Quantity’, ‘18’)

If I am understanding this correct, I should only have to change the ‘18’ as I add units to the system.

To decrement I added a button and put the following code into the actionPerformed event:

value = event.source.parent.getPropertyValue('Air_Unit') lowend = '1' if value==lowend: value=event.source.parent.getPropertyValue('Air_Unit_Quantity') else: value=value-1 event.source.parent.setPropertyValue('Air_Unit', value)

That didn’t work. The number would go negative rather than wrap back around to my Air_Unit_Quantity value.

So I changed lowend=‘1’ to lowend=1 and it worked.

So I am guessing what is going on here that something inside the ’ ’ is the value of a property and if it isn’t in ’ ’ then it is either a value or a variable and it will look at the value of the variable.

I further refined this by removing lowend=1

and changed if value==lowend to if value==1

Hello,

First off, as you seem to be doing a bit of scripting, you will really benefit from running through some of those tutorials on Python. The scripting language in FactoryPMI is Jython, which is Python running on Java, so syntax-wise, it is exactly the same as Python. This will help clear up things like:

No, its much simpler than that! Things inside single quotes are strings. So, the number 1 is not equal to the string ‘1’. Thats what was going on there. Here is a quick rundown:
[ul]
[li]123 numeric value[/li]
[li]‘abc’ string value[/li]
[li]myvar value of the variable named myvar[/li]
[li]object.doSomething() function call of a function named “doSomething” on variable “object”[/li]
[li][1, 32, ‘abc’] list of values[/li][/ul]

[quote=“jet400ex”]I went to the global even scripts and under startup put the line:

event.source.parent.setPropertyValue(‘Air_Unit_Quantity’, ‘18’)[/quote]
Ack, remove that, it won’t do anything! This doesn’t make sense for a variety of reasons. #1 is that the global startup script runs before any windows are open. #2 is that “event.source…” won’t work in the global startup script - global scripts don’t get event objects, only action scripts that occur within windows.

Ok, I just wanted to clear those things up. Sounds like you got it working though - thats great!

Let us know when you have more questions,

It’s gone. I told you I know enough to be dangerous. :open_mouth:

Whats gone?

[quote]Ack, remove that, it won’t do anything! This doesn’t make sense for a variety of reasons. #1 is that the global startup script runs before any windows are open. #2 is that “event.source…” won’t work in the global startup script - global scripts don’t get event objects, only action scripts that occur within windows.
[/quote]

That.

Thank you for the clarification via phone. I am sufficiently dangerous now.

Haha, well, when you get into trouble, let us know :wink:

Have fun,