04-28-2021 06:31 PM
Hello,
I'm trying to streamline my scripts and this is the last manual thing that I have to do. I have some data go through an event search and end up with a data channel that is zero's or one's. Then I would multiply that by the data I'm interested in looking at. Is there a way that I can split up that data the final data into as many channels as there is distinct blocks of data?
For example in the picture below there are 3 distinct blocks of data. The top graph is the event search and the bottom one is the data after multiplication with the event search. I would like to run a script that breaks it up into three different channels.
I'm trying to figure out a DataBlCopy command inside a loop, but I don't know how to do that. I also could maybe use ChnSplitAtValue inside a loop?
Thanks,
Tyler
Solved! Go to Solution.
04-30-2021 12:55 PM
I got a purely hardcoded script put together. This will be good enough for most of my testing at the moment. I couldn't figure out how to get this into a dynamic for... loop. If anyone has any additional information for getting the for... loop to work that would be appreciated.
Dim Mark1, Mark2, Mark3, Mark4, Mark5, Mark6, Mark7, Mark8, Mark9, Mark10, Mark11, Mark12
Mark1 = ChnFind("Ch(""EventKPH"")>0",0)
Mark2 = ChnFind("Ch(""EventKPH"")=0",Mark1)
Mark3 = ChnFind("Ch(""EventKPH"")>0",Mark2)
Mark4 = ChnFind("Ch(""EventKPH"")=0",Mark3)
Mark5 = ChnFind("Ch(""EventKPH"")>0",Mark4)
Mark6 = ChnFind("Ch(""EventKPH"")=0",Mark5)
Mark7 = ChnFind("Ch(""EventKPH"")>0",Mark6)
Mark8 = ChnFind("Ch(""EventKPH"")=0",Mark7)
Mark9 = ChnFind("Ch(""EventKPH"")>0",Mark8)
Mark10 = ChnFind("Ch(""EventKPH"")=0",Mark9)
Mark11 = ChnFind("Ch(""EventKPH"")>0",Mark10)
Mark12 = ChnFind("Ch(""EventKPH"")=0",Mark11)
Call DataBlClpCopy("[1]/Integrated", Mark1, Mark2-Mark1)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark3, Mark4-Mark3)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark5, Mark6-Mark5)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark7, Mark8-Mark7)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark9, Mark10-Mark9)
Call ChnClpPaste(1, True)
Call DataBlClpCopy("[1]/Integrated", Mark11, Mark12-Mark11)
Call ChnClpPaste(1, True)
05-05-2021 08:09 AM
Please have also a look at the Event functions in ANALYSIS and possibly at the example "EventDetection.VBS"
Greetings
Walter
05-06-2021 09:49 AM
Thanks Walter. Unless there is more functionality in the "Event Search" function that I'm missing, that is how I came up with the segmented runs. Before that there was data in between the distinct blocks of data.
I'm working on a for...loop right now that isn't quite working, but I'll try posting it later today to see if someone can get it all the way there.
Thanks,
Tyler
05-06-2021 11:41 AM - edited 05-06-2021 11:43 AM
Hey TW_Test,
Aside from the looping question, I would recommend that you switch away from the clipboard commands you probably Script Recorded:
Call DataBlClpCopy("[1]/Integrated", Mark1, Mark2-Mark1)
Call ChnClpPaste(1, True)
The DataBlClpCopy() command formats all the data values you're copying as strings and saves them to the Windows clipboard, then the ChnClpPaste() command unformats them from those clipboard strings back into DBL values. It's a completely unnecessary pair of steps that will slow execution.
You can accomplish the same thing with one traditional DIAdem command:
Call DataBlCopy("[1]/Integrated", Mark1, Mark2-Mark1, NewChannel)
You can also use built in methods of the Channel object to do the same thing:
Set Channel = Data.Root.ChannelGroups(1).Channels("Integrated")
Values = Channel.GetValuesBlock(Mark1, Mark2-Mark1)
Call NewChannel.SetValuesBlock(Values)
Brad Turpin
Principal Technical Support Engineer
NI
05-06-2021 02:26 PM
Thanks Brad. You are correct, I just Script Recorded those clipboard commands. I will try to integrate the Channel objects you mentioned below. I think those will help me out when trying to write future scripts.
Thanks,
Tyler
05-07-2021 12:56 PM
This is ideally how I would want to write this loop, but either I don't have the right syntax or I can't define a variable with a collection of string and a different variable.
Mark0 = 0
For n = 0 to 6 Step 2
a = n + 1
b = n + 2
"Mark" & a = ChnFind("Ch(""[1]/EventKPH"")>0", "Mark" & n)
"Mark" & b = ChnFind("Ch(""[1]/EventKPH"")=0", "Mark" & a)
Next
To get around that I tried to make a new channel for each time ChnFind finds the next row. This should work, but I can't figure out how to call the first value from the channel. So it starts at zero each time and just finds the same point each time it goes through the loop. Both ChnFind and PNo find the row that corresponds with a value. I can't figure out how to call the value in row 1 of Channel "Mark0" for example, which is zero. The MsgBox is just for me to try to figure out why it is not working.
Dim n, a, b
Dim Mark0, MarkFirst, MarkFirstNum, MarkStart, MarkStartNum, MarkEnd, MarkEndNum
Dim sInput
Call Data.Root.ChannelGroups(1).Channels.Add("Mark0",DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels("Mark0").SetValues(0,1,1)
For n = 0 to 6 Step 2
a = n + 1
b = n + 2
MarkFirst = "Mark" & n
'MarkFirstNum = ChnFind("Ch(""[1]/" & MarkFirst & """)>-1",0)
'MarkFirstNum = PNo(Data.Root.ChannelGroups(1).Channels(MarkFirst),1)
MarkStartNum = ChnFind("Ch(""[1]/EventKPH"")>0",MarkFirstNum)
MarkStart = "Mark" & a
Call Data.Root.ChannelGroups(1).Channels.Add(MarkStart,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkStart).SetValues(MarkStartNum,1,1)
MarkEndNum = ChnFind("Ch(""[1]/EventKPH"")=0",MarkStartNum)
MarkEnd = "Mark" & b
Call Data.Root.ChannelGroups(1).Channels.Add(MarkEnd,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkEnd).SetValues(MarkEndNum,1,1)
sInput = "MarkFirst = " & Markfirst & vbCRLF & " MarkFirstNum = " & MarkFirstNum & vbCRLF & " MarkStart = " & MarkStart & vbCRLF & " MarkStartNum = " & MarkStartNum & vbCRLF & " MarkEnd = " & MarkEnd & vbCRLF & " MarkEndNum = " & MarkEndNum
Call MsgBox(sInput)
Next
05-07-2021 01:04 PM
I knew it would be an easy thing I was overlooking. I'll play around with it some more now and try to get the rest of it working.
MarkFirstNum = Data.Root.ChannelGroups(1).Channels(MarkFirst).Values(1)
05-18-2021 04:00 PM
Here is the loop that I got working. Thought I would put this up here in case it helps anyone.
Call Data.Root.ChannelGroups(1).Channels.Add("Mark0",DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels("Mark0").SetValues(0,1,1)
For n = 0 to 6 Step 2
a = n + 1
b = n + 2
MarkFirst = "Mark" & n
MarkFirstNum = Data.Root.ChannelGroups(1).Channels(MarkFirst).Values(1)
MarkStartNum = ChnFind("Ch(""[1]/EventKPH"")>0",MarkFirstNum)
MarkStart = "Mark" & a
Call Data.Root.ChannelGroups(1).Channels.Add(MarkStart,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkStart).SetValues(MarkStartNum,1,1)
MarkEndNum = ChnFind("Ch(""[1]/EventKPH"")=0",MarkStartNum)
MarkEnd = "Mark" & b
Call Data.Root.ChannelGroups(1).Channels.Add(MarkEnd,DataTypeFloat64)
Call Data.Root.ChannelGroups(1).Channels(MarkEnd).SetValues(MarkEndNum,1,1)
Set Channel = Data.Root.ChannelGroups(1).Channels("Integrated")
Values = Channel.GetValuesBlock(MarkStartNum, MarkEndNum - MarkStartNum)
Call Data.Root.ChannelGroups(1).Channels.Add("Integrated" & n,DataTypeFloat64)
Set NewChannel = Data.Root.ChannelGroups(1).Channels("Integrated" & n)
Call NewChannel.SetValuesBlock(Values)
Next