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.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Deleting data across all channels

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!

0 Kudos
Message 1 of 8
(5,471 Views)

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! Smiley Happy

 

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)

_________________________________________________________________

 

0 Kudos
Message 2 of 8
(5,397 Views)

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! Smiley Happy

 

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)

_________________________________________________________________

 

0 Kudos
Message 3 of 8
(5,397 Views)

You could Create a For loop to go through all of your desired groups

0 Kudos
Message 4 of 8
(5,366 Views)

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

0 Kudos
Message 5 of 8
(5,356 Views)

Thanks for the reply Brad,

 

What would my loop look like if I wanted to use the loop method?

0 Kudos
Message 6 of 8
(5,323 Views)

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

Message 7 of 8
(5,281 Views)

Thank you!

0 Kudos
Message 8 of 8
(5,206 Views)