AnsweredAssumed Answered

Macro to link Element Relatives to button in Processbook PIW files.

Question asked by MPCPRO on Oct 16, 2017
Latest reply on Oct 17, 2017 by MPCPRO

Hi!

 

Have been told to make buttons for a list of Element Relatives in a PIW file. So the user can easily switch between elements by using the buttons instead of using the Element Relative Display window in Processbook. I am not quite sure how to do this and was wondering if anyone is able to help.

We had a visual basic code to link buttons to relative displays, but this does not work: (I'm pretty sure its because its made for PDIs and not PIWs and throws out Run-time errors and automation errors when I click on the test button I made. 

errorwindow.PNG

 

Code:

 

Sub GoTo_WellP1()
    ' Open that display
   GoToDisplay "PI Processbook HTM.piw!Single well annulus", "\\Operation Harry\Harry AF Tool\Harry Subsea Wells\P-1"


End Sub








'Function for setting context on given display
Function GoToDisplay(pdi As String, ctxt As String)


    Dim strCurrentPath As String
    Dim PBDisplay As PBObjLib.Display
    
    
    strCurrentPath = Left(ThisDisplay.Path, (InStrRev(ThisDisplay.Path, "\")))
    strCurrentPath = strCurrentPath & pdi
    Set PBDisplay = Application.Displays.Open(strCurrentPath, True)
    Application.ContextHandlers("E").CurrentContext(PBDisplay) = ctxt
    
    Application.DockWindows.Item("Element Relative Display").Visible = False
    
End Function


Private Sub CleanBadData()


    Dim vrDate As Variant
    Dim vrStatus As Variant
    Dim vrVal As Variant
    Dim oVal As Symbol


    For Each oVal In ThisDisplay.Symbols
        If oVal.Type = pbSYMBOLTYPE.pbSymbolValue Then
        
            vrVal = oVal.GetValue(vrDate, vrStatus)
            If vrStatus = 247 Then
                oVal.Visible = False
            Else
                oVal.Visible = True
            
            End If
        End If
    Next oVal


End Sub

 

Anyone able to help ?

Outcomes