How to Add PI Points to an XY-Plot in PI ProcessBook from .NET Code
Learn how to dynamically add PI Points or AF Attributes to an existing XY-Plot in PI ProcessBook using .NET and the AF SDK, leveraging the XYPlot .NET library for seamless integration.
Roshan Soni
Integrating PI Points into XY-Plots in PI ProcessBook Using .NET and AF SDK
One common task for engineers and developers working with OSIsoft PI ProcessBook is dynamically adding PI Points or AF Attributes to an existing XY-Plot. Traditionally, this operation is straightforward in ProcessBook VBA, but what if you’re developing a PI ProcessBook add-in using .NET (VB or C#) and the AF SDK? Let’s walk through how this can be accomplished.
The Challenge
Suppose you want to perform, from .NET VB code, what you could perform in VBA:
Dim aDefinition As XYDefinition
Set aDefinition = ThisDisplay.SelectedSymbols.Item(1).GetDefinition
aDefinition.Tags.Add(sTagName)
ThisDisplay.SelectedSymbols.Item(1).SetDefinition aDefinition
Set aDefinition = Nothing
How do you achieve this in .NET with ProcessBook add-in templates?
Understanding the Approach
Although AF SDK is powerful for managing PI Systems and Asset Framework data structures, the ProcessBook display manipulation (adding tags to an XY Plot, for example) is still governed by the libraries and COM interfaces provided by ProcessBook itself. Therefore, the approach is:
- Reference the XYPlot .NET Library: This provides you with the .NET objects needed to interact with and modify XY Plots within your ProcessBook add-in.
- Access the Display and Selected Symbol: From .NET code, obtain the active display and the selected XY-Plot symbol.
- Modify the XYDefinition: Get the symbol’s definition, add your desired PI Point or AF Attribute (the same way as in VBA), and set the modified definition back.
Practical Implementation Steps
Let’s say you’re using the OSIsoft PI ProcessBook add-in .NET VB template. Here’s how to add a PI Point (or AF Attribute) to an XY-Plot:
1. Add the XYPlot .NET Library
Reference XYPlotLib.dll (or the equivalent library shipped with ProcessBook) in your .NET project. This exposes the needed classes and interfaces.
2. Use the Familiar Methodology
Your code in .NET VB will look remarkably similar to VBA:
Imports PBObjLib
Imports XYPlotLib
' Inside your add-in code
Dim display As Display = application.ActiveDisplay
Dim xySymbol As Symbol = display.SelectedSymbols.Item(1)
Dim xyDef As XYPlotDefinition = xySymbol.GetDefinition()
' Add the tag or attribute
xyDef.Tags.Add(sTagName)
' Apply the modified definition
xySymbol.SetDefinition(xyDef)
You may need to cast or convert the symbol and definition types based on your application structure.
3. Notes
- Ensure you handle object releases and COM references properly to avoid locking symbols or causing memory leaks.
- Error checking (e.g., verifying
SelectedSymbolscount, type checking the symbol) is important for robust add-ins. - You can add both PI Tag names and AF Attribute paths as needed.
Conclusion
By referencing the XYPlot .NET library, you can manipulate XY-Plots within PI ProcessBook from a .NET add-in using virtually the same logic as VBA. This approach allows you to build robust, user-friendly ProcessBook extensions that dynamically modify plots based on user input or automated criteria.
If you have old VBA logic you want to port, this interoperability with .NET makes it possible without major rewrites—streamlining your transition to modern add-in development.
Tags
About Roshan Soni
Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.
No comments yet
Be the first to share your thoughts on this article.
Related Articles
Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead
A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.
Roshan Soni
Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB
Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.
Roshan Soni
Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?
Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.
Roshan Soni