Page 1 of 2 1 2 LastLast
Showing results 1 to 10 of 14

Thread: How to create Function with linking rule with vba

  1. #1
    Join Date
    10.08.2012
    Posts
    17

    Default How to create Function with linking rule with vba

    Hi all,
    I created function with code below, now I need to do linking rule for all variables in the picture "TestPicture". Is it possible with vba ?
    Br.
    Lukasz

    Dim zFCT As RtFunction
    Set zFCT = MyWorkspace.ActiveDocument.RtFunctions.Create("TestFunction", tpPicture)
    With zFCT
            .DynProperties("Picture") = "TestPicture"
    End With

  2. #2
    Join Date
    20.08.2009
    Posts
    293

    Default AW: How to create Function with linking rule with vba

    Hi,

    this should work:

    Dim zFCT As RtFunction
    Set zFCT = MyWorkspace.ActiveDocument.RtFunctions.Create("TestFunction", tpPicture)
    With zFCT
            .DynProperties("PictSwitch[0].Picture") = "TestPicture"
    End With

    Have a look at the attached screen and check the XML Export of your function for details.
    PictSwitch_0 in the XML has to be PictSwitch[0] in the code.

    Click image for larger version

Name:	xml.PNG
Views:	168
Size:	23.6 KB
ID:	1234

    Note that the PictFilter_0 settings are screen type specific, so it can be dangerous exchanging the screen afterwards.
    (As filters are screen type specific and might not fit after exchanging the screen/screen type, which is prohibited in the Editor anyway).


    Regards,
    Bernhard
    Last edited by bernhardf : 1st October 2013 at 09:57

  3. #3
    Join Date
    10.08.2012
    Posts
    17

    Default Re: How to create Function with linking rule with vba

    Maybe I didn't explain what exactly do I need to do in VBA.
    What I'm trying to achieve is:
    1. Create a function screen switch with VBA
    2. Chose a picture to open
    3. Find out what variable are on the picture
    4. Make a linking rule for all variables in the picture
    5. replacement for example: to .
    I'm expecting to create function like in the attachment.
    Br.
    Lukasz
    Attached Thumbnails Attached Thumbnails prefix.png  

  4. #4
    Join Date
    10.12.2007
    Posts
    260

    Blinzeln AW: How to create Function with linking rule with vba

    Maybe this helps:
    Set zFct = thisProject.RtFunctions.Item("TestFunction")
    If Not zFct Is Nothing Then
        For i = 0 To CLng(zFct.DynProperties("PictSwitch.SubstiVar[-1]")) - 1
            zFct.DynProperties("PictSwitch.SubstiVar[" & i & "].Destination") = vba.Replace(zFct.DynProperties("PictSwitch.SubstiVar[" & i & "].Source"), "Prefix1", "Prefix2")
        Next i
        zFct.Start
        Set zFct = Nothing
    End If

    To use this Code, you have to create the Function "TestFunction" in the Editor as a PictureSwitch Function to the designatet Picture with substituted Variables (otherwise DynProperties("PictSwitch.SubstiVar[-1]") will show 0).
    Last edited by mst : 1st October 2013 at 10:52

  5. #5
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    881

    Default Re: How to create Function with linking rule with vba

    @mst: your code does modify existing linking rules (substitution) of variables before executing the function in the runtime (thats not creating a function in the editor)

    @rrkobra: if you have already a function available and you simply want to duplicate this kind of function you can make copy of the function itself and then modifing the parameters of the copied function to you needs

    Copy Functions:
    Manual -> Programming interfaces -> Object model -> RtFunction -> Copy

    regards,
    herbert


  6. #6
    Join Date
    10.08.2012
    Posts
    17

    Default Re: How to create Function with linking rule with vba

    I would like to create the function in Editor from scratch.
    Br
    Lukasz

  7. #7
    Join Date
    10.12.2007
    Posts
    260

    Default AW: How to create Function with linking rule with vba

    I know that my Code changes the substituted Variables from the Function in the RT, but I made the experience that this is much better than creating all the Functions via Wizard in the Editor.
    Reason:
    It doesnīt mind if you need more Functions later and it doesnīt matter if you change the Picture afterwards.

    But you are right, this is not exactly what rrkobra was asking for. (itīs better )

  8. #8
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    881

    Default Re: How to create Function with linking rule with vba

    Somewhere on my harddisk i have a sample project which demonstrate the substition of variables within a screen switch function in the zenon runtime. the major advantage doing so is that you only have 1 function which you have to create and also maintain - before executing in the runtime the function is modified (as mentioned by mst).

    Let me know if you want to consider the above mentioned functionality of substituting variable of a function then i will search about this demo and upload it here....

    regards,
    herbert


  9. #9
    Join Date
    10.08.2012
    Posts
    17

    Default Re: How to create Function with linking rule with vba

    So, it means that is not possible to do it in the editor with vba.
    Would be nice If you can upload your sample project.

  10. #10
    Join Date
    30.05.2007
    Location
    Salzburg
    Posts
    881

    Default AW: How to create Function with linking rule with vba

    So, it means that is not possible to do it in the editor with vba.
    -> of course it is possible

    Let me explain it via following example:
    If you create via zenon Editor (not VBA) a screen switch function and you do not make a subsitution there the function will not add the additional information (=DynProperties) - "Substivar".
    If you create via zenon Editor (not VBA) a screen switch function and you also do a variable substitution there it will add this information as dynamic properties (=DynProperties) to this function.

    With the VBA/VSTA method "CreateDynProperty" you can create those DynProperties "by hand".
    Check out the help documentation at
    Manual -> Programming interfaces -> Object model -> RtFunction -> CreateDynProperty
    for a code snippet


    Find in the attachment the mentioned sample project (see 2013-07-18_12-50-47 demo_replace_indices_vba.zip)
    Instead of wild card substitution the way via "replace indices" is shown. This has the advantage that the substitution is then also available for other functions which should use the same target

    It works at folowing
    in the zenon Editor
    - at the linked symbol 1 property is released (invisible button -> station name)
    - so on placing the linked symbol at the screen close the normal substition dialog
    - instead you double-click on the linked element and the integrated symbol wizard appears
    - here you enter the target (i.e. Motor1, Motor2, ... of course the variable structures with that name must exist)
    -> thats all you have to do in the editor (no further functions or so... )

    in the zenon Runtime
    - at this invisible button (at the symbol) also a "LeftClickDown" Macro is linked
    - on clicking this element the configured target (=station name) is read via VBA and then written to a string variable (shown at the top of the screen)
    - on release of the mouse button the linked screen switch function (also linked to this invisible button) is executed
    - this screenswitch function uses "replace indices" -> so it reads the value of the string variable (which value was before written via VBA) and then replaces all variables which matches the substiution criteria


    regards,
    herbert
    Attached Files Attached Files


Similar Threads

  1. Create a function for a trend picture
    By robertf in forum VBA
    Replies: 8
    Last Post: 4th October 2018, 14:33
  2. linking multiple projects
    By talal.mubarak in forum zenon Service Engine Supervisor
    Replies: 1
    Last Post: 10th June 2013, 23:36
  3. Replies: 2
    Last Post: 12th April 2013, 14:40
  4. Zugriff auf die "Create PDF Function"
    By gralex in forum VBA
    Replies: 2
    Last Post: 17th March 2013, 23:17
  5. Execute function in VBA
    By focus in forum VBA
    Replies: 1
    Last Post: 17th January 2012, 15:17

Posting Rules

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