sDAP 2022可以在脚本中调用第三方的.NET类库分析数据并展示分析结果。
通过 clr.AddReference('类库名称')
加载.NET类库(需要将类库放到sDAP安装目录下的Lib文件夹)。
.NET的命名空间和子命名空间以Python模块的形式导入。
import System # 导入System命名空间
和Python的模块一下,也可以使用其他导入方法
from System import Environment
from System import *
命名空间的类以命名空间的属性导入,因此访问类需要加上完整的命名空间。
下面的示例调用 FftSharp 的方法计算PSD并展示结果:
import sys
import clr
clr.AddReference("FftSharp")
import FftSharp
# -- Use tab indentation by default (8 spaces) --
# -- Beginning of user code --
# -- This is the entry point of the script, do not modify the method name --
def main():
# Any changes to the channel will be saved, if you do not want to affect the original data use sNewChannel() to create a new channel.
channel = dap.ActiveDocument.sGetChannel('Velocity') # Channel name or index
psd = FftSharp.Transform.FFTpower(channel.DataY)
freq = FftSharp.Transform.FFTfreq(channel.SampleRate, psd.Length)
channel.DataX = freq
channel.DataY = psd
channel.UnitX = 'Hz'
channel.NameX = 'Frequency'
dap.ActiveDocument.sShowFrequencyDomain(channel)
运行结果: