Showing results 1 to 5 of 5

Thread: Dynamic Screen Switch Function

  1. #1
    Join Date
    03.09.2019
    Posts
    7

    Frage Dynamic Screen Switch Function

    Hi,

    I'm trying to find a way to build a "Screen Switch Function" on the fly in an Add-In service. Considering the following configuration:


    [AddInExtension("Temp Service", "Service extension description", DefaultStartMode = DefaultStartupModes.Auto)]
    public class ProjectServiceExtension : IProjectServiceExtension
    {
    private IProject _project;



    public void Start(IProject context, IBehavior behavior)
    {
    _project = context;


    //-- This can just read from an attached variable on any object, and just execute this
    //-- BUT, this throws an exception that says it's a read only setting (Parameter)
    //-- Yet, the .Parameters says "get; set;" when I peek at the method implementation in visual studio.
    switchFunc.Parameter = "NextScreenName";
    switchFunc.Execute();
    }
    catch(Exception ex)
    {
    //-- Log exception...
    }
    }

    public void Stop()
    {
    _project.ScreenCollection.ElementLeftButtonUp -= ScreenCollection_ElementLeftButtonUp;
    }
    }

    My end goal is to just create a little add-on or script to have one common screen switch that can be reused and not have to define a 100 different screen switch functions in my project for simple tasks.

    How do I do this in Zenon?

    Thanks!
    Last edited by justinL : 4th June 2021 at 17:43 Reason: C# Code Formatter is not working correctly on website, left it as plain text

  2. #2
    Join Date
    03.11.2015
    Posts
    34

    Default Re: Dynamic Screen Switch Function

    Seriously, I cannot recommend this. If you want to create a screen switch function every time you create a screen or have a screen switch function created for all your screens: consider to create an Editor wizard or service, which creates the screen switch functions for you.

    ___

    It is possible to change the screen name in a dynamic property.
    Example (Wizard):

    ´´´Code

    public void Run(IProject context, IBehavior behavior)
    {
    var function = context.FunctionCollection["GenericScreenSwitch"];
    var propertyPathScreenParameter = "PictSwitch[0].Picture";
    var targetScreenName = "Screen2";
    function.SetDynamicProperty(propertyPathScreenPara meter,targetScreenName);
    function.Execute();
    }
    ´´´End

    Also remark, that some of the screen switch functions have filters included. You have to take care of them yourself.
    Last edited by c.f. : 7th June 2021 at 08:15 Reason: Added sample code

     

  3. #3
    Join Date
    01.07.2008
    Location
    Salzburg, AT
    Posts
    1,031

    Default Re: Dynamic Screen Switch Function

    i'm moving this thread from energy node as the topic is not energy specific

  4. #4
    Join Date
    03.09.2019
    Posts
    7

    Default Re: Dynamic Screen Switch Function

    Quote Originally Posted by c.f. View Post
    Seriously, I cannot recommend this. If you want to create a screen switch function every time you create a screen or have a screen switch function created for all your screens: consider to create an Editor wizard or service, which creates the screen switch functions for you.



    ___



    It is possible to change the screen name in a dynamic property.

    Example (Wizard):



    ´´´Code



    public void Run(IProject context, IBehavior behavior)

    {

    var function = context.FunctionCollection["GenericScreenSwitch"];

    var propertyPathScreenParameter = "PictSwitch[0].Picture";

    var targetScreenName = "Screen2";

    function.SetDynamicProperty(propertyPathScreenPara meter,targetScreenName);

    function.Execute();

    }

    ´´´End



    Also remark, that some of the screen switch functions have filters included. You have to take care of them yourself.


    Hi C.F.,

    I appreciate the help, thank you. It appears that you can't create the function on the fly if it doesn't exist, but it does work if the function already exists, which is no big deal.

    The following line of code does not work at runtime:

    screenSwitchFunction = context.FunctionCollection.Create("NameOfFunction", FunctionType.ScreenSwitch);

    This may be normal behavior though.

    You say you do not recommend this, but this is a far more efficient workflow: To have one screen switch function in the project that is reused by each element with the project. Each element would have a simple variable attached that defines the screen name that the triggered element will switch to.

    As opposed to having 100 screen switch functions defined in the project for 100 different elements. That's kind of silly when you consider I have to define one screen switch per element and I can't simply create 1 function that simply takes the name of the screen to switch to as the parameter.

    Now, that being said, my example is with "Standard" screen types, this may be different when I delve into the intricacies of the other screen types, but for now this is sufficient.

    Thanks!
    Last edited by justinL : 7th June 2021 at 14:15 Reason: Modification

  5. #5
    Join Date
    03.11.2015
    Posts
    34

    Default Re: Dynamic Screen Switch Function

    Yes, the function has to exist.


    Creating a function in the context of the runtime does not work. normal behaviour - as stated.
    Last edited by c.f. : 7th June 2021 at 14:31

     

Similar Threads

  1. Reg: Variables Will Impact Delay in Screen switch function in Runtime
    By saravanan1985 in forum zenon Service Engine Supervisor
    Replies: 1
    Last Post: 3rd July 2018, 13:09
  2. Reg: Variables Will Impact Delay in Screen switch function in Runtime
    By saravanan1985 in forum zenon Energy Edition
    Replies: 0
    Last Post: 12th June 2018, 15:51
  3. Manipulation 'Screen switch'-Rt-Function via C#
    By michael.winter in forum VSTA
    Replies: 4
    Last Post: 19th November 2014, 14:46
  4. Replies: 2
    Last Post: 24th May 2013, 04:12
  5. Dynamic text on momentary switch button
    By robolution in forum zenon Service Engine Supervisor
    Replies: 2
    Last Post: 8th May 2013, 08:30

Tags for this Thread

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •