DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert All View Channel References from Numbers to Names

Solved!
Go to solution

I have a number of View Layouts, with many many sheets, resulting in a really lot of plots. But they almost all reference group numbers. As I've evolved my data analysis, my resulting TDM files don't always have the data groups in the same order. I started making plots reference by group name, but somewhere along the way, its almost all reverted back to numbers. I didn't find this come up before (surprisingly). Anyone already have a script for doing this conversion on every view in the current/every sheet of the open View layout?  Still using version 2015, sorry.

 

Would like to know if a conversion button has been implemented in a later release, but I still need a solution for 2015. 🙂

 

--Scott

0 Kudos
Message 1 of 8
(3,298 Views)

So I did discover that if I have the general settings to "group name" and move group 3 into the group 2 position in the Data Portal, it magically changes the references for the groups affected to the names of the groups. That was a bit unexpected. We'll see if it holds.

0 Kudos
Message 2 of 8
(3,285 Views)

To standardize on group name instead of index you have to change DIAdem's general settings (Settings>>DIAdem Settings...) to use  "Group name/Channel" name as address syntax

Capture.PNG

0 Kudos
Message 3 of 8
(3,249 Views)

@StefanR wrote:

To standardize on group name instead of index you have to change DIAdem's general settings (Settings>>DIAdem Settings...) to use  "Group name/Channel" name as address syntax

 


Yes, changing the settings is great for future views (and apparently affecting some existing view when you change group order) but it doesn't solve the problem of fixing existing group numbers to names in existing views.

0 Kudos
Message 4 of 8
(3,245 Views)
Solution
Accepted by sg000

Hi Scott,

 

you find below a script which works as requested. The only restriction is that you need a dataset which matches with the VIEW layout (no check whether a channel exists).

dim iLoop, jLoop, kLoop, oCurrArea, oCurrCurves

for iLoop = 1 to View.Sheets.Count
  for jLoop = 1 to View.Sheets(iLoop).Areas.Count
    set oCurrArea = View.Sheets(iLoop).Areas(jLoop)
    if oCurrArea.DisplayObjType = "CurveChart2D" then
      set oCurrCurves = oCurrArea.DisplayObj.Curves2D
      
      for kLoop = 1 to oCurrCurves.Count
        if oCurrCurves(kLoop).XChannelName <> "" then
          oCurrCurves(kLoop).XChannelName = GetGroupNameAndChnName(oCurrCurves(kLoop).XChannelName)
        end if
        oCurrCurves(kLoop).YChannelName = GetGroupNameAndChnName(oCurrCurves(kLoop).YChannelName)
      next
    
    end if
  next
next

'-------------------------------------------------------------------------------
function GetGroupNameAndChnName(sName)
  GetGroupNameAndChnName = Data.GetChannel(sName).GetReference(eRefTypeNameName)
end function

Greetings

Walter

Message 5 of 8
(3,231 Views)

Quick update to the function to check for whether the channel exists.

Thank you Walter for the main code.

function GetGroupNameAndChnName(sName)
  if CNo(sName) Then
    GetGroupNameAndChnName = Data.GetChannel(sName).GetReference(eRefTypeNameName)
  else
    GetGroupNameAndChnName = sName
  end If
end function
0 Kudos
Message 6 of 8
(3,222 Views)

Hi Scott,

 

In DIAdem 2017 is CNO marked as obsolete. CNO is part of the old script syntax which is replaced by the data-api. With this background, I would recommend the following:

 

function GetGroupNameAndChnName(sName)
  if Data.GetChannels(sName).Count > 0 Then
    GetGroupNameAndChnName = Data.GetChannel(sName).GetReference(eRefTypeNameName)
  else
    GetGroupNameAndChnName = sName
  end If
end function

Greetings

Walter

Message 7 of 8
(3,218 Views)

@Walter_Rick wrote:

Hi Scott,

 

In DIAdem 2017 is CNO marked as obsolete. CNO is part of the old script syntax which is replaced by the data-api. With this background, I would recommend the following:

 

function GetGroupNameAndChnName(sName)
  if Data.GetChannels(sName).Count > 0 Then
    GetGroupNameAndChnName = Data.GetChannel(sName).GetReference(eRefTypeNameName)
  else
    GetGroupNameAndChnName = sName
  end If
end function

Greetings

Walter


Thank you Walter for the clarification.

 

Here's also a version (for anyone else how might want it) that only does the change on the active sheet. I have some layouts I don't want a global change.

dim jLoop, kLoop, oCurrArea, oCurrCurves

  for jLoop = 1 to View.ActiveSheet.Areas.Count
    set oCurrArea = View.ActiveSheet.Areas(jLoop)
    if oCurrArea.DisplayObjType = "CurveChart2D" then
      set oCurrCurves = oCurrArea.DisplayObj.Curves2D
      
      for kLoop = 1 to oCurrCurves.Count
        if oCurrCurves(kLoop).XChannelName <> "" then
          oCurrCurves(kLoop).XChannelName = GetGroupNameAndChnName(oCurrCurves(kLoop).XChannelName)
        end if
        oCurrCurves(kLoop).YChannelName = GetGroupNameAndChnName(oCurrCurves(kLoop).YChannelName)
      next
    
    end if
  next

'-------------------------------------------------------------------------------
function GetGroupNameAndChnName(sName)
  if Data.GetChannels(sName).Count > 0 Then
    GetGroupNameAndChnName = Data.GetChannel(sName).GetReference(eRefTypeNameName)
  else
    GetGroupNameAndChnName = sName
  end If
end function

 

0 Kudos
Message 8 of 8
(3,216 Views)