DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Can I copy data points from a VBScript?

Solved!
Go to solution

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

Clipboard03.png

 

 

Thank you 

 

Lucas

0 Kudos
Message 1 of 6
(5,588 Views)
Solution
Accepted by topic author LucasG

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

Message 2 of 6
(5,554 Views)

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

Message 3 of 6
(5,535 Views)

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...

0 Kudos
Message 4 of 6
(5,282 Views)

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.

0 Kudos
Message 5 of 6
(3,249 Views)

The script functions for flags do not implement that feature yet. So far the presented workaround is the option to go with.

0 Kudos
Message 6 of 6
(3,232 Views)