Eplan Platform API
Eplan API / User Guide / API Framework / Add-ins / Actions / Modifying action status
In This Topic
    Modifying action status
    In This Topic

    If you want to verify the status of your action, you can have your action class implement the  IEplActionChecked  interface (in addition to the  IEplAction  interface). In the  IEplActionChecked.Checked  method you can then get the current status of your action and you can modify its status in the  Execute  method. Here are two useful application examples:

    Toggling an action status via on / off action

    The following example shows an action that enables / disables script debugging by toggling the corresponding setting.

    public class OnOffAction : IEplAction, IEplActionChecked
    {
        public bool DebugScriptsEnabled { get; set; }
        public static string SettingsPath = "USER.EplanEplApiScriptLog.DebugScripts";
    
        public bool Execute(ActionCallingContext ctx)
        {
            DebugScriptsEnabled = !DebugScriptsEnabled;
            new Settings().SetBoolSetting(SettingsPath, DebugScriptsEnabled, 0);
    
            if (new Settings().GetBoolSetting(SettingsPath, 0) != DebugScriptsEnabled)
            {
                new Decider().Decide(EnumDecisionType.eOkDecision, 
                                     "Switching setting failed!", 
                                     "Toggle Script Debugging", 
                                     EnumDecisionReturn.eOK, 
                                     EnumDecisionReturn.eOK);
                return false;
            }
            
            new Decider().Decide(EnumDecisionType.eOkDecision, 
                                 $"Debugging scripts {(DebugScriptsEnabled ? "enabled" : "disabled")}", 
                                 "Toggle Script Debugging", 
                                 EnumDecisionReturn.eOK, 
                                 EnumDecisionReturn.eOK);
            return true;
        }
    
        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            return true;
        }
    
        // The GetActionProperties method is only to be implemented for .NET Framework.
        // If you use .NET 8, please delete this method.
        public void GetActionProperties(ref ActionProperties actionProperties)
        {
        }
    
        #region IEplActionChecked Members
        public int Checked(string strActionName, ActionCallingContext actionContext)
        {
            return Convert.ToInt32(DebugScriptsEnabled);
        }
        #endregion
    }
    
    

     

    Toggling a group of radio buttons

    Below is an example in which the display language is controlled by a group of three radio buttons. For each radio button, create an action class that implements the  IEplActionChecked  interface. However, the status is only saved in the one of these radio button action classes.

    public class RadioButtonDisplayLanguageEnglish : IEplAction, IEplActionChecked
    {
        public static ISOCode.Language ActiveDisplayLanguage { get; set; }
        private const string SettingsPath = "TRANSLATEGUI.DISPLAYED_LANGUAGES";
        private const ISOCode.Language Language = ISOCode.Language.L_en_US;
    
        public bool Execute(ActionCallingContext ctx)
        {
            var project = new SelectionSet().GetCurrentProject(false);
    
            // Set the display language to English
            if ((project != null) && new Translate().SetDisplayedLanguages(project, new ISOCode().GetString(Language)))
            {
                ActiveDisplayLanguage = Language;
                new Decider().Decide(EnumDecisionType.eOkDecision, 
                                    $"The display language was changed to {new ISOCode().GetLongName(Language)}.", 
                                    "Toggle Display Language", 
                                    EnumDecisionReturn.eOK, 
                                    EnumDecisionReturn.eOK);
                return true;
            }
    
            new Decider().Decide(EnumDecisionType.eOkDecision, 
                                $"Setting the display language to {new ISOCode().GetLongName(Language)} failed!", 
                                "Toggle Display Language", 
                                EnumDecisionReturn.eOK, 
                                EnumDecisionReturn.eOK);
            return false;
        }
    
        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            using(new LockingStep()) 
            {
                // Initialize ActiveDisplayLanguage: Get the current display language
                var project = new SelectionSet().GetCurrentProject(false);
                if (project == null) return true;
    
                ActiveDisplayLanguage = new ISOCode().GetNumber(new ProjectSettings(project)
                    .GetExpandedStringSetting(SettingsPath, 0).Trim(';'));
            }
                return true;
        }
    
        // The GetActionProperties method is only to be implemented for .NET Framework.
        // If you use .NET 8, please delete this method.
        public void GetActionProperties(ref ActionProperties actionProperties)
        {
        }
    
        #region IEplActionChecked Members
        public int Checked(string strActionName, ActionCallingContext actionContext)
        {
            // This function is called often and should work fast
            return Convert.ToInt32(ActiveDisplayLanguage == Language);
        }
        #endregion
    }
    
    

     

    The other two radio button action classes access the status in the first one class when querying and changing:

    public class RadioButtonDisplayLanguageGerman : IEplAction, IEplActionChecked  
    {
        private const ISOCode.Language Language = ISOCode.Language.L_de_DE;
    
        public bool Execute(ActionCallingContext ctx)
        {
            var project = new SelectionSet().GetCurrentProject(false);
    
            if ((project != null) && new Translate().SetDisplayedLanguages(project, new ISOCode().GetString(Language)))
            {
                RadioButtonDisplayLanguageEnglish.ActiveDisplayLanguage = Language;
                new Decider().Decide(EnumDecisionType.eOkDecision,
                    $"The display language was changed to {new ISOCode().GetLongName(Language)}.",
                    "Toggle Display Language",
                    EnumDecisionReturn.eOK,
                    EnumDecisionReturn.eOK);
                return true;
            }
    
            new Decider().Decide(EnumDecisionType.eOkDecision,
                $"Setting the display language to {new ISOCode().GetLongName(Language)} failed!",
                "Toggle Display Language",
                EnumDecisionReturn.eOK,
                EnumDecisionReturn.eOK);
            return false;
           
        }
    
        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            return true;
        }
    
        // The GetActionProperties method is only to be implemented for .NET Framework.
        // If you use .NET 8, please delete this method.
        public void GetActionProperties(ref ActionProperties actionProperties)
        {
        }
    
        #region IEplActionChecked Members
        public int Checked(string strActionName, ActionCallingContext actionContext)
        {
            // This function is called often and should work fast
            return Convert.ToInt32(RadioButtonDisplayLanguageEnglish.ActiveDisplayLanguage == Language);
        }
        #endregion
    }
    
    

     

    public class RadioButtonDisplayLanguageFrench : IEplAction, IEplActionChecked
    {
        private const ISOCode.Language Language = ISOCode.Language.L_fr_FR;
    
        public bool Execute(ActionCallingContext ctx)
        {
            var project = new SelectionSet().GetCurrentProject(false);
    
            // Set the display language to French
            if ((project != null) && new Translate().SetDisplayedLanguages(project, new ISOCode().GetString(Language)))
            {
                RadioButtonDisplayLanguageEnglish.ActiveDisplayLanguage = Language;
                new Decider().Decide(EnumDecisionType.eOkDecision,
                    $"The display language was changed to {new ISOCode().GetLongName(Language)}.",
                    "Toggle Display Language",
                    EnumDecisionReturn.eOK,
                    EnumDecisionReturn.eOK);
                return true;
            }
    
            new Decider().Decide(EnumDecisionType.eOkDecision,
                $"Setting the display language to {new ISOCode().GetLongName(Language)} failed!",
                "Toggle Display Language",
                EnumDecisionReturn.eOK,
                EnumDecisionReturn.eOK);
            return false;
        }
    
        public bool OnRegister(ref string Name, ref int Ordinal)
        {
            return true;
        }
    
        // The GetActionProperties method is only to be implemented for .NET Framework.
        // If you use .NET 8, please delete this method.
        public void GetActionProperties(ref ActionProperties actionProperties)
        {
        }
    
        #region IEplActionChecked Members
        public int Checked(string strActionName, ActionCallingContext actionContext)
        {
            // This function is called often and should work fast
            return Convert.ToInt32(RadioButtonDisplayLanguageEnglish.ActiveDisplayLanguage == Language);
        }
        #endregion
    }
    
    

     

    Please keep in mind that the  IEplActionChecked.Checked  method is called very often and should therefore be performant.

    See Also