Page 1 of 1

Math function in InputText

Posted: November 18th, 2017, 8:51 pm
by 55thSwiss
Hi all,

I've been modifying the Google/Bing InputText example and I've gotten hung up on one spot. I'm setting some variables using the !SetVariable bang and then would like to add the two together to display in the Output meter (I'm going to be using a more complex formula later, just adding the two to get it to work). I cannot seem to get the calculation to go through though.

Any help would be much appreciated. Even a work around although it doesn't seem it should be this difficult :headbang:

Thank you!

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
;CurrentInput="Pitch Diameter"

[MeterHelixHeading]
Meter=String
X=52
Y=0r
W=170
H=18
FontSize=12
FontColor=255, 139, 0
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Bold
AntiAlias=1
Text=Helix Angle Calculator


[MeterInputLabel]
Meter=String
X=52
Y=20r
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Italic
AntiAlias=1
Text=Enter values here...
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1-4"]

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=57
Y=24
W=171
H=20
FontSize=10
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
;DefaultValue=#CurrentInput#
OnDismissAction=[!SetVariable CurrentInput ""][Play "#@#Sounds\Dismiss.wav"]
Command1=[!SetVariable pitchDiameter "$UserInput$"] DefaultValue="Pitch Diameter?"
Command2=[!SetVariable threadLead "$UserInput$"] DefaultValue="Thread Lead?"
Command3=[!SetVariable helixAngle "(#pitchDiameter#+#threadLead#)"]        ; line I'm having trouble with
Command4=[!SetOption MeterOutput Text "#*helixAngle*#"][!UpdateMeter *][!Redraw]

[MeterOutput]
Meter=String
X=52
Y=0R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,5,30,5
StringStyle=Italic
AntiAlias=1
DynamicVariables=1


Re: Math function in InputText

Posted: November 19th, 2017, 3:48 am
by eclectic-tech
Generally you want to have separate input meters for each user input request, so I added a meter for thread lead. That meant changes in the !CommandMeasures "executes" to obtain the input for each parameter when each meter is clicked.
I modified the commands so the meters update after inputs, and removed the last 2 commands. Those calculations were moved a new helix calculation measure. Now you can bound that helix measure to the output meter section. I also modified the X&Y positions for the user inputs so the values show after the current meter text.

Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
;CurrentInput="Pitch Diameter"
pitchDiameter=0
threadLead=0

[MeasureHelix]
Measure=Calc
Formula=#pitchDiameter#+#threadLead#
DynamicVariables=1

[MeterHelixHeading]
Meter=String
X=52
Y=0r
W=170
H=18
FontSize=12
FontColor=255, 139, 0
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Bold
AntiAlias=1
Text=Helix Angle Calculator

[MeterInputLabelPitch]
Meter=String
X=52
Y=R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Italic
AntiAlias=1
Text=Pitch diameter: #pitchDiameter#
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1"]
DynamicVariables=1

[MeterInputLabelLead]
Meter=String
X=52
Y=R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Italic
AntiAlias=1
Text=Thread lead: #threadLead#
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 2"]
DynamicVariables=1

[MeterOutput]
Meter=String
MeasureName=MeasureHelix
X=52
Y=0R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,5,30,5
StringStyle=Italic
AntiAlias=1
NumOfDecimals=2
Text="Helix Angle: %1"
DynamicVariables=1

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=150
Y=32
W=95
H=20
FontSize=10
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
;DefaultValue=#CurrentInput#
OnDismissAction=[!SetVariable pitchDiameter 0][!SetVariable threadLead 0][Play "#@#Sounds\Dismiss.wav"][!UpdateMeter *][!Redraw]
Command1=[!SetVariable pitchDiameter "$UserInput$"] DefaultValue="Pitch Diameter?" [!UpdateMeter *][!Redraw]
Command2=[!SetVariable threadLead "$UserInput$"] DefaultValue="Thread Lead?" X=136 Y=60 [!UpdateMeasure MeasureHelix][!UpdateMeter *][!Redraw]
; Command3=[! helixAngle "(#pitchDiameter#+#threadLead#)"]
; ; line I'm having trouble with
; Command4=[!SetOption MeterOutput Text "#*helixAngle*#"][!UpdateMeter *][!Redraw]

Let us know if you have any questions about the changes or advice.

Re: Math function in InputText

Posted: November 19th, 2017, 1:32 pm
by 55thSwiss
That was extremely helpful. I guess it makes sense to have two separate input meters. I didn't know how to update the code with !UpdateMeasure or to use the %1 to obtain a previous measures value.

I do have a couple questions though, in a bang does the * in !UpdateMeter * cause all meters to update?

And lastly the real formula I'm using contains the atan function. It is calculating fine if my inputs are > 1. I need it to function with inputs < 1 but > 0. Is this possible? The NumOfDecimals is only an output thing correct?

Edit: should have posted formula sorry

Formula=atan(#threadLead#/((#pitchDiameter#/2)*PI))

Re: Math function in InputText

Posted: November 19th, 2017, 2:03 pm
by balala
55thSwiss wrote:in a bang does the * in !UpdateMeter * cause all meters to update?
Exactly.
55thSwiss wrote:And lastly the real formula I'm using contains the atan function. It is calculating fine if my inputs are > 1. I need it to function with inputs < 1 but > 0. Is this possible?
The Atan function is defined on the whole domain of the real numbers, from -infinite to +infinite. So no matter what value are you entering, the function should give a result. If it doesn't, plase post the whole code, containing the incriminated formula.
55thSwiss wrote:The NumOfDecimals is only an output thing correct?
NumOfDecimals can be used on String meters (not measures, but meters).

Re: Math function in InputText

Posted: November 19th, 2017, 2:12 pm
by 55thSwiss
Thank you for the clarification balala. I'm obviously doing something wrong concerning the formula if it works as you stated. It gives output values for anything greater than 1 but stays 0 if my inputs are < 1. The values I'll generally be using as input are more like .02 thru .25 just for reference. How would you go about using the deg(x) to convert the formula's end value before posting it thru MeterOutput? If I can't that's fine, my main concern is not being able to use decimals.


Code: Select all

[Rainmeter]
Update=1000
AccurateText=1
DynamicWindowSize=1

[Variables]
pitchDiameter=0
threadLead=0

[MeasureHelix]
Measure=Calc
Formula=atan(#threadLead#/((#pitchDiameter#/2)*PI))
DynamicVariables=1

[MeterHelixHeading]
Meter=String
X=52
Y=0r
W=170
H=18
FontSize=12
FontColor=255, 139, 0
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Bold
AntiAlias=1
Text=Helix Angle Calculator

[MeterInputLabelPitch]
Meter=String
X=52
Y=R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Italic
AntiAlias=1
NumOfDecimals=4
Text=Pitch diameter: #pitchDiameter#
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 1"]
DynamicVariables=1

[MeterInputLabelLead]
Meter=String
X=52
Y=R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,6,30,4
StringStyle=Italic
AntiAlias=1
NumOfDecimals=4
Text=Thread lead: #threadLead#
LeftMouseUpAction=[!CommandMeasure MeasureInput "ExecuteBatch 2"]
DynamicVariables=1

[MeterOutput]
Meter=String
MeasureName=MeasureHelix
X=52
Y=0R
W=170
H=18
FontSize=10
FontColor=170,170,170,255
SolidColor=27,27,27,255
Padding=5,5,30,5
StringStyle=Italic
AntiAlias=1
NumOfDecimals=3
Text="Helix Angle: %1"
DynamicVariables=1

[MeasureInput]
Measure=Plugin
Plugin=InputText
X=150
Y=32
W=95
H=20
FontSize=10
FontColor=255,255,255,255
SolidColor=47,47,47,255
AntiAlias=1
FocusDismiss=1
OnDismissAction=[!SetVariable pitchDiameter 0][!SetVariable threadLead 0][Play "#@#Sounds\Dismiss.wav"][!UpdateMeter *][!Redraw]
Command1=[!SetVariable pitchDiameter "$UserInput$"] DefaultValue="Pitch Diameter?" [!UpdateMeter *][!Redraw]
Command2=[!SetVariable threadLead "$UserInput$"] DefaultValue="Thread Lead?" X=136 Y=60 [!UpdateMeasure MeasureHelix][!UpdateMeter *][!Redraw]



Re: Math function in InputText

Posted: November 19th, 2017, 2:24 pm
by jsmorley
Do keep in mind that .02 is invalid in Rainmeter, it must be expressed as 0.02 in a formula.
1.png

Re: Math function in InputText

Posted: November 19th, 2017, 2:59 pm
by balala
jsmorley wrote:Do keep in mind that .02 is invalid in Rainmeter, it must be expressed as 0.02 in a formula.
Be careful about this detail: enter 0.02 and 0.25 instead of .02 and .25.

But there is one more issue in the posted code. On refresh it gives in the log a Calc: Division by 0 error message, related on the [MeasureHelix] measure. This because both variables (pitchDiameter and threadLead) are defined as 0 in the [Variables] section. pitchDiameter being in the denominator, gives the error message (the denominator of a fraction can't be zero).
The easiest way to avoid the error message would be to use any non zero value for this variable. But in this case the problem still occurs if you enter 0 from the keyboard.
In my opinion, the best solution is to add an extremely small, but not zero value to the #pitchDiameter# variable: Formula=atan(#threadLead#/(((#pitchDiameter#[color=#FF0000]+0.000001[/color])/2)*PI)). The added value doesn't change the result, but avoids the error.

Re: Math function in InputText

Posted: November 19th, 2017, 3:02 pm
by 55thSwiss
Wow, that was it! What a dummy :? Thank you so much for the help. And as far as my question about converting to degrees I think I can just add it into the formula like: Formula=deg(atan(#threadLead#/((#pitchDiameter#/2)*PI)))

Also, balala thank you for the input on the divisor. I'll add that bit into the formula and make a note why it's there. I also didn't know there was a debug mode, so thank you for the heads up on that. I'll fool around with it and it should help me not ask quite so many noob questions next time :D

I've got to say props to this community for very fast and effective troubleshooting. Pretty impressive compared to most communities.

Thank you for the help everyone.

Re: Math function in InputText

Posted: November 19th, 2017, 3:18 pm
by balala
55thSwiss wrote:And as far as my question about converting to degrees I think I can just add it into the formula like: Formula=deg(atan(#threadLead#/((#pitchDiameter#/2)*PI)))
Yep, you can, but this formula still doesn't avoid the error message.
55thSwiss wrote:Also, balala thank you for the input on the divisor.
Math is our friend.
55thSwiss wrote:I also didn't know there was a debug mode, so thank you for the heads up on that. I'll fool around with it and should help me not ask such noob questions next time :D
https://docs.rainmeter.net/manual/user-interface/about/#LogTab