It is currently April 28th, 2024, 3:34 am

How to use a meter attribute value in a formula?

Get help with creating, editing & fixing problems with skins
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

How to use a meter attribute value in a formula?

Post by MattNY177 »

Say I have a skin with 100 different meters (e.g. box1, box2, ... , box100) but only want some of them to be visible. Rather than toggling the "hidden" option for each of them individually, I'd like to do this formulaically.

So for example if I set a "BoxCount" variable equal to 40, only the first 40 boxes should be visible. If I want to show another 40 I could just change it to BoxCount = 80.

My initial thought was to set some arbitrary attribute (like UpdateDivider) counting up from 1 to 100 for each meter, then use a calc measure to test if that value is lower or higher than the BoxCount variable, which would return 1 or 0 for that meter's "hidden" attribute.

Is there any way to use something like a meter's UpdateDivider value in the formula of a calc measure? Or is there some other way to achieve the same result via different method?
User avatar
Active Colors
Moderator
Posts: 1255
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: How to use a meter attribute value in a formula?

Post by Active Colors »

MattNY177 wrote: September 1st, 2021, 5:58 am So for example if I set a "BoxCount" variable equal to 40, only the first 40 boxes should be visible. If I want to show another 40 I could just change it to BoxCount = 80.

My initial thought was to set some arbitrary attribute (like UpdateDivider) counting up from 1 to 100 for each meter, then use a calc measure to test if that value is lower or higher than the BoxCount variable, which would return 1 or 0 for that meter's "hidden" attribute.
1) No need for arbitrary attributes. That would cause more frictions in the code. Since you have your meters numbered (indexed) — all you need is to plug index.lua in the code (courtesy of Yincognito). I attached it to this post.

2) No need for extra measures. That would increase the number of sections twice (if you have 100 meters to display then you need 100 measures to test them) which is another friction. You can use formulas as any value in Rainmeter, and as for your case you can put if condition which will "test" the value right inside the Hidden option.

Here is the code. Make sure you run the latest at the moment Rainmeter 4.5.0.

Code: Select all

[Rainmeter]
Update=-1
DynamicWindowSize=1
AccurateText=1
BackgroundMode=2
SolidColor=0,0,0,255

[Variables]
BoxCount=5
; Necessary variable to make index.lua work
INDEX=[&INDEX:SectionIndex('[#*CURRENTSECTION*]','last','(<x>)')]

[INDEX]
Measure=Script
ScriptFile=#@#Index.lua
UpdateDivider=-1

[StyleText]
X=0
Y=R
FontFace=Arial
FontSize=10
FontColor=255,255,255,255
Padding=10,0,10,10
AntiAlias=1
Text=[#CURRENTSECTION]
; Tests the value. If the index is less or equals the BoxCount then show the meter, otherwise (if more) then hide the meter. 
; e.g. if Box3 <= BoxCount=5 then Hidden=0
Hidden=([#INDEX] <= [#BoxCount] ? 0 : 1)
UpdateDivider=-1
DynamicVariables=1

[Box1]
Meter=String
MeterStyle=StyleText
Y=10

[Box2]
Meter=String
MeterStyle=StyleText

[Box3]
Meter=String
MeterStyle=StyleText

[Box4]
Meter=String
MeterStyle=StyleText

[Box5]
Meter=String
MeterStyle=StyleText

[Box6]
Meter=String
MeterStyle=StyleText

[Box7]
Meter=String
MeterStyle=StyleText

[Box8]
Meter=String
MeterStyle=StyleText

[Box9]
Meter=String
MeterStyle=StyleText

[Box10]
Meter=String
MeterStyle=StyleText
You do not have the required permissions to view the files attached to this post.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2613
Joined: March 23rd, 2015, 5:26 pm

Re: How to use a meter attribute value in a formula?

Post by SilverAzide »

MattNY177 wrote: September 1st, 2021, 5:58 am Is there any way to use something like a meter's UpdateDivider value in the formula of a calc measure? Or is there some other way to achieve the same result via different method?
ActiveColors method is the really fancy way to do it. If you want the old-fashioned low-tech way, in every one of your meters add the expression:

Code: Select all

[Box1]
...
Hidden=(#BoxCount# < 1)

[Box2]
...
Hidden=(#BoxCount# < 2)

;...etc.
The downside to this is you need to edit all 100 meters with different formulas. AC's way is much more auto-magical. :)
Gadgets Wiki GitHub More Gadgets...
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: How to use a meter attribute value in a formula?

Post by sl23 »

I prefer the Rainmeter way! Mainly cos I can just about find my way about the code :lol: Lua is a complete mystery to me! :o
I like what you did there SilverAzide, quite simple really, but interesting.
- MuLab -
User avatar
balala
Rainmeter Sage
Posts: 16182
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: How to use a meter attribute value in a formula?

Post by balala »

sl23 wrote: September 1st, 2021, 5:01 pm I prefer the Rainmeter way! Mainly cos I can just about find my way about the code :lol: Lua is a complete mystery to me! :o
Me personally am not really convinced it does worth to involve lua in this. Yes, it's true the code is simpler in the way that no need to add one by one the Hidden options, but those options can be easily added and modified.
User avatar
sl23
Posts: 1140
Joined: February 17th, 2011, 7:45 pm
Location: a Galaxy S7 far far away

Re: How to use a meter attribute value in a formula?

Post by sl23 »

I would agree, seeing as the solution is as simple as one short line of code :D
- MuLab -
MattNY177
Posts: 28
Joined: December 3rd, 2018, 1:15 am

Re: How to use a meter attribute value in a formula?

Post by MattNY177 »

Thanks for the replies, both solutions seem like they will work for this specific situation. I appreciate the help.

I was still just curious about the other part of that question, though... if it's possible to reference another meter's attributes as a variable in a formula? I know you can do it with basic ones like H/W/X/Y such as [MeterName:X] but what about other things like SolidColor, FontColor (string), ImageAlpha (image), etc? Or is the only way to achieve this to store those values in their own variables to be referenced from both the meter and formula?
The downside to this is you need to edit all 100 meters with different formulas. AC's way is much more auto-magical.
SilverAzide's answer got me thinking of another question... is it possible to reference part of a meter's name using the #CURRENTMEASURE# variable? In the example above where the names range from Box001 to Box100, is there some way to reference the last 3 characters like this (borrowing from another language):

Hidden=(#BoxCount# < CINT(RIGHT(#CURRENTMEASURE#,3)))
User avatar
death.crafter
Rainmeter Sage
Posts: 1399
Joined: April 24th, 2021, 8:13 pm

Re: How to use a meter attribute value in a formula?

Post by death.crafter »

MattNY177 wrote: September 2nd, 2021, 4:41 am Thanks for the replies, both solutions seem like they will work for this specific situation. I appreciate the help.

I was still just curious about the other part of that question, though... if it's possible to reference another meter's attributes as a variable in a formula? I know you can do it with basic ones like H/W/X/Y such as [MeterName:X] but what about other things like SolidColor, FontColor (string), ImageAlpha (image), etc? Or is the only way to achieve this to store those values in their own variables to be referenced from both the meter and formula?



SilverAzide's answer got me thinking of another question... is it possible to reference part of a meter's name using the #CURRENTMEASURE# variable? In the example above where the names range from Box001 to Box100, is there some way to reference the last 3 characters like this (borrowing from another language):

Hidden=(#BoxCount# < CINT(RIGHT(#CURRENTMEASURE#,3)))
No. Tho as Active Colors suggested, you can use Lua to extract them from the meter names.

But keep in mind that there is no foolproof way of doing this. When using Active Color's method, you have to setup workarounds for FontWeight and similar settings where value can not be 0. Other than that it's a good and probably the only way of doing it.
from the Realm of Death
User avatar
Active Colors
Moderator
Posts: 1255
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: How to use a meter attribute value in a formula?

Post by Active Colors »

MattNY177 wrote: September 2nd, 2021, 4:41 am I was still just curious about the other part of that question, though... if it's possible to reference another meter's attributes as a variable in a formula? I know you can do it with basic ones like H/W/X/Y such as [MeterName:X] but what about other things like SolidColor, FontColor (string), ImageAlpha (image), etc? Or is the only way to achieve this to store those values in their own variables to be referenced from both the meter and formula?
There is no straightforward way of doing this. The workaround depends on your "skin architecture". Without knowing how you build your skin it is difficult to recommend something. If it was me I would make use of !WriteKeyValue and !SetOption bangs, would Group meters and measures, and heavily utilize MeterStyles along with Variables, In-built Variables, and the [#INDEX] trick.
MattNY177 wrote: September 2nd, 2021, 4:41 am SilverAzide's answer got me thinking of another question... is it possible to reference part of a meter's name using the #CURRENTMEASURE# variable? In the example above where the names range from Box001 to Box100, is there some way to reference the last 3 characters like this (borrowing from another language):

Hidden=(#BoxCount# < CINT(RIGHT(#CURRENTMEASURE#,3)))
At the moment the lua script works with Box5 format and returns 5 by using [#INDEX], however it ignores the leading zeros so it is incompatible with Box005 format. I think if Yincognito reads this thread and can modify his lua script for your then it would be possible to use it in your case.
User avatar
Active Colors
Moderator
Posts: 1255
Joined: February 16th, 2012, 3:32 am
Location: Berlin, Germany

Re: How to use a meter attribute value in a formula?

Post by Active Colors »

sl23 wrote: September 1st, 2021, 5:01 pm I prefer the Rainmeter way! Mainly cos I can just about find my way about the code :lol: Lua is a complete mystery to me! :o
I like what you did there SilverAzide, quite simple really, but interesting.
sl23, to use the script you don't need to dive into lua and you don't need to have any knowledge about lua. All you need is to plug the script somewhere in your skin with the "Rainmeter way":

Code: Select all

[INDEX]
Measure=Script
ScriptFile=#@#Index.lua
UpdateDivider=-1
and set the variable in your skin:

Code: Select all

[Variables]
INDEX=[&INDEX:SectionIndex('[#*CURRENTSECTION*]','last','(<x>)')]
At the end you get a new variable that you can use to extract current section's index anywhere by using [#INDEX].