Fran

PI ProcessBook Element Relative Display Open

Discussion created by Fran on Jul 30, 2013
Latest reply on Jul 31, 2013 by Marcos Vainer Loeff

Hi,

 

I am trying to do the following i ProcessBook with VBA.

 

In an Element Relative Display, I want to open a distinct pdi depending on the selected node (there is one AF Attribute which contains this information.

 

The problem is that if I try to close the old pdi and assign the correct node in the new display, it works, but the ERD Dock Window on the left, always shows the root hierarchy node.

 

is there any way to decide what the contexthanlder should show? Is it possible opening anew display inthe same windows as with the PB Button (not openm new and close the old) ?

 
Dim CurrentOpenPDI As String
Dim CurrentOpenPDIPath As String

Private Sub svg_Path_DataUpdate()
    Check_Display
End Sub

Private Sub Check_Display()
    Dim vrDate As Variant
    Dim vrStatus As Variant
    Dim NewDisplay As Display
    Dim OldContextPath As String

    ' gets the currently open pdi
    CurrentOpenPDI = ThisDisplay.Path
    SplitPath = Split(CurrentOpenPDI, "\", , vbTextCompare)
    CurrentOpenPDI = SplitPath(UBound(SplitPath))
    CurrentOpenPDIPath = Replace(ThisDisplay.Path, "\" & CurrentOpenPDI, "")
    
    'gets the path selected in the context handler
    Dim AFContext As ContextHandler
    Set AFContext = Application.ContextHandlers("E")
    OldContextPath = AFContext.CurrentContext(ThisDisplay)
    
    'gets from a PBValue with the attribute for the new pdi the pdi to open
    newpdipath = svg_Path.GetValue(vrDate, vrStatus)
    If newpdipath <> "" Then
        SplitPath = Split(newpdipath, "/", , vbTextCompare)
        newpdipath = SplitPath(UBound(SplitPath))
    Else
        GoTo NoDisplayChange
    End If

    'if the new and old display are different, open it
    If newpdipath <> CurrentOpenPDI Then
        Dim NewDisplayPath As String
        Dim OldDisplay As Display
        On Error GoTo NoDisplayChange
        Set OldDisplay = ThisDisplay
        NewDisplayPath = CurrentOpenPDIPath & "\" & newpdipath
        Set NewDisplay = Application.Displays.Open(NewDisplayPath, True)
        AFContext.CurrentContext(NewDisplay) = OldContextPath

        'here is the problem, closing the old pdi, will imply that root node is selected  in the contexthandler
        OldDisplay.Close (False)
    End If
    End
NoDisplayChange:
    Debug.Print ("Display cannot be found " & NewDisplayPath)
End Sub

Thank you in advance for suggestion,

 

Fran

Outcomes