It is currently April 24th, 2024, 1:29 pm

How can I use custom plugin functions in a skin?

Get help with creating, editing & fixing problems with skins
ayousuf
Posts: 3
Joined: November 6th, 2020, 7:38 pm

How can I use custom plugin functions in a skin?

Post by ayousuf »

I made a custom plugin, which has a function that returns a string (an IntPtr that refers to a string). How can I call that function from my skin? Do I have to call it from the meter or measure or only one of them?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I use custom plugin functions in a skin?

Post by jsmorley »

It's not clear from your post if you used the Plugin API, but if you did, then you are going to want to do the work that creates the string in Update(), and simply return the value in GetString(). The string will become the string value of the measure in the skin, and will be updated on each update of the measure.

https://docs.rainmeter.net/developers/#CreatePlugin

https://docs.rainmeter.net/developers/#APIDocumentation

The example PluginSystemVersion in the Plugin API is probably a good one to show how to return both number and string values with a plugin.

If you are not using the Plugin API, I seriously doubt you will ever get it to work with Rainmeter.
ayousuf
Posts: 3
Joined: November 6th, 2020, 7:38 pm

Re: How can I use custom plugin functions in a skin?

Post by ayousuf »

If you look at the C# plugin overview at https://docs.rainmeter.net/developers/plugin/csharp/ in the section "optional functions" there is a subsection called "custom function".

The website says under "custom function", "You can define a custom function to be used in a section variable. The name of the function is the name to be used in the skin file as a section variable. The function must be exported. [...] the skin will call this function (as a section variable) like this: [PluginMeasure:func(someArg1, someArg2)]."

I am using the Plugin API. How do I use the custom function in the skin?
User avatar
jsmorley
Developer
Posts: 22629
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: How can I use custom plugin functions in a skin?

Post by jsmorley »

You just call the function as a section variable. More often than not, it will be in the Text option of a String meter, but it could be anywhere you can use a section variable. The resulting string returned by the function will simply replace the section variable wherever it is used.

Two things to keep in mind:

1) You should use DynamicVariables=1 on any meter or measure you use it on, since you are presumably not just passing it some static argument. This is not required if you are using the section variable in a !Bang parameter, those are always evaluated dynamically.

2) You must use the "nested" format for a section variable.
https://docs.rainmeter.net/manual/variables/nesting-variables/

Text=[&PluginMeasureName:YourFunctionName(SomeArgument)]

LeftMouseUpAction=[!SetOption SomeMeter Text "[&PluginMeasureName:YourFunctionName(SomeArgument)]"]

The example PluginSectionVariables in the Plugin API demonstrates pretty well I think.

If you build that plugin and add the appropriate 32bit or 64bit .dll to the %APPDATA%\Rainmeter\Plugins folder and restart or Refresh All Rainmeter, you can use it like this:

Code: Select all

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

[Variables]

[MyPlugin]
Measure=Plugin
Plugin=SectionVariables
Disabled=1

[MeterUpper]
Meter=String
FontSize=11
FontWeight=400
FontColor=255,255,255,255
SolidColor=47,47,47,255
Padding=5,5,5,5
AntiAlias=1
Text=[&MyPlugin:ToUpper(Hello World)]
DynamicVariables=1


1.jpg


Note that I Disabled the plugin measure, since I am not in any way depending on the Update() function in the plugin, and thus don't need to bother having Rainmeter update the plugin on each skin / measure update. I'm just directly calling the Function() on each update of the meter, to do all processing and return a value. While in this case I can Disable the plugin measure, it must be there, as it will act as the "host" for the function.

Note that the Function() in the API as written assumes that the argument is a string, and no "quotes" are required around what you pass to it. If you want to pass a number and do math with it, you will need to re-cast it as a number in the function, then re-cast the result back to a string to return. Both the input and output of the Function() will always be a string. If you return a string that represents a number, Rainmeter won't care. It will dynamically type the value in the context it is used. If you use it as a number, Rainmeter will treat it as a number.

Note that DynamicVariables=1 is actually not required in this instance, as I am in fact just passing a static string argument that won't change. This is just an example, and I suspect that more often than not you will be passing some dynamic argument. Some changing #Variable# or some value of another [&MeasureName], and DynamicVariables=1 will then be required.

If you are planning to distribute your plugin, take care to fill in and keep current the AssemblyInfo.cs (C#) or PluginName.rc (C++) file in the project. You should have a new version number each time you release an update, or the process that installs .rmskin packages in Rainmeter will ignore it.
You do not have the required permissions to view the files attached to this post.
ayousuf
Posts: 3
Joined: November 6th, 2020, 7:38 pm

Re: How can I use custom plugin functions in a skin?

Post by ayousuf »

Thanks! I really appreciate your help! :D :welcome: