scriptA.py是在AEDT執行的IronPython程式。首先ScriptA將AEDT模擬資料輸出到data.csv當中(這裡用0,1,2,...13做示範)。接著用命令列呼叫Anaconda當中的Python執行ScriptB。ScriptB讀出data.csv資料轉為numpy格式並完成加總,接著將加總資料寫入result.csv。最後ScriptA讀取result.csv並輸出到AEDT的訊息視窗當中。
# scriptA
import os, sys
sys.path.append(os.path.dirname(__file__))
os.chdir(os.path.dirname(__file__))
with open('data.csv', 'w') as f:
for i in range(14):
f.writelines(str(i) + '\n')
os.system('call C:\ProgramData\Anaconda3\Scripts\activate.bat & C:\ProgramData\Anaconda3\python.exe .\scriptB.py')
with open('result.csv') as f:
result = f.readline()
AddWarningMessage(result)
# scriptB
import numpy as np
with open('data.csv') as f:
x = np.array([float(i) for i in f.readlines()])
with open('result.csv', 'w') as f:
f.write(str(np.sum(x)))
沒有留言:
張貼留言