05-20-2021 12:31 PM
Hi,
When I want to load some channels from file in a DIAdem script, I am used to writing:
dd.DataFileLoadSel(MyFile, "TDM", "*/MyChan1 | */XX | */t10", "LoadImmediately|ChnXYRelation")
It works great, only the selected channels (MyChan1, XX, and t10 in the example above) are loaded, and it saves me a lot of time (less than a second vs 1 minute), since I'm often dealing with files with hundred of channels, most of which are not necessary for the tests I want to perform.
Now I want to automatise it through SystemLink; I've created a Data Index, and my acquisitions are stored there.
Of course I can load the acquisitions as follows:
def On_Run_AnalysisProcedure(oContext):
dd = DIAdem.Application
dd.ApplicationSetLocale("english")
# Please enter your code sequences here.
# --------------------------------------
for link in oContext.DataLinks:
elements = dd.Navigator.LoadData(link)
oContext.LogWarning("Loaded elements: "+str(elements.Count))
Unfortunately, I haven't found a way to selectively load channels. I saw a procedure called dd.Navigator.LoadChannelsByName that was promising, but I'm not able to make it work.
Is there a way to selectively load channels from a Data Index structure? If not, any workaround?
Remarks. I'm working with DIAdem 2020SP1 and use Python scripts, but I can also go with VBA if requested.
Solved! Go to Solution.
05-21-2021 03:37 PM - edited 05-21-2021 03:53 PM
Hi panta,
This is not as elegant as the DataFileLoadSel() command, but it is an approach that will avoid delving into DataLink xml parsing:
# -- Register Load the full data file to DIAdem Data Portal
dd.Navigator.LoadData(oContext.DataLinks.Item(1), "Register|ChnXYRelation")
# -- Expand the selected list of channels
ExpandChannels = dd.Data.CreateElementList()
ExpandChannels.AddElementList(dd.Data.GetChannels("*/MyChan1"))
ExpandChannels.AddElementList(dd.Data.GetChannels("*/XX"))
ExpandChannels.AddElementList(dd.Data.GetChannels("*/t10"))
dd.ChnValExpand(ExpandChannels)
# -- Delete any channels that are still registered
DeleteChannels = dd.Data.CreateElementList()
for Group in dd.Data.Root.ChannelGroups:
for Channel in Group.Channels:
if Channel.Properties("status").Value == "readonly":
DeleteChannels.Add(Channel)
dd.Data.Remove(DeleteChannels)
Brad Turpin
Principal Technical Support Engineer
NI
05-21-2021 03:48 PM - edited 05-21-2021 03:53 PM
Hi panta,
If you're willing to brave the xml parsing of the DataLink, you can spare yourself the gymnastics in the Data Portal afterwards. Also, this opens up the entire set of loading options you're used to in a regular DIAdem script:
import xml.etree.ElementTree as ET
for DataLink in oContext.DataLinks:
root = ET.fromstring(DataLink)
nodes = root.findall(r"./addresslist/basepoint/usistore/param")
for item in nodes:
param_node = ET.fromstring("<?xml version='1.0' encoding='UTF-16' standalone='no'?><param>" + item.text + "</param>")
file_node = param_node.find(r"./filename")
file_path = file_node.text
exit # only analyze the first DataLink in the list
# -- Load the selected channels to DIAdem Data Portal
dd.DataFileLoadSel(file_path, "TDM", "*/MyChan1 | */XX | */t10", "LoadImmediately|ChnXYRelation")
Brad Turpin
Principal Technical Support Engineer
NI
05-23-2021 11:00 AM - edited 05-23-2021 11:01 AM
Hi Brad,
Thank you vey much for both your responses!
By the way, on Friday I was figuring out something similar to your second reply.
I realised that when I write
for link in oContext.DataLinks:
link is actually a string that among other things contains the whole path, and came up with some string parsing. My solution seems to be working, but yours look more robust - I feel like mine could only work on some particular cases.
I'll give your suggestions a try!