YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

How to refer to a tagname in VBA for processbook Options · View
Madhu
#1 Posted : Sunday, February 21, 2010 10:40:07 AM
Rank: Newbie
Groups: Member

Joined: 2/12/2010
Posts: 3
Location: qatar
Hai I am novice to PI and VBA
I am trying to
(1) rerange the scale of pens for a particular tag displayed in more than one adhoc trend
(2)Change to same colour of the pens for a particular tag in all adhoc trends thru VBA
for example the tag name in PI is 01ABCDE.pv

I went up to setting colurs for trend elements in the VBA code, put stuck without knowing how to tell teh code to distinguish which element to be formatted.
Sponsor  
 
Madhu
#2 Posted : Friday, February 26, 2010 6:29:37 PM
Rank: Newbie
Groups: Member

Joined: 2/12/2010
Posts: 3
Location: qatar
Helllppppppppp.

I am able to refer each of the trend pen in the trend display by using number of the trend element.

But using the tagname to set some formats is the issue.
Pls teach me how to use the tag name to set formats.
I would like to set buttons to format and rerange all the trend elements based on a value of a particular tag name.

any help is greatly appreciated
RJK Solutions
#3 Posted : Friday, February 26, 2010 9:11:38 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 409
Location: Cheshire, United Kingdom.
Hi Madhu,

Welcome to the forum!
Apologies, for some reason I completely missed your original post.

I presume so far you have got to the point of getting/setting the format of a Trend using the "TrendFormat" object.
In order to refer to the Elements, you can use the "pbTrendELEMENT" enumeration, e.g. pbTrendELEMENT.pbPen1. For each trace on your trend, the trace index refers to the pen number - the 1st trace = pbPen1 etc. What you need to do is parse the traces on the trend and set the format accordingly.

Below is some example code where I look for the PI tag "sinusoid" and then change the format of that particular trace.

Code:

Sub ParseTrend(ByVal TheTrend As Trend)

' If there are no traces, don't parse the Trend.
If TheTrend.TraceCount = 0 Then Exit Sub

Dim TF As TrendFormat
Set TF = TheTrend.GetFormat()
    Dim iTrace As Integer, sTag As String
    For iTrace = 1 To TheTrend.TraceCount
       
        sTag = TheTrend.GetTagName(iTrace)
       
        ' Check to see if "\" is present...
        ' If so it is a PI tag...
        ' Otherwise a dataset (AF or PI Calc)
        If InStr(1, sTag, "\") > 0 Then
            sTag = Trim(Split(sTag, "\")(3))
            If LCase(Trim(sTag)) = "sinusoid" Then
                Dim iElementEnum As Integer
                Select Case iTrace
                    Case 1: iElementEnum = pbTrendELEMENT.pbPen1
                    Case 2: iElementEnum = pbTrendELEMENT.pbPen2
                    Case 3: iElementEnum = pbTrendELEMENT.pbPen3
                    Case 4: iElementEnum = pbTrendELEMENT.pbPen4
                    Case 5: iElementEnum = pbTrendELEMENT.pbPen5
                    '... etc
                    'Be careful, pbPen8 = index 12, pbPen 9 = index 17!!!
                    Case Else: iElementEnum = -1
                End Select
               
                If Not iElementEnum = -1 Then
                    TF.Elements(iElementEnum).LineStyle = pbLSolid
                    TF.Elements(iElementEnum).LineWidth = pbMedium
                    TF.Elements(iElementEnum).Color = pbRed
                End If
            End If
        End If
       
    Next iTrace
   
    Call TheTrend.SetFormat(TF)
Set TF = Nothing

End Sub


Hope this helps!

Rhys


OSIsoft PI System Specialists
PI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!


Madhu
#4 Posted : Thursday, March 25, 2010 11:09:15 AM
Rank: Newbie
Groups: Member

Joined: 2/12/2010
Posts: 3
Location: qatar
Hi Rhys
Thanks for the code.

I had few difficulties running the code because of my lack of basic knowledge.
I pasted the code inthe module but when trying to run could not see the macro.

Somehow now I am able to see the macro listed when running I got a bug reported at
Set TF = Thetrend.GetFormat()
I thought "Thetrend" was to be replaced with suitable name for my trend which itself is a collection of adhoc trends
I found it was not right to do since the Debug stopped repeatedly stopped at the same line despite trying different trend names.

I am back to the forum looking for your kind help.

RJK Solutions
#5 Posted : Monday, March 29, 2010 12:03:25 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 409
Location: Cheshire, United Kingdom.
Hi Madhu,

Change the scope of the Sub routine to Public...but..you won't see the routine in the Macros window because it accepts one parameter as input. You need to create an additional routine with no parameters.
To assign the correct Trend symbol, when you call the routine you need give it the correct name of the Trend, e.g.

Code:

Public Sub TestTrend()
  Call ParseTrend(ThisDisplay.Symbols("MyTrendName"))
End Sub


You would then see "TestTrend" as an available macro to run.


OSIsoft PI System Specialists
PI consultancy on PI Systems, PISDK, AFSDK, OLEDB etc and PI custom developments. Well pretty much anything to do with PI!


Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.