在 NI DIAdem 中透過 Python 呼叫 VB 或其他腳本

更新 Jan 2, 2025

環境

軟體

  • DIAdem

程式語言

  • Python
  • Visual Basic

在 NI DIAdem 中,可以執行 Python 和 VB 腳本。為了更高的效率,可從您的主腳本中再間接去呼叫其他腳本。
本文介紹如何從 VB 腳本呼叫 Python 腳本,以及如何從另一個 Python 腳本呼叫 Python 腳本。

實施或執行程式碼的步驟

A. 從 VB 腳本呼叫 Python 腳本。
我們應該有兩個腳本檔案。

在 VB 中我們應該要有:

ScriptStart("C:\\...\\testPy.PY")

在名為 testPy.PY 的 Python 腳本中:

dd.print("testVar")

B. 從 Python 腳本中呼叫 Python 腳本:

PY 1:檔案名printhellodef.PY

def PrintHello():
  print("Hello")

PY 2-呼叫者:檔案名callprinthello.PY

import printhellodef
importlib.reload(printhellodef)

printhellodef.PrintHello()