With the help of this forum and other examples from OSI I was able to get the autorange to work just how I wanted. My programming is a probably messy, but it seems to work. Here goes:
The first section of code is used to maximize the application window and display window. Also, the setviewport method sets the viewport based on the width. If the specified height does not match the necessary height based on the screen resolution, the height is adjusted so the symbols are not skewed. I wanted to set the height of the viewport as I built my display from left-to-right and I wanted to maximize the size of the symbols. All of this wouldn't be necessary if the display was only used on monitors with the same resolution setting, but I do not have that luxury. (one other comment, I noticed that when you try to execute the Application.Maximize and ThisDisplay.Maximize from the Display_Open sub it glitches up and the application window shows to be maximized, but isn't maximized. BUT, if you do this action in a different sub and Call it using Display_Open it works great... I'm not really sure, maybe one of the programming guru's could shed some light...)
Private Sub Display_Open()
Call MaximizeDisplay
End Sub
Sub MaximizeDisplay()
Application.Maximize
ThisDisplay.Maximize
ThisDisplay.SetViewPort 14999, -15000, 1940, 4144
h1 = 1940
h2 = ThisDisplay.ViewHeight
If h2 = 1940 Then
Exit Sub
Else
For i = 1 To 1000
'h1 = ThisDisplay.ViewHeight
ThisDisplay.SetViewPort 14999, -15000, 1940, 4144 - Change
h2 = ThisDisplay.ViewHeight
Change = h2 - 1940 / 2
Next i
End If
End Sub
All of our controllers are set up with a similar naming system. TAGNAME.PV, TAGNAME.SP, etc. So I built buttons that matched the tagname for the controller that I wanted to trend. This gave me the ability to build a single trend and then just insert the traces for the controller. I made use of Rhys' GetSummary function that I found in the forum (couldn't have done it without this - THANKS!). Using the function, I get the min and max scale for the PV and SP and I set up the trend named "Controller_Trend" with trace 3 and 4 (.OP and .MODE) as autorange on both min and max. I also did a simple automation of the location of the trend in the viewport, this way when the trend is opened it is visible in the active viewport. Like I said, messy, but functional. Thanks to all who have posted thier ideas and solutions on this board, it was critical to this success (at least I call it a success..).
Public Sub AutoTrend()
Dim Trend As Object
Dim Button As Object
Dim PVtagname As String
Dim SPtagname As String
Dim OPtagname As String
Dim MODEtagname As String
Dim Max As Variant
Dim Min As Variant
Dim SearchChar As String
Dim MyPos As Integer
Dim Name As String
Set TheButton = SelectedSymbols.Item(ThisDisplay.SelectedSymbols.Count)
ButtonName = TheButton.Name
SearchChar = "_"
MyPos = InStr(1, ButtonName, SearchChar, vbTextCompare)
ParseName = Left$(ButtonName, MyPos - 1)
PVtagname = ParseName & ".PV"
SPtagname = ParseName & ".SP"
OPtagname = ParseName & ".OP"
MODEtagname = ParseName & ".MODE"
TrendName = "Controller_Trend"
Set Trend = Symbols.Item(TrendName)
Set Button = Symbols.Item(ButtonName)
If Trend.Visible = True Then
With Trend
.Visible = False
.Height = Button.Height
.Width = Button.Width
.Top = 13135
.Left = -14966
End With
Else:
Call MaxMinCalc(Min, Max, PVtagname, SPtagname)
Trend.SetTagName 1, PVtagname
Trend.SetTagName 2, SPtagname
Trend.SetTagName 3, OPtagname
Trend.SetTagName 4, MODEtagname
Trend.CurrentTrace = 1
Trend.SetTraceScale Min, Max
Trend.CurrentTrace = 2
Trend.SetTraceScale Min, Max
Call PositionTrend(Trend, Button)
Trend.SetTimeRange "*-1day", "*"
End If
End Sub
Sub MaxMinCalc(Min As Variant, Max As Variant, PVtagname As String, SPtagname As String)
Max1 = GetSummary(PISDK.Servers("appg-PIHOUT").PIPoints(PVtagname), "*-24h", "*", astMaximum)
Max2 = GetSummary(PISDK.Servers("appg-PIHOUT").PIPoints(SPtagname), "*-24h", "*", astMaximum)
If Max1 > Max2 Then
Max = Max1
Else: Max = Max2
End If
Min1 = GetSummary(PISDK.Servers("appg-PIHOUT").PIPoints(PVtagname), "*-24h", "*", astMinimum)
Min2 = GetSummary(PISDK.Servers("appg-PIHOUT").PIPoints(SPtagname), "*-24h", "*", astMinimum)
If Min1 < Min2 Then
Min = Min1
Else: Min = Min2
End If
End Sub