PTK 的 Excel 集成采用客户端-服务器(CS)架构,包括四个核心组件:
- Excel 文档:用户界面和数据存储
- logic.py:实现与 PIPESIM 模型的数据交互逻辑
- server.py:监听端口,处理来自客户端的消息
- client.py:连接服务器,发送命令
架构工作流
Excel 中的 VBA 按钮调用 logic.py → logic.py 启动 server.py 监听 → 用户点击命令按钮 → VBA 通过 client.py 发送命令到 server.py → logic.py 处理命令并操作 PIPESIM 模型 → 结果返回 Excel。文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/27028.html
Excel 文档要求
Excel 工作簿需要包含两个基本工作表:文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/27028.html
- Introduction 表:包含 PortNumber 和 Python 安装路径的命名范围
- Model 表:包含 PythonFolder(下拉列表)、ModelFolder、ModelFile 等命名范围
至少需要两个表单控件按钮:「Connect」和「Command」。文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/27028.html
logic.py 中的消息处理
def handleMessage(message):
if message == 'get_info':
get_info()
print("Information received")
return True
elif message == 'run_simulation':
run_network_sim()
print("Simulation completed")
return True
return FalseVBA 代码示例
Sub RunSimulation()
Call ExecuteServerScript
Call ExecuteCommand("run_simulation")
End Sub自动端口检测
CS 架构自动检测并使用可用端口,无需手动配置。_CommonScripts 文件夹中的脚本可以跨案例共享,减少重复代码。文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/27028.html 文章源自云智设计-https://www.cidrg.com/cid-college/tutorial/27028.html

客服微信
扫一扫

EngGPT
微信号已复制
云智微信公众号
扫一扫

cidrg_com
公众号已复制



