cst-python版本更新

# -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 14:06:54 2020

@author: tWX5331009
"""

import numpy as np
import matplotlib.pyplot as plt
import sys
import os
from os.path import dirname, abspath
#设置环境变量
#os.environ['CST_INSTALLPATH_2020'] = r'E:\Program Files (x86)\CST Studio Suite 2020'   -> if path is NOT default..
sys.path.append("D:\installation\CST2020\AMD64\python_cst_libraries")

# Import cst modules
# cst.interface - Allows controlling a running CST Studio Suite.
# cst.results - Provides access to 0D/1D Results of a cst file.
# For more information, please take a look at the online help "Automation and Scripting -> Python -> CST Python Libraries"
import cst.results
import cst
import cst.interface

print(cst.__file__) # should print '<PATH_TO_CST_AMD64>\python_cst_libraries\cst\__init__.py

CstFileName  = input("请输入cst文件名(勿带cst后缀):")
ProjectName  = CstFileName+'.cst'
#getcwd()方法获取当前工作目录+文件名=文件目录
# Initialize secondary variables
ProjectPath = os.path.join(os.getcwd(), ProjectName)

#判断项目是否打开状态

# 首先,用一个开放的DE生成所有PIDs的列表 (cst.interface).
AllPIDs = cst.interface.running_design_environments()
IsOpen  = False

# Go through list of PIDs and query projects
for CurrentPID in AllPIDs:
    MyCurrentDE = cst.interface.DesignEnvironment.connect(CurrentPID)
    for ProjectPath in MyCurrentDE.list_open_projects():
        if ProjectPath == ProjectPath:
            MyPID            = CurrentPID
            MyCurrentProject = MyCurrentDE.get_open_project(ProjectPath)
            IsOpen           = True
            break

# In version 2021 I could e.g. now query if a solver is running or not...

if IsOpen:
    print('Project is already open...')
else:
    print('Project is not open at the moment...')



# If the project is not open already, open it now (cst.interface).

#if not IsOpen:
#    MyCurrentDE      = cst.interface.DesignEnvironment()
#    MyCurrentProject = MyCurrentDE.open_project(ProjectPath)



# Now the project is open and can be worked on...

# PLEASE NOTE: For workflows involving accessing 1D Results it is generally recommended to work with a closed project - although it is also possible to work in interactive mode.
# However, the assumption is that we want to trigger the solver, so we need an open project.

# PLEASE NOTE: With the python interface it is possible at the moment to execute vba commands, but we cannot get information back from the project through this method (at least currently)
# If we wanted to e.g. check on the existance of a 1D Result this could easily be done using the cst.results module.
# But to directly query the existance of e.g. a farfield result we (currently still) need to use the COM interface (which could in principle be done in conjunction with the python interface).
# But, at the moment we are assuming that the farfield has not been calculated yet.
#运行当前选定的解算器,直到它完成,并返回解算器运行是否成功。 
# Run the solver:
#MyCurrentProject.modeler.run_solver()


a = input("请输入需要导出到的频率(以空格间隔):")
b = int(input("请输入需要连续导出的端口数,如果指定端口导出,请输入-1:"))
b_list = []
if b == -1:
    b_assigned = input("请输入需要指定端口(以空格间隔):")
    b_list = str(b_assigned).split(' ')
        
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值