Showing results 1 to 7 of 7

Thread: VSTA Project not working properly

  1. #1
    Join Date
    09.02.2018
    Posts
    9

    Frage VSTA Project not working properly

    Hi people,

    I am new with Zenon and I am trying to create a runtime script with C# on VSTA. I have copied the code written in the help's examples (the one named "Writing project information in the zenon output window")  and I am getting errors with the "this" members like this.Application or this.ActiveDocument. I have already added the Microsoft.VisualStudio.Tools.Applications.Runt ime.v9.0 reference in the project but that didn't fix it. 

    Here I will put some additional information that I think might have something to do with my problem:
    • There is the following error in zenon's output window:
           Debug output:Addin Error!
           Debug output:C:\ProgramData\COPA-DATA\zenon760\VSTAWorkspace\CSharp\WorkspaceAddin\ bin\WorkspaceAddin.dll
           Debug output:Loading Addin
           Debug output:Could not find file 'C:\ProgramData\COPA-DATA\zenon760\VSTAWorkspace\CSharp\WorkspaceAddin\ bin\WorkspaceAddin.dll'.

    • Before my VSTA project opens an alert with the following message is displayed "For current projects please use the Add-In interface with visual studio in order to make full use of the newest .NET functionality".
    • If I try to open VSTA directly and create a new project there is no project template to choose from so I cannot create any project (I tried to use the VSTA/setup command but didn't work).

    I am really stuck here I will appreciate any help I can get.

    Thanks

  2. #2
    Join Date
    15.11.2016
    Posts
    87

    Default Re: VSTA Project not working properly

    Hello,

    and welcome to the Forum.

    A few notes:
    1. VBA, VSTA and Addin-Framework are three different things.
    2. API access in zenon is split in
     - Editor (WorkspaceAddin, ActiveDocument, etc.)
     - Runtime (ProjectAddin, ThisProject, etc.)

    I have copied the code written in the help's examples (the one named


    "Writing project information in the zenon output window")  and I am


    getting errors with the "this" members like this.Application or


    this.ActiveDocument.
    Most examples in the Help are for use with the Editor.
    -> ActiveDocument and the output window are only accessible in the Editor.

    Please tell us what you would like to do.
    -> There may be a way to do this without C# Code.


    • Before my VSTA project opens an alert with the following message


      is displayed "For current projects please use the Add-In interface with


      visual studio in order to make full use of the newest .NET


      functionality".
    • If I try to open VSTA directly and create a new


      project there is no project template to choose from so I cannot create


      any project (I tried to use the VSTA/setup command but didn't work).
    We recommend to use the Addin-Framework.
    - Open the Addin-Editor with: Main menu: Tools -> Open Add-In Editor...
    - You have access to the pre-installed Templates: Editor Wizard and Service, Runtime Wizard and Service.
    - The help does explain new API (with Addin Framework).
     -> But it is well documented in the Reference
     -> Please see general information in the help: Manual -> Programming Interfaces -> Add-Ins
     -> There are also some examples on our Git: https://github.com/COPA-DATA

    Hope this helps.

    BR,
    Georg

  3. #3
    Join Date
    09.02.2018
    Posts
    9

    Default Re: VSTA Project not working properly

    Thanks Georg,

    I have created the Add-In as you said and looked the Add-In section in the manual. I've created a project service extension and added the following code to make it run automatically:

    [AddInExtension("testADA", "test ADA", "test category", DefaultStartMode=DefaultStartupModes.Auto)]

    Now I want to change a zenon variable's value through my extension's start function (just as an experiment). I saw that the context object has a "Variable Collection" property so I made a for loop to iterate collection looking for a variable by name like this:

    var variables = context.VariableCollection;
    for(int i=0;i if(variables[i].Name=="VarName")
    variables[i].SetValue(true);
    }


    With this I want to look for a variale with name "VarName" and change itīs value to true (VarName is a bool in zenon). But this method asks for four parameters: Object value, int lowerState, int time and short timeMilliSeconds. I don't find much sense in these parameters and it doesn't accept just the true I want to set. I would like to know if this approach I did is correct and how I use the SerValue method since I don't find any example of this method in the manual. Also I find a little confusing the difference between editor and runtime Add-In and when to use each one.

    Thank you
    Last edited by jesus_michel : 12th February 2018 at 18:46

  4. #4
    Join Date
    15.11.2016
    Posts
    87

    Default Re: VSTA Project not working properly

    Hello,

    I guess I should explain the differences between Editor and Runtime API.
    And the difference between Service and Wizard.

    A Wizard is something you can execute, it runs through the code and closes itself again.
    -> Triggered by function in Runtime and by Wizard-dialog in Editor.

    A Service is something thats starts automatically, or manually via dialog (no function).
    - It has a start() function and a stop() function that trigger when the service is started and stopped.
    Its main use is to subscribe an Event and work with that.
    -> Runtime example: Variable Changed Event, Alarm comes Event, Screen opened event.
    -> Editor example: Element created Event, RemoteTransport events, etc.

    In your case you probably want a Runtime Wizard.
    -> That way you can trigger it via a function (button).

    For getting your variable:
    You can directly access your variable from the collection by name:
    IVariable myVar = context.VariableCollection["bool"];

    For setting values, there are multiple ways.
    The SetValue function has 5 ways to set a value.
    For just setting a value, i recommend the 5th way:
    void SetValue(int index, object value);

    The Index does not really matter. I always use an index of 1.

    Hope this helps.

    BR,
    Georg

  5. #5
    Join Date
    09.02.2018
    Posts
    9

    Default Re: VSTA Project not working properly

    Hi, 

    Thank you very much Georgk. You are helping me a lot to understand this. Now I was able to write my script, but I don't know how to run it.

    I have imported the Add-In I created after saving and building the project which is a runtime service. Then I placed a breakpoint to debug my program, but when I run zenon in runtime it doesn't show signals that the debugger is working and the code is not executing. I've checked the output window and it showed the following message:

    Debug output:Addin Error!
    Debug output:C:\ProgramData\COPA-DATA\zenon760\VSTAWorkspace\CSharp\WorkspaceAddin\ bin\WorkspaceAddin.dll
    Debug output:Loading Addin
    Debug output:Could not find file 'C:\ProgramData\COPA-DATA\zenon760\VSTAWorkspace\CSharp\WorkspaceAddin\ bin\WorkspaceAddin.dll'.

    hope you can give me guidance with this and with the debugging process.

    Thank you

  6. #6
    Join Date
    15.11.2016
    Posts
    87

    Default Re: VSTA Project not working properly

    Hi,

    Make sure the Project has the Debug Target configured.
    (in SharpDevelop) Project -> Properties -> Add-In
    Select Debug Target: Runtime with name of Project.
    -> Runtime ahs to be running for beeing selectable.

    Also:
    If you have a Runtime Wizard, you have to create the function to run it.
    -> new function -> Add-In -> Execute Project Wizard Extenstion.
    For Services, you can open show the function: dialog with the Display dialog Manage Runtime Services.

    Hope this helps.

    BR,
    Georg

  7. #7
    Join Date
    09.02.2018
    Posts
    9

    Default Re: VSTA Project not working properly

    Hi Gerogk,

    It is working fine now thanks. 

Similar Threads

  1. VSTA read variable value's another project!
    By dvangenderen in forum VSTA
    Replies: 5
    Last Post: 1st December 2011, 10:04
  2. Replies: 5
    Last Post: 3rd August 2011, 17:24
  3. Problem of VSTA after restore project
    By altera in forum VSTA
    Replies: 2
    Last Post: 22nd June 2010, 14:48
  4. Replies: 3
    Last Post: 7th February 2008, 16:55
  5. Replies: 0
    Last Post: 25th September 2007, 14:10

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
  •