DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Change the labelname for each channel in a channelgroup in the actual legend with script

Hello,

 

I have several channelgroups of data.

In each channelgroup there are several channels.

The channels have the same names as the other channelgroups.

I want to distinguish between them.

 

My first thought was to change the names of them and I did. 

The code might not be the most effective but it works.

 

 

Spoiler
Option Explicit  'Forces the explicit declaration of all the variables in a script.



Dim Battery1,Battery2, Battery3, Battery4,Battery5,Battery6, n1,n2,n3,n4,n5,n6

'Set which name that should be after each data value (data channel)

Battery1 = "- S/N 1"

Battery2 = "- S/N 2"

Battery3 = "- S/N 3"

Battery4 = "- S/N 4"

Battery5 = "- S/N 5"

Battery6 = "- S/N 6"





' Renames the channels in the channelgroup

for n1 = 1 to Data.Root.ChannelGroups(1).Channels.Count step 1  ' Sets n1 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(1).Channels(n1).Name = Data.Root.ChannelGroups(1).Channels(n1).Name + Battery1 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery1 string.

next

for n2 = 1 to Data.Root.ChannelGroups(3).Channels.Count step 1  ' Sets n2 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(3).Channels(n2).Name = Data.Root.ChannelGroups(3).Channels(n2).Name + Battery2 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery2 string.

next

for n3 = 1 to Data.Root.ChannelGroups(5).Channels.Count step 1  ' Sets n3 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(5).Channels(n3).Name = Data.Root.ChannelGroups(5).Channels(n3).Name + Battery3 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery3 string.

next

for n4 = 1 to Data.Root.ChannelGroups(7).Channels.Count step 1  ' Sets n4 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(7).Channels(n4).Name = Data.Root.ChannelGroups(7).Channels(n4).Name + Battery4 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery4 string.

next

for n5 = 1 to Data.Root.ChannelGroups(9).Channels.Count step 1  ' Sets n5 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(9).Channels(n5).Name = Data.Root.ChannelGroups(9).Channels(n5).Name + Battery5 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery5 string.

next

for n6 = 1 to Data.Root.ChannelGroups(11).Channels.Count step 1  ' Sets n6 to the number of channels in Channelgroup1

Data.Root.ChannelGroups(11).Channels(n6).Name = Data.Root.ChannelGroups(11).Channels(n6).Name + Battery6 ' Change name of all channels in ChannelGroup 1 n1 channel by adding Battery6 string.

next

MsgBox("Renaming Complete")

 

However

 

In the REPORT section I have several sheets of premade graphs (2DAxis), were all the channels plotted and compared,

 

Each graph are set to the specific channel name that have been set in the script.

 

But If I want to change the name in the future:

e.g 

Battery1 = "- S/N 1"

to

Battery1 = "- S/N 13"

Then it won't work in the REPORT section as its not the same name anymore and will not link correctly.

 

Therefore:

- I think I need to change the labelname for each channel in a channelgroup in the actual legend.

or a less preferable option

- The graphs should load the channels based on its position rather than the name itself.
(This will make complications when more channels are added in between and not at the end of the channelgroup)

Or maybe theres better options.

 

 

The closest I found to a solution was this:

https://forums.ni.com/t5/DIAdem/Controlling-Report-Legend-with-Script/m-p/3744474?profile.language=e...

 

Report.Sheets(3).Objects("2DAxis1").Curves2D.RelatedLegendText(1) = "1"

But I receive the error code, "Object doesn't support this property or method."

 

By Labels I mean these, they can also be set to different modes.

image.png

 

Thank you.

 

/Niflheim

 

 

 

0 Kudos
Message 1 of 2
(2,016 Views)

/Niflheim

 

Just some ideas for you,

 

I usually try to make a reduced number of report TDR files, and then copy them as needed to for different files.  Keeps down on the maintenance time latter, as have much fewer reports to alter.

 

To accomplish this, Below are two functions that will change the group names for chart objects, and also a function to change the name for charts in a tdr sheet

 

To append a report tdr I use the report.AppendLayout command.

 

Also when need to display text that in chart or report that is unique and not like channel or group names,   I would make a custom property for the channel, and put in that the text you want to display. Then it will travel with the group and the report can reference it when ever needed.

 

Paul

 

 

 

 

 

' Changes the groups called in in all Tables for the channels called out in Sheet
'
public sub ChangeGroupAllTables (sSheetName,sFromGroupName, sToGroupName)
dim x, i
dim sChType,iColType
dim oChan,sChan
dim oRptSht, oRptShts
dim oRptObj,oRptObjs
dim oTableSettings
dim oMyIndexSettings
dim dTableHeight,dHeaderTablePct
dim sOutput
dim aTemp
dim sGroup

dim sNewChanName
dim dX2,dY2
dim dUpperLeftX1,dUpperLeftY1
dim iNumDataRows ,dUpperLeftWidth

set oRptShts = report.Sheets
sOutput = ""

for each oRptSht in oRptShts
if oRptSht.Name= sSheetName then
'msgbox(oRptSht.Name )
set oRptObjs = oRptSht.Objects
for each oRptObj in oRptObjs
if oRptObj.ObjectType =eReportObject2DTable then

for x = 1 to oRptObj.Columns.Count
iColType = oRptObj.Columns.Item(x).Type
if iColType = e2DTableColumnChannel then
sChan = oRptObj.Columns.Item(x).Channel.reference
aTemp = split (sChan,"/")
sGroup = aTemp(0)
if sGroup = sFromGroupName then
sNewChanName = sToGroupName&"/"&aTemp(1)
oRptObj.Columns.Item(x).Channel.reference = sNewChanName
' msgbox(oRptObj.Columns.Item(x).Channel.reference)
end if
end if
next

end if ' desired report type
next 'oRptObj in oRptObjs
end if ' desired sheet
next 'oRptSht in oRptShts
end sub

' Changes the groups called in in all Chart for the channels called out in Sheet
'
public sub ChangeGroupAllCharts (sSheetName,sFromGroupName, sToGroupName)
dim x, i
dim sChType,iColType
dim oChan,sChan
dim oRptSht,oRptShts
dim oRptObj,oRptObjs
dim oTableSettings
dim oMyIndexSettings
dim dTableHeight,dHeaderTablePct
dim sOutput
dim aTemp
dim sGroup
dim sOldChanName
dim sNewChanName
dim dX2,dY2
dim dUpperLeftX1,dUpperLeftY1
dim iNumDataRows ,dUpperLeftWidth
Dim oMy2DAxisSystem, oMyCurve, oMyPos, oMyShape

set oRptShts = report.Sheets
sOutput = ""

'------------------- ChannelReference ------------------------------

for each oRptSht in oRptShts
if oRptSht.Name= sSheetName then

set oRptObjs = oRptSht.Objects
for each oRptObj in oRptObjs
if oRptObj.ObjectType = eReportObject2DAxisSystem then

for x = 1 to oRptObj.Curves2D.Count

'msgbox(oRptObj.Curves2D.Item(1).Shape.XChannel.Reference)
if oRptObj.Curves2D.Item(x).ShapeType = e2DShapeLine _
or oRptObj.Curves2D.Item(x).ShapeType = e2DShapeLineAndPoints _
or oRptObj.Curves2D.Item(x).ShapeType = e2DShapeBars then

sOldChanName = oRptObj.Curves2D.Item(x).Shape.XChannel.Reference
'msgbox(sOldChanName)
aTemp = split (sOldChanName ,"/")
sGroup = aTemp(0)
if sFromGroupName = sGroup then
oRptObj.Curves2D.Item(x).Shape.XChannel.Reference = sToGroupName&"/"&aTemp(1)
end if

sOldChanName =oRptObj.Curves2D.Item(x).Shape.YChannel.Reference
'msgbox(sOldChanName)
aTemp = split (sOldChanName ,"/")
sGroup = aTemp(0)
if sFromGroupName = sGroup then
oRptObj.Curves2D.Item(x).Shape.YChannel.Reference = sToGroupName&"/"&aTemp(1)
end if
end if
next
end if
next 'oRptObj in oRptObjs
end if ' desired sheet
next 'oRptSht in oRptShts
end sub

0 Kudos
Message 2 of 2
(1,992 Views)