通过自动化接口访问塔温度分布的示例

import win32com.client as win32

def temp_prof_example(ih_ap_sim):
    """
    与 VB 的 TempProfExample 完全一致:
    读取 B6 塔温度分布(单标识符非标量变量)
    """
    # 1. 获取 B_TEMP 节点
    ih_t_var = ih_ap_sim.Tree.Data.Blocks.B6.Output.B_TEMP

    # 2. 拼接表头:维度名 + 变量名
    str_out = [f"{ih_t_var.Elements.DimensionName(0)}\t{ih_t_var.Name}"]

    # 3. 遍历每个塔板(Elements 即各 stage)
    for ih_stage in ih_t_var.Elements:
        stage_name = ih_stage.Name
        temp_val   = ih_stage.Value
        unit_str   = ih_stage.UnitString
        # 与 VB 的 Format(xxx, "###.00") 等效
        str_out.append(f"{stage_name}\t{temp_val:.2f}\t{unit_str}")

    # 4. 弹出消息框(同 VB MsgBox)
    from tkinter import Tk, messagebox
    root = Tk(); root.withdraw()
    messagebox.showinfo("TempProfExample", "\n".join(str_out))
    root.destroy()

# ---------------- 调用示例 ----------------
if __name__ == "__main__":
    ap = win32.Dispatch("AspenPlus.Document.34.0")
    ap.InitNew2()                 # 也可 GetObject 打开已有文件
    temp_prof_example(ap)
    ap.Quit()