From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
08-20-2015 10:16 PM
Hi Guys,
I want to write a script to delete data values across all my channels. I have 3 groups of data in my data portal, each containing 4 channels. My data sets are about 40,000 long.
Let's say that I wanted to delete the last 30,000 values of all the channels in each group. What would my script look like to perform this operation?
Thanks in advance!
08-21-2015 06:52 AM
I found the following script to work very well to delete data.
But instead of specifying the quantity of data to delete within the channel strings, the data is trimmed down to an interval of time (trimmed to 0-.3 s in the script).
This script only works for one channel group. How can I modify this script to work for all groups? Lets say 3 groups.
Thanks!
Script:
__________________________________________________________________
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim Group, XChannel, P0, P1, P2, PN, Channels, Starttime, Endtime
If Not ItemInfoGet("sPathDocuments") Then
Call GlobalDim("sPathDocuments")
Call GlobalDim("sPathData")
Call GlobalDim("sMyText")
Call GlobalDim("iMyIntVal")
Call GlobalDim("dMyRealVal")
End If
sPathDocuments = CurrentScriptPath
sPathData = CurrentScriptPath & "..\Data\"
Starttime = 0
Endtime = .3
Chnvalexpand("[1]/[1]")
Set Group = Data.Root.ChannelGroups(1)
Set XChannel = Group.Channels(1)
P0 = 1
P1 = PNo(XChannel, Starttime)
P2 = PNo(XChannel, Endtime)
PN = XChannel.Size
Set Channels = Group.Channels
IF PN-P2 > 0 THEN Call DataBlDel(Channels, P2+1, PN-P2)
IF P1-P0 > 0 THEN Call DataBlDel(Channels, P0, P1-P0)
_________________________________________________________________
08-21-2015 06:53 AM
I found the following script to work very well to delete data.
But instead of specifying the quantity of data to delete within the channel strings, the data is trimmed down to an interval of time (trimmed to 0-.3 s in the script).
This script only works for one channel group. How can I modify this script to work for all groups? Lets say 3 groups.
Thanks!
Script:
__________________________________________________________________
Option Explicit 'Forces the explicit declaration of all the variables in a script.
Dim Group, XChannel, P0, P1, P2, PN, Channels, Starttime, Endtime
If Not ItemInfoGet("sPathDocuments") Then
Call GlobalDim("sPathDocuments")
Call GlobalDim("sPathData")
Call GlobalDim("sMyText")
Call GlobalDim("iMyIntVal")
Call GlobalDim("dMyRealVal")
End If
sPathDocuments = CurrentScriptPath
sPathData = CurrentScriptPath & "..\Data\"
Starttime = 0
Endtime = .3
Chnvalexpand("[1]/[1]")
Set Group = Data.Root.ChannelGroups(1)
Set XChannel = Group.Channels(1)
P0 = 1
P1 = PNo(XChannel, Starttime)
P2 = PNo(XChannel, Endtime)
PN = XChannel.Size
Set Channels = Group.Channels
IF PN-P2 > 0 THEN Call DataBlDel(Channels, P2+1, PN-P2)
IF P1-P0 > 0 THEN Call DataBlDel(Channels, P0, P1-P0)
_________________________________________________________________
08-21-2015 08:03 AM
You could Create a For loop to go through all of your desired groups
08-21-2015 08:43 AM
Hi rvilla,
You can create you own custom collection of Channels to pass to the DataBlDel() command, from as many groups as you want. You can also reference the channels for each group by index, by name, or you can just take all of them in a loop.
Set Channels = Data.CreateElementList() Set Group = Data.Root.ChannelGroups(1) Call Channels.Add(Group.Channels(1)) Call Channels.Add(Group.Channels(2)) Set Group = Data.Root.ChannelGroups("GroupName2") Call Channels.Add(Group.Channels("Time")) Call Channels.Add(Group.Channels("Data"))
Set Group = Data.Root.ChannelGroups(3)
FOR Each Channel In Group.Channels
Call Channels.Add(Channel)
NEXT ' Channel IF PN-P2 > 0 THEN Call DataBlDel(Channels, P2+1, PN-P2) IF P1-P0 > 0 THEN Call DataBlDel(Channels, P0, P1-P0)
The script you found turns the desired time interval into a row interval (P1 to P2). If you already know the row interval you want to retain, you can skip the PNo() commands.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
08-23-2015 05:58 AM
Thanks for the reply Brad,
What would my loop look like if I wanted to use the loop method?
08-23-2015 04:50 PM
Hi rvilla,
What sort of loop do you want? I already showed you above how to loop over all the channels of a specific (3) group. If you want to loop over all channels of all groups, it would look like this:
FOR Each Group In Data.Root.ChannelGroups FOR Each Channel In Group.Channels Call Channels.Add(Channel) NEXT ' Channel NEXT ' Group
Brad Turpin
DIAdem Product Support Engineer
National Instruments
08-26-2015 04:47 PM
Thank you!