It is currently May 3rd, 2024, 1:40 am
Can I extract the position of a skin to use as a variable?
-
- Posts: 14
- Joined: January 28th, 2018, 8:45 am
Can I extract the position of a skin to use as a variable?
I would like to get the position a skin to use it as a variable in another skin. So depending on the position, the value of the variable should automatically change and the skin should automatically be refreshed. Is it possible?
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Can I extract the position of a skin to use as a variable?
Although a skin doesn't know the position of another one, this is possible though, by setting some variables by the first skin, into the second one.Gangula wrote:I would like to get the position a skin to use it as a variable in another skin. So depending on the position, the value of the variable should automatically change and the skin should automatically be refreshed. Is it possible?
Add the following measure in to the skin which position should have to be set into the other one:
Code: Select all
[MeasureXY]
Measure=Calc
Formula=( #CURRENTCONFIGX# + #CURRENTCONFIGY# )
OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "The-Other-Config"][!SetVariable Y "#CURRENTCONFIGY#" "The-Other-Config"]
DynamicVariables=1
Then in this second skin (placed into the The-Other-Config config), you can watch the position of the first skin, for example though a String meter:
Code: Select all
[MeterPosition]
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=X: #X##CRLF#Y: #Y#
DynamicVariables=1
-
- Rainmeter Sage
- Posts: 2617
- Joined: March 23rd, 2015, 5:26 pm
Re: Can I extract the position of a skin to use as a variable?
Hi Balala,
This isn't quite right, your sample code is missing an important bang. The problem is the original poster mentions both skins will be active and wants the position change to be read by the other skin. The "other skin" will not re-read the variables once it has started, so the when the "first skin" changes position and writes the new X/Y, the X/Y variables will not be re-read.
But fixing this is simple; you just need to make a minor addition to the OnChangeAction to add a !Refresh bang:So when the "first config" skin moves, it will write the position and refresh "the other config", which will re-read the variable values.
Better yet, you should write the position not to a variable in some file, but to Rainmeter.ini, so that the other skin is moved to the position you want. Like so:You'll need to adjust the "???" to some number you want, of course.
P.S.: Forcing the "other-config" to refresh might be problematic, depending on what that skin is doing.
This isn't quite right, your sample code is missing an important bang. The problem is the original poster mentions both skins will be active and wants the position change to be read by the other skin. The "other skin" will not re-read the variables once it has started, so the when the "first skin" changes position and writes the new X/Y, the X/Y variables will not be re-read.
But fixing this is simple; you just need to make a minor addition to the OnChangeAction to add a !Refresh bang:
Code: Select all
OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "The-Other-Config"][!SetVariable Y "#CURRENTCONFIGY#" "The-Other-Config"][!Refresh "The-Other-Config"]
Better yet, you should write the position not to a variable in some file, but to Rainmeter.ini, so that the other skin is moved to the position you want. Like so:
Code: Select all
OnChangeAction=[!WriteKeyValue "The-OtherConfig" "WindowX" (#CURRENTCONFIGX#+???) "#SETTINGSPATH#Rainmeter.ini"][!WriteKeyValue "The-OtherConfig" "WindowY" (#CURRENTCONFIGY#+???) "#SETTINGSPATH#Rainmeter.ini"][!Refresh "The-Other-Config"]
P.S.: Forcing the "other-config" to refresh might be problematic, depending on what that skin is doing.
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Can I extract the position of a skin to use as a variable?
But yes, it definitely will. Just have to take care to use the DynamicVariables=1 option in any meter or measure which should have to use the variables. Have you added this option? Because believe me, before I post a such reply, I try out what I write. This time I also did and worked well.SilverAzide wrote:The problem is the original poster mentions both skins will be active and wants the position change to be read by the other skin. The "other skin" will not re-read the variables once it has started, so the when the "first skin" changes position and writes the new X/Y, the X/Y variables will not be re-read.
Have you tried out all these? Because I don't agree at all with you.SilverAzide wrote:But fixing this is simple; you just need to make a minor addition to the OnChangeAction to add a !Refresh bang:So when the "first config" skin moves, it will write the position and refresh "the other config", which will re-read the variable values.Code: Select all
OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "The-Other-Config"][!SetVariable Y "#CURRENTCONFIGY#" "The-Other-Config"][!Refresh "The-Other-Config"]
If you set a variable into The-Other-Config, then you refresh this "Other" config, the set up variable are immediately lost. The refresh is a very "big gun", as jsmorley very well said. Although there are some cases when it has to be used, usually is a good idea to be avoided. Anyway if you set up a variable with a !SetVariable bang, then you refresh the skin (even if all these are done by another skin), the newly set value of the variable is lost. There is no reason for a such action. Even if Gangula in his initial request said
I think better he should have not to refresh, but to update the skin, which are not the same at all. Many beginners make this confusion.Gangula wrote:the value of the variable should automatically change and the skin should automatically be refreshed.
As you said very well yourself:
SilverAzide wrote:P.S.: Forcing the "other-config" to refresh might be problematic, depending on what that skin is doing.
This wasn't asked by Gangula in his request, I think. If this is his real intention, then yes, this is the procedure to be followed.SilverAzide wrote:Better yet, you should write the position not to a variable in some file, but to Rainmeter.ini, so that the other skin is moved to the position you want. Like so:You'll need to adjust the "???" to some number you want, of course.Code: Select all
OnChangeAction=[!WriteKeyValue "The-OtherConfig" "WindowX" (#CURRENTCONFIGX#+???) "#SETTINGSPATH#Rainmeter.ini"][!WriteKeyValue "The-OtherConfig" "WindowY" (#CURRENTCONFIGY#+???) "#SETTINGSPATH#Rainmeter.ini"][!Refresh "The-Other-Config"]
-
- Posts: 14
- Joined: January 28th, 2018, 8:45 am
Re: Can I extract the position of a skin to use as a variable?
As balala mentioned, I'm a newbie to Rainmeter. But I understand the code good enough. Although your lines of code were too advanced, I understood it well enough thanks to your explanation.
Even then I was not able to achieve the result.
This is the code that is used in the config whose X value will be extracted
And this is the code I used in "test\number" config
This just returned a skin with the following text
Even then I was not able to achieve the result.
This is the code that is used in the config whose X value will be extracted
Code: Select all
Measure=Calc
Formula=( #CURRENTCONFIGX# + #CURRENTCONFIGY# )
OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "test\number"][!SetVariable Y "#CURRENTCONFIGY#" "test\number"]
DynamicVariables=1
Code: Select all
Meter=STRING
X=0
Y=0
Padding=15,5,15,5
FontColor=220,220,220
SolidColor=0,0,0,150
FontSize=8
FontFace=Segoe UI
StringStyle=BOLD
StringAlign=LEFT
AntiAlias=1
Text=X: #X##CRLF#Y: #Y#
DynamicVariables=1
X: #X#
Y: #Y#
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Can I extract the position of a skin to use as a variable?
This changes to two numeric value immediately you're moving the first skin, which has the posted Calc measure. Try it out.Gangula wrote:This just returned a skin with the following text
-
- Posts: 14
- Joined: January 28th, 2018, 8:45 am
Re: Can I extract the position of a skin to use as a variable?
never mind the previous reply. IT worked. Thanks for the reply. I missed using the "DynamicVariables=1"balala wrote:This changes to two numeric value immediately you're moving the first skin, which has the posted Calc measure. Try it out.
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Can I extract the position of a skin to use as a variable?
Observe the major difference between the [MeterPosition] meter and the [number] measure. The meter has a DynamicVariables=1 option, the measure don't have it. This option is required when a dynamically set variable is used (with the !SetVariable bang).Gangula wrote:Although, I was trying to use the variable #X# in a "CALC" measure along with the string meter you've given. But it doesn't seem to work. Can you tell me why?
So, add this option to the [number] measure and it'll start working.
-
- Posts: 14
- Joined: January 28th, 2018, 8:45 am
Re: Can I extract the position of a skin to use as a variable?
Can I use the !SetVariable bang to create a variable in the @resources folder?balala wrote:This option is required when a dynamically set variable is used (with the !SetVariable bang).
-
- Rainmeter Sage
- Posts: 16195
- Joined: October 11th, 2010, 6:27 pm
- Location: Gheorgheni, Romania
Re: Can I extract the position of a skin to use as a variable?
A variable isn't created into a folder, nor in @Resources, nor in any other. It can be written into the file, either in the main file of the skin, or in any other existing file, which has the proper structure (following the structure of the .ini files, having a [Variables] section, where the variable will be written). But no way to write it to a folder.Gangula wrote:Can I use the !SetVariable bang to create a variable in the @resources folder?
To write the variable into a file you have to use the !WriteKeyValue bang. Eg [!WriteKEyValue Variables X "#CURRENTCONFIGX#" "#@#Options.inc"] writes the value of the X variable into the Variables section of the #@#Options.inc file.
On the other hand !SetVariable sets dynamically the value of the variable, without writing it anywhere. This way you can use immediately and directly the newly set value (just have to add the DynamicVariables=1 options to any meter or measure where you want to use it).
Many times we're using both bangs to set dynamically the variable AND write it for a later use (eg after a refresh of the skin).