10-24-2023 04:36 AM
Hello guys, I am the newbie of the newbies (not only in DIAdem, but basically for every script-software).
I try to explain my question --> "Channel 1" is composed by 14 numeric values, some of them positive and others negative, but for different reasons I need that Channel 1 would have only positive values or zeros, so all the negative values have to be converted into zeros. The problem is that this operation has to be described into a Script for automatic process, because everytime I load a different "Channel 1" i would only lose time. So, how can write it? Thanks in advance!
Solved! Go to Solution.
10-25-2023 04:56 AM
Hello,
If you want to replace all negative values from a channel with 0, you can do this with the ChnRangeLimit method. With the following script all negative values are replaced by 0, because 0 is specified as lower limit. So that no change occurs with the upper limit, NOVALUE is passed.
call ChnRangeLimit("[1]/Channel1", 0, NOVALUE, "[1]/Channel1_MinZero")
If you want to do this only for specific channels, then add a condition, such as querying the channel name or checking for the minimum of the channel. The example code shows how to check the mininum of each channel of the second group. You can test it with Example.tdm.
dim group : set group = data.Root.ChannelGroups(2)
dim result_group : set result_group = data.Root.ChannelGroups.Add("ResultGroup")
dim chn
for each chn in group.Channels
if chn.Minimum < 0 then
call ChnRangeLimit(chn, 0, NOVALUE, result_group.Name & "/" & chn.Name & "_MinZero")
end if
next
10-25-2023 06:59 AM
It works!!! Thank you!