Plugin Formulas (aka "field expressions")

Posted on
Sat Sep 05, 2015 5:05 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Plugin Formulas (aka "field expressions")

Hi Korey - here's one way to do it (presumes that the value you're looking for will always follow 'P1VM'). You'll need to figure out how to grab the string in the first place...

Code: Select all
x = 'P1VM-34.5'
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(123456, vol)

or condensed down:
Code: Select all
x = 'P1VM-34.5'
indigo.variable.updateValue(123456, x[x.find('P1VM') + 4:])

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Sep 05, 2015 2:32 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Plugin Formulas (aka "field expressions")

DaveL17 wrote:
Hi Korey - here's one way to do it (presumes that the value you're looking for will always follow 'P1VM'). You'll need to figure out how to grab the string in the first place...

Code: Select all
x = 'P1VM-34.5'
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(123456, vol)

or condensed down:
Code: Select all
x = 'P1VM-34.5'
indigo.variable.updateValue(123456, x[x.find('P1VM') + 4:])

Dave



Thanks, Dave,

That will work if x= P1VM-34.5 , but the value changes, i.e.: P1VM-19.0, it will no longer write to the variable.

How do I get it to just grab P1VM and make that x?

if I can just get x to be the prefix I can have feedback from the unit for every parameter just by changing the script to suit the commands.

I really need to learn python.. :?

--
Korey

Posted on
Sat Sep 05, 2015 5:41 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Plugin Formulas (aka "field expressions")

Hmmm. Not sure what you're seeing Korey, because it should work for any value.
Code: Select all
>>> x = 'P1VM-34.5'
>>> print x[x.find('P1VM') + 4:]
-34.5

>>> x = 'P1VM-19.0'
>>> print x[x.find('P1VM') + 4:]
-19.0

>>> x = 'P1VM-123456.789'
>>> print x[x.find('P1VM') + 4:]
-123456.789

>>> x = "P1VM Why, oh why didn't I take the blue pill?"
>>> print x[x.find('P1VM') + 4:]
 Why, oh why didn't I take the blue pill?
>>>

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Sep 05, 2015 6:33 pm
FlyingDiver offline
User avatar
Posts: 7189
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Plugin Formulas (aka "field expressions")

Korey - YOU need to set the value of X from somewhere else. It's not hardcoded in the script. It's only there so the script will do something for testing purposes.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Sep 05, 2015 6:51 pm
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Plugin Formulas (aka "field expressions")

Joe's right (sorry if that wasn't clear Korey!) The value of 'x' will come from another place--the plugin, a variable value, etc. Korey, contact me offline if you want me to walk you through step by step. Happy to do that. :D

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sat Sep 05, 2015 9:52 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Plugin Formulas (aka "field expressions")

Thanks Fellas!


I thought I could do this all with one trigger, but realized I needed to have a seperate trigger that watches the variable that Perry's plugin writes to, then runs this code:

Code: Select all
x = indigo.variables[1959029577].value # Get the value from the variable.
start = x.find('P1VM') + 4
vol = x[start:]
indigo.variable.updateValue(63670514, vol)


Works like a charm!

Now i have about 50 - 100 new actions and triggers to make!! :roll:
Attachments
Screen Shot 2015-09-05 at 8.51.56 PM.PNG
Screen Shot 2015-09-05 at 8.51.56 PM.PNG (15.15 KiB) Viewed 12989 times

--
Korey

Posted on
Sun Sep 06, 2015 4:42 am
DaveL17 offline
User avatar
Posts: 6741
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Plugin Formulas (aka "field expressions")

That's the ticket.

Korey, why don't you contact me offline and we can talk about what you're trying to accomplish. Hopefully, we can keep you from having to write 100 triggers!

Dave

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Sun Sep 06, 2015 10:10 pm
Perry The Cynic offline
Posts: 836
Joined: Apr 07, 2008

Re: Plugin Formulas (aka "field expressions")

Korey wrote:
The trigger will now fire, just unsure how to pass the -34.5 to a variable, not the whole P1VM-34.5 as it is currently doing :?

I assume there is a simple python script I could run in the trigger to remove the prefix?

Thanks Guys.


Each Recognized Input event has its own variable that you can specify. And by the magic of regular expressions, you can ask for only part of your input string to end up in the variable. Try something like
Code: Select all
P1VM(.*)
as the matched string, and the variable should end up set to -34.5 (as a string, since all Indigo variables are strings). The event will still "eat" the whole string; but it'll only store the part between parentheses.

Cheers
-- perry

Posted on
Sun Sep 06, 2015 11:40 pm
Korey offline
User avatar
Posts: 811
Joined: Jun 04, 2008
Location: Henderson, NV

Re: Plugin Formulas (aka "field expressions")

Perry The Cynic wrote:

Each Recognized Input event has its own variable that you can specify. And by the magic of regular expressions, you can ask for only part of your input string to end up in the variable. Try something like
Code: Select all
P1VM(.*)
as the matched string, and the variable should end up set to -34.5 (as a string, since all Indigo variables are strings). The event will still "eat" the whole string; but it'll only store the part between parentheses.

Cheers
-- perry


Thank you Perry!! :D :D :D

You just saved me from having to create around 200 new triggers to parse the info!

Seems my preamp will return the value of 109 different settings (3 zones) :shock:

Thank you once again for your wonderful plugins!

--
Korey

Who is online

Users browsing this forum: No registered users and 4 guests