Click or drag to resize

RelaxISPlugin General Example

The example class below is intended to serve as an illustration of the functions and properties common to the RelaxISPlugin class. This is the base class that all RelaxIS plugins inherit from.

Only the Name and Description properties are mandatory to overwrite. Overwriting the other properties and methods can be useful in certain circumstances depending on the plugin type and application.

Requirements
  • Reference to the RelaxIS_SDK.dll

  • .NET Framework 4.7.2 target (class library)

  • Recommended: Development environment with compiler e.g. RelaxIS SDK Code Editor, Microsoft Visual Studio

Demonstrates

This examples illustrates the common properties and methods in the RelaxISPlugin class.

Example
C#
// <copyright file="RelaxISPluginGeneral.cs" company="rhd instruments GmbH and Co. KG">
// Copyright (c) rhd instruments GmbH and Co. KG. All rights reserved.
// Licensed under the MIT No Attribution (MIT-0) license. See section 'License' in the 'SDK Examples / Tutorials' topic for full license information.
// </copyright>

namespace RelaxIS_SDK_Examples.Plugins
{
    /***
     * This class demonstrates which properties are common to all RelaxISPlugin classes.
     */

    using System.Collections.Generic;

    /// <summary>
    /// Shows the functions and properties common to all <see cref="RelaxIS_SDK.Plugins.RelaxISPlugin"/> plugins.
    /// </summary>
    public abstract class RelaxISPluginGeneral
        : RelaxIS_SDK.Plugins.RelaxISPlugin
    {
        /***
         * The Name and Description properties must be overridden by all plugin.
         * Name defines the internal name of the plugin, that is not only used for display
         * purposes, but also by functions to refer to the plugin.
         * For example, plot presets refer to AxisValue plugins using this Name property.
         * Description however is only defined for display purposes.
         */

        /// <inheritdoc/>
        public override string Name
        {
            get
            {
                return "A plugin name";
            }
        }

        /// <inheritdoc/>
        public override string Description
        {
            get
            {
                return "A plugin description";
            }
        }

        /***
         * This property determines the order of plugins in RelaxIS.
         * E.g. RelaxIS loads all plugins and then sorts them by this property value, ascending.
         * The consequences of defining this index depend on the plugin type. E.g. plot presets
         * will show up in a different order in the ribbon dropdown, while for file formats it
         * determines in which order RelaxIS tries them out in order to load data.
         * Overriding it is not required in most cases, but can be used for some specialized purposes.
         */

        /// <inheritdoc/>
        public override int SortIndex
        {
            get
            {
                return base.SortIndex;
            }
        }

        /***
         * Per default, the AfterStartupInitialization function does nothing.
         * It runs once, after the plugin has been initialized by RelaxIS.
         * Plugins can utilize it to perform one-time initialization steps if needed.
         */

        /// <inheritdoc/>
        public override void AfterStartupInitialization()
        {
            base.AfterStartupInitialization();
        }

        /***
         * The ShouldDiscardPlugin function runs once after the plugin has been initialized by RelaxIS.
         * If the function returns true, RelaxIS will discard the plugin, and it will
         * not be available to the user afterwards.
         * If not overridden, it always returns false.
         */

        /// <inheritdoc/>
        public override bool ShouldDiscardPlugin()
        {
            return base.ShouldDiscardPlugin();
        }

        /***
         * The GetAdditionalInformation function per default returns some
         * information fields that are displayed to the user in the
         * RelaxIS Setup -> Plugins screen.
         * It is recommended to get the values from the parent implementation
         * and add to it, instead of fully returning a custom dictionary.
         */

        /// <inheritdoc/>
        public override Dictionary<string, string> GetAdditionalInformation()
        {
            return base.GetAdditionalInformation();
        }

        /***
         * This function demonstrates the use of additional properties and functions
         * of the plugin, namely properties to get the plugin and user data paths and
         * the ability to write log entries to RelaxIS.
         */

        /// <summary>
        /// Illustrates further plugin properties.
        /// </summary>
        protected void IllustrateProperties()
        {
            // The PluginSourcePath is set by RelaxIS to the full path to the
            // file that the plugin was loaded from.
            var srcPath = this.PluginSourcePath;

            // The UserDataDirectory is set by RelaxIS to the full path to the
            // current user data directory, per default in My Documents\RelaxIS\3.0\
            var userDataPath = this.UserDataDirectory;

            // The AddLogMessage raises the NewLogMessage event which is handled by RelaxIS
            // to write log entries into the RelaxIS log file.
            // It is useful for debugging purposes.
            this.AddLogMessage("Plugin source path: " + srcPath);
            this.AddLogMessage("User data path: " + userDataPath);
        }
    }
}
See Also

Other Resources

List of examples