It is currently April 16th, 2024, 5:52 am

Can I extract the position of a skin to use as a variable?

Get help with creating, editing & fixing problems with skins
Gangula
Posts: 14
Joined: January 28th, 2018, 8:45 am

Can I extract the position of a skin to use as a variable?

Post by Gangula »

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?
User avatar
balala
Rainmeter Sage
Posts: 16141
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can I extract the position of a skin to use as a variable?

Post by balala »

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?
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.
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
When the sum of the X and Y position of the skin is changing, the two !SetVariable bangs set up position of the skin, as the X and Y variables, into the other skin (config). What you have to take care is to set up properly the name of the config where is placed the skin where you would like to use the position of the current skin.
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
If you want a more accurate calculation, you should have to use instead of the [MeasureXY] measure (in the first skin), two measures, one for each position: [MeasureX] and respectively [MeasureY]. Each of these should have to set the appropriate variable. But I don't think it worth to create two different measures, one is enough, in my opinion. It's practically impossible to change the position of the skin in a way to have the sum not changing.
User avatar
SilverAzide
Rainmeter Sage
Posts: 2601
Joined: March 23rd, 2015, 5:26 pm

Re: Can I extract the position of a skin to use as a variable?

Post by SilverAzide »

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:

Code: Select all

OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "The-Other-Config"][!SetVariable Y "#CURRENTCONFIGY#" "The-Other-Config"][!Refresh "The-Other-Config"]
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:

Code: Select all

OnChangeAction=[!WriteKeyValue "The-OtherConfig" "WindowX" (#CURRENTCONFIGX#+???) "#SETTINGSPATH#Rainmeter.ini"][!WriteKeyValue "The-OtherConfig" "WindowY" (#CURRENTCONFIGY#+???) "#SETTINGSPATH#Rainmeter.ini"][!Refresh "The-Other-Config"]
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.
Gadgets Wiki GitHub More Gadgets...
User avatar
balala
Rainmeter Sage
Posts: 16141
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can I extract the position of a skin to use as a variable?

Post by balala »

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.
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: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"]
So when the "first config" skin moves, it will write the position and refresh "the other config", which will re-read the variable values.
Have you tried out all these? Because I don't agree at all with you.
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
Gangula wrote:the value of the variable should automatically change and the skin should automatically be refreshed.
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.
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.
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:

Code: Select all

OnChangeAction=[!WriteKeyValue "The-OtherConfig" "WindowX" (#CURRENTCONFIGX#+???) "#SETTINGSPATH#Rainmeter.ini"][!WriteKeyValue "The-OtherConfig" "WindowY" (#CURRENTCONFIGY#+???) "#SETTINGSPATH#Rainmeter.ini"][!Refresh "The-Other-Config"]
You'll need to adjust the "???" to some number you want, of course.
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.
Gangula
Posts: 14
Joined: January 28th, 2018, 8:45 am

Re: Can I extract the position of a skin to use as a variable?

Post by Gangula »

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

Code: Select all

Measure=Calc
Formula=( #CURRENTCONFIGX# + #CURRENTCONFIGY# )
OnChangeAction=[!SetVariable X "#CURRENTCONFIGX#" "test\number"][!SetVariable Y "#CURRENTCONFIGY#" "test\number"]
DynamicVariables=1
And this is the code I used in "test\number" config

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
This just returned a skin with the following text
X: #X#
Y: #Y#
User avatar
balala
Rainmeter Sage
Posts: 16141
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can I extract the position of a skin to use as a variable?

Post by balala »

Gangula wrote:This just returned a skin with the following text
This changes to two numeric value immediately you're moving the first skin, which has the posted Calc measure. Try it out.
Gangula
Posts: 14
Joined: January 28th, 2018, 8:45 am

Re: Can I extract the position of a skin to use as a variable?

Post by Gangula »

balala wrote:This changes to two numeric value immediately you're moving the first skin, which has the posted Calc measure. Try it out.
never mind the previous reply. IT worked. Thanks for the reply. I missed using the "DynamicVariables=1"
User avatar
balala
Rainmeter Sage
Posts: 16141
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can I extract the position of a skin to use as a variable?

Post by balala »

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?
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).
So, add this option to the [number] measure and it'll start working.
Gangula
Posts: 14
Joined: January 28th, 2018, 8:45 am

Re: Can I extract the position of a skin to use as a variable?

Post by Gangula »

balala wrote:This option is required when a dynamically set variable is used (with the !SetVariable bang).
Can I use the !SetVariable bang to create a variable in the @resources folder?
User avatar
balala
Rainmeter Sage
Posts: 16141
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Can I extract the position of a skin to use as a variable?

Post by balala »

Gangula wrote:Can I use the !SetVariable bang to create a variable in the @resources folder?
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.
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).