01-04-2010 05:09 AM
Hello,
If I have a 2D-Axis area in VIEW, I can copy data points into a new channel by selecting the button "Flags: Copy Data Points". Is it possible to have the same functionality from a VBScript? I can set and remove flags, but I cannot find a way to copy those flags.
This is the button which functionallity I want to automate from my script
Thank you
Lucas
Solved! Go to Solution.
01-05-2010 03:59 AM
Hi Lucas,
To set flags in DIAdem VBScript use the command ChnFlagSet. But there is no command in VBS to remove or copy the flagged part of the curve. So I would suggest to use the cursor position and read the x-value from it, after this you can find the next value in the channel (use PNo). If you have an area and two coursor one on the left and one on the right you have to read x1 (left) and x2 (right). With this coordinats use the DataBlCopy command to copy the marked data in between the coursors to a new channel.
If this is to difficult, you can also use CHF to lookup which value of a channel is flagged and copy this to a new channel. Doing this you have to flag the values first.
As an example for this topic you can also look at "Automatische Anzeige harmonischer Frequenzen" in the DIAdem Example Finder
Hope this helps.
Regards
TomBaum
01-05-2010 09:21 AM
Hi Lucas,
I agree with TomBaum that the best way to do this is to use the X1 and X2 cursor positions or other methods to find the desired start and stop X values of the region to copy. This is in fact the way I always do this. Note that the cursor point number approach is squirrelly-- please use the X1 and X2 properties and the PNo() or Find() or ChnFind() functions to get the start and end channel rows of the region to copy. In rare cases you may need to copy already flagged data points-- there is a function ChF() that checks if a particular channel value has been flagged, so you could use an approach like this in those cases:
sub CopyFlaggedChnVal(Chn_X, Chn_Y)
Dim NewChn_X, NewChn_Y, X_No, Y_No, Xn_No, Yn_No, iMaxLen, iLoop, iCurrPos
iMaxLen = ChnPropValGet(Chn_Y, "length")
' allocate new channels
NewChn_X = ChnAlloc("TimeChn_New", iMaxLen)
NewChn_Y = ChnAlloc("ValChn_New", iMaxLen)
' get channel numbers for fast access
Xn_No = cno(NewChn_X(0))
Yn_No = cno(NewChn_Y(0))
X_No = cno(Chn_X)
Y_No = cno(Chn_Y)
iCurrPos = 1
' loop over the channel
for iLoop = 1 to iMaxLen
' check flag
if Chf(iLoop, Chn_Y) then
' copy value into new channel with fast access
ChdX(iCurrPos, Xn_No) = ChdX(iLoop, X_No)
ChdX(iCurrPos, Yn_No) = ChdX(iLoop, Y_No)
' increase loop counter for new channel
iCurrPos = iCurrPos + 1
end if
next
' set channel length (necessary because of fast access
Call ChnPropValSet(NewChn_X(0), "length", iCurrPos)
Call ChnPropValSet(NewChn_Y(0), "length", iCurrPos)
' set channel characteristics (necessary because of fast access
call ChnCharacter(NewChn_X(0))
call ChnCharacter(NewChn_Y(0))
end sub
Brad Turpin
DIAdem Product Support Engineer
National Instruments
02-11-2010 04:33 AM
thanks for the script, one short notice:
you should let iCurrPos start at zero instead of one, and move the line
iCurrPos=iCurrPos+1
up to the top of the if loop, or else you always get an extra line with only zeros in your new channel. This makes the VIEW-graph hard to read...
05-24-2018 10:42 AM
I'm looking to use this function and I was wondering if there have been updates to DAIdem to improve on the feature? I noticed this post was from 2010.
05-25-2018 04:04 AM
The script functions for flags do not implement that feature yet. So far the presented workaround is the option to go with.