MattNY177 wrote: ↑March 27th, 2019, 4:16 pm
I'm trying to come up with the most efficient way to form Meter/Measure combinations, so that string meters can easily reference corresponding measures on a large scale WITHOUT having to type each individual meter's MeasureName option. Where this can get tricky is when you have hundreds of meters, each meter having multiple corresponding measures that can be toggled using !SetOption or !WriteKeyValue to update the MeasureName.
My question is, what is the best practice for setting up these types of relationships? Should I approach every skin as if the Meter name is always the starting point, and every measure name is derived from that by adding a prefix/postfix to the #CURRENTSECTION# variable?
I went down the road you have, and the best way to handle this is stop creating hundreds of measures/meters, and just
reuse a single one (or a couple of them). Now, of course, I don't know the specifics in your case, but generally, if you have repetitive things measured/handled, then you should identify the things that are similar to all of them, create one or more base measure/meters containing the similarities, and then at runtime just adapt that/those measure/meters by tweaking the relevant index/bangs/variables that are subject to change.
Of course, sometimes such tricks are just not possible, as you'd want to get all things in one big measurement/parse because maybe you need all the values to calculate something else, but those are the exceptions. In all the other cases, you'd generally want to measure or display just a part of the whole at a given moment, and this is where the bangs changing the relevant indexes or variables come handy.
To illustrate this, take a look at this little excerpt from a skin I wrote:
Code: Select all
---Measures Rainmeter---
[MS_Rainmeter_Counter]
Group=DiskGroup
Measure=Calc
Formula=0
UpdateDivider=-1
RegExpSubstitute=1
Substitute="^0$":"Total","^1$":"C","^2$":"D","^3$":"E","^4$":"F","^5$":"G","^6$":"H","^7$":"I","^8$":"J","^9$":"K","^10$":"L","^11$":"M","^12$":"N","^13$":"O","^14$":"P","^15$":"Q","^16$":"R","^17$":"S","^18$":"T","^19$":"U","^20$":"V","^21$":"W","^22$":"X","^23$":"Y","^24$":"Z"
IfCondition=(MS_Rainmeter_Counter=0)
IfTrueAction=[!SetVariable DiskIDPrefix "_"][!SetVariable DiskID [MS_Rainmeter_Counter]][!SetVariable DiskIDPostfix ""]
IfFalseAction=[!SetVariable DiskIDPrefix ""][!SetVariable DiskID [MS_Rainmeter_Counter]][!SetVariable DiskIDPostfix ":"]
IfConditionMode=1
DynamicVariables=1
---Measures UsageMonitor---
[MS_UsageMonitor_DiskReadRate]
Group=DiskGroup
Measure=Plugin
Plugin=UsageMonitor
Category=LogicalDisk
Counter=Disk Read Bytes/sec
Name=#DiskIDPrefix##DiskID##DiskIDPostfix#
DynamicVariables=1
[MS_UsageMonitor_DiskReadRateValue]
Group=DiskGroup
Measure=Calc
Formula=MS_UsageMonitor_DiskReadRate
[MS_Rainmeter_SetMeters]
Group=DiskGroup
Measure=Calc
IfCondition=(MS_Rainmeter_Counter=0)
IfTrueAction=[!SetOption MT_Rainmeter_DiskReadUse Text "Disks Read"][!SetOption MT_Rainmeter_DiskReadUse ToolTipTitle "Disk #DiskID#: [MS_Rainmeter_#DiskID#Used]"][!SetOption MT_Rainmeter_DiskReadUse ToolTipText "Read [MS_Rainmeter_DiskReadRate]Bs"][!SetOption MT_Rainmeter_DiskReadUseValue MeasureName MS_UsageMonitor_DiskReadRateValue]
IfFalseAction=[!SetOption MT_Rainmeter_DiskReadUse Text "#DiskID# Read"][!SetOption MT_Rainmeter_DiskReadUse ToolTipTitle "Disk #DiskID#: [MS_Rainmeter_#DiskID#Used]"][!SetOption MT_Rainmeter_DiskReadUse ToolTipText "Read [MS_Rainmeter_DiskReadRate]Bs"][!SetOption MT_Rainmeter_DiskReadUseValue MeasureName MS_Rainmeter_DiskUsedValue]
IfConditionMode=1
DynamicVariables=1
---Meters---
[MT_Rainmeter_DiskReadUse]
Meter=STRING
MeterStyle=SCell | STitleColText
Text=
ToolTipTitle=
ToolTipText=
MouseScrollUpAction=[!SetOption MS_Rainmeter_Counter Formula ((MS_Rainmeter_Counter<=(0))?(24):(MS_Rainmeter_Counter-1))][!UpdateMeasureGroup "DiskGroup"][!UpdateMeter *][!Redraw]
MouseScrollDownAction=[!SetOption MS_Rainmeter_Counter Formula ((MS_Rainmeter_Counter>=(24))?(0):(MS_Rainmeter_Counter+1))][!UpdateMeasureGroup "DiskGroup"][!UpdateMeter *][!Redraw]
DynamicVariables=1
[MT_Rainmeter_DiskReadUseValue]
Meter=STRING
MeterStyle=SCell | SPrimaryColText
MeasureName=MS_UsageMonitor_DiskReadRateValue
AutoScale=1k
NumOfDecimals=1
Text="%1Bs"
DynamicVariables=1
This is adapted and cut off from the main skin, so it won't work, but what it does is
reuse a single
[MS_UsageMonitor_DiskReadRate] measure to measure the read rate of any of the 25 possible drives (i.e.
_Total, plus
C:,
D:, etc.), by using bangs to change variables like
#DiskIDPrefix#,
#DiskID# or
#DiskIDPostfix# on mouse scroll, variables that are also used to set the relevant
Name option of the
[MS_UsageMonitor_DiskReadRate] measure in order to measure the previous or the next drive read rates. Bottom line, instead of creating 25 measures and meters to handle each drive individually, I only work with 2 or 3 that will dynamically change their "index-like" option on demand, to measure the desired drive.
This way of approaching things made my skins span on just a couple of pages instead of tens and tens of pages, simplified the process and the readability, probably improved performance a little bit (since I'm only measuring one thing instead of 25 things) and overall made it easier for me to work on my skins. Sure, there will be some long bang rows in the process, but it's just a row, not lots of pages.
One other thing you could do to make things easier is to use the regex search/replace function in Notepad++, on the whole document or just the selected text (if you're not doing it already, that is). That helps a lot in changing lots of text according to the desired pattern, and it only takes a couple of seconds, if you build your regexes properly.