Hyperview Python 二次开发 模型显示与隐藏
·

def pid (showtype,*args):
# showtype 显示 "add" 隐藏 "era"
# *args 一个数字表示显示/隐藏单个pid
# 列如 pid("era",2005)
# *args 两个数字表示显示/隐藏pid 范围
# pid("era",2001,6010)
# *args 大于两个数字表示显示/隐藏无规律pid list
# 列如pid("era",2001,6010,4001,9001)
import hw
import hw.hv as hv
ses = hw.Session()
win = ses.get(hw.Window)
model = ses.get(hv.Model)
# 新建 collection
collection = hv.Collection(hv.Part,populate=False)
# 通过pid 添加 part到collection中
if len(args) == 1:
collection.addByID(hv.Part,idstr=args[0],visible=False)
if len(args) == 2:
collection.addByID(hv.Part,f"{args[0]}-{args[1]}",visible=False)
if len(args) > 2:
args_str = ",".join(str(arg) for arg in args)
collection.addByID(hv.Part,args_str,visible=False)
# 遍历collection中元素,执行显示或隐藏
for part in collection.getEntities():
if showtype =="add":
part.visibility = True
if showtype =="era":
part.visibility = False
win.draw()
更多仿真笔记,欢迎关注公众号 【CAE仿真记】
更多推荐


所有评论(0)