12-20-2022 07:48 AM
I have an oscillation you can see in my upper area and I want to cut off the parts before and after the big oscillations using script. They are the inner part of the hysteresis you can see in the lower area.
So far I've got most of the Code done, but I don't understand why the variables, that position the cursors, always have value -1 and 0
dim P1, Pn
P1 = ChnFind("Ch(AccelLateral_Filtered) > 1") 'this should select part of the first upper peak
Pn = ChnFindReverse("Ch(AccelLateral_Filtered > 1)") 'this should select part of the last upper peak
'Bereich wird per VIEW ausgeschnitten
Dim MySheet, MyChart, MyCurve
Call View.NewLayout()
Set MySheet = View.ActiveSheet
MySheet.ActiveArea.DisplayObjType = "CurveChart2D"
Set MyChart = View.ActiveSheet.ActiveArea.DisplayObj
Set MyCurve = MyChart.Curves2D.Add("","[1]/AccelLateral_Filtered") 'here I Add the Channels I want to cut out to my VIEW window
Set MyCurve = MyChart.Curves2D.Add("","[1]/SWA_Filtered")
Set MyCurve = MyChart.Curves2D.Add("","[1]/SWT_Filtered")
Set MyCurve = MyChart.Curves2D.Add("","[1]/YawRate_Filtered")
View.Sheets("Blatt 1").Cursor.Type = "Band"
MySheet.Cursor.X1 = P1
MySheet.Cursor.P2 = Pn
Call ScriptStart("O:\...\Delete Around Selected Region.VBS", "", False) 'this script I found on the forums and does a good job at extracting the part selected by the band cursor
Call ChnLinGenImp("C1", 100, P1, 0, "") 'here I generate lines to check if the variables work as intended. They don't
Call ChnLinGenImp("C2", 100, Pn, 0, "")
I remember having this problem with Cursors on another script too, so I did it manually in VIEW, but here I want to do it the right way.
Is there something I'm missing?
Nukwa
Solved! Go to Solution.
12-21-2022 01:33 AM
Hi Nukwa,
Without a dataset it is difficult to exactly find this problem because it is not possible to debug. But after a quick script review I saw two this which needs your attention.
Pn seems to be wrongly calculated. I think this is correct:
Pn = ChnFindReverse("Ch(AccelLateral_Filtered) > 1")
P1 and Pn are containing index values of the channel. Your definition of the cursor position uses one time the X value range X1 (like time in seconds) and one time the index value of the channel P2.
MySheet.Cursor.X1 = P1
MySheet.Cursor.P2 = Pn
This is of course possible, but in case of P1 and Pn calculated with ChnFind if should be the cursor index for both.
If you only want to isolate a certain part of a channel you can use this script:
dim P1, Pn, oSourceChn, oTargetChn, oChnGroupChns
set oChnGroupChns = Data.Root.ChannelGroups(1).Channels
set oSourceChn = oChnGroupChns("AccelLateral_Filtered")
set oTargetChn = oChnGroupChns.Add("Result", DataTypeChnFloat64 )
Dim sFormula, aSymbol(2), aValues(2)
sFormula = "A > B"
aSymbol(1) = "A"
aSymbol(2) = "B"
Set aValues(1) = oSourceChn
aValues(2) = 1
P1 = ChnFind(sFormula,, aSymbol, aValues)
Pn = ChnFindReverse(sFormula,, aSymbol, aValues)
oTargetChn.SetValuesBlock(oSourceChn.GetValuesBlock(P1, Pn - P1))
Greetings
Walter
12-21-2022 02:47 AM
Thanks for the help, I wasn't sure of the difference between P and X as cursor, because I've seen both of them used in similar cases, on the forum, but P is the one I wanted to use.
Your script did the script for me and was a great help.