9 of 9 people found this helpful
Well, it's possible to programmatically add VBA code using a simple VBA script such as the following:
Dim codelessDisplay As Display
Dim cVBE As VBE
Dim cCodePane As CodePane
Dim cFnString As String
Dim cComponent As VBComponent
Set codelessDisplay = Application.Displays.Open("C:\Users\John\Documents\NeedsCode.PDI", True)
Set cVBE = Application.VBE
Set cComponent = cVBE.SelectedVBComponent
Set cCodePane = cComponent.CodeModule.CodePane
cFnString = "Private Sub Display_BeforeClose(bCancelDefault As Boolean)"
cFnString = cFnString & vbCrLf & vbCrLf
cFnString = cFnString & "ThisDisplay.Modified = false" & vbCrLf & vbCrLf
cFnString = cFnString & "End Sub"
Set codelessDisplay = Nothing
Set cVBE = Nothing
Set cComponent = Nothing
Set cCodePane = Nothing
You will need to add a reference to 'Microsoft Visual Basic for Applications Extensibility'. I've used this method to programmatically create new ProcessBook displays that have some simple VBA code behind them. The above example has been modified to open an existing display, add some code to it, save and then close it. You could wrap this into a loop that iterates through your collection of ProcessBook displays to peform this process.
Thank you John
Great response John! Very helpful
Tried to built a PDI file for your usecase.
Let me know if that work for you.
Create a Text file with the code you need to insert.
1 ) In the Input folder path put the folder path where all .PDI files are located.
2) In the Code File Path put the text file path which has the code to be inserted in PDI files.
InsertVBAinPDI-V2.pdi.zip 15.6 KB
Kindly guide me how can we insert VBA Script into Different/all Displays inside a .PIW file
1 of 1 people found this helpful
Refer this link White Paper - A Few PI ProcessBook VBA Tips
The Last part has what you need ,ie, looping all the displays in a PIW file.
Thanks for your support, I have implemented the same code & its working but new code is not being inserted in the PIW file.
Kindly check my code & feedback if there is any mistake.
InsertVBAinPIW.pdi.zip 11.1 KB
Waiting for your response
is there a way to assign layer to symbols pragmatically? i can create layer but do not see how to assign created layer to tag or any symbol.
Yes, although it should be noted that symbols are added to layers, and not layers added to symbols. Have a look at the Layers class and the LayerSymbols Collection topics in the PI ProcessBook Programmer Reference Guide (available through the Help menu in ProcessBook). This is a sub-branch of the Displays Class topic in the Contents view. You add a symbol to a layer using
Hope this helps.