首页/文章/ 详情

基于Python语言的二次开发-Tcl语言基础回顾- Variables(1/12)

27天前浏览1456

Tcl variables are always strings even when they contain numeric values. For most applications, using strings has no effect, but occasionally a HyperWorks application will expect a real number and passing a string will cause an error.

Tcl variables may not contain tabs, spaces, carriage returns, nor the following characters: $ [ ] { } . #

The set command is used to associate variables with data.

set var1 "one plus one equals";
set var2 "2";

set can also return the value of a variable. This can be useful when using one variable to reference the name of another variable.

set var1 "one plus one equals 2"; 
set var1;
one plus one equals 2
set var2 "var1";
set var2;
var1
set [set var2];
one plus one equals 2

Placing a $ before a variable name will replace (substitute) the variable with its associated value.

puts "The expression: $var1 $var2";
The expression: one plus one equals 2

To set a variable to nothing:

set var2 "2";
set var2 {};
puts $var2;

Tcl returns a carriage return.

To remove a variable from the current script use the unset command. This is handy because there are commands to check a variables existence.

set var2 "2";
unset var2;
puts $var2;
can't read "var2": no such variable
来源:TodayCAEer
ACT二次开发pythonUM
著作权归作者所有,欢迎分享,未经许可,不得转载
首次发布时间:2024-08-14
最近编辑:27天前
TodayCAEer
本科 签名征集中
获赞 16粉丝 8文章 163课程 0
点赞
收藏
作者推荐

HyperWork 2024 -二次开发 - Python 的基础应用-厚度分布图

这篇文章按照最开始的顺序,应该是当tcl语言基础回顾发完后再发的,但是还是应该先展示下有趣的内容。思来想去,不知道该写什么题材的内容,最后决定还是写它。关注了的小伙伴可能对这张图片比较熟悉。这是前段时间在写ANSA基础教程时,讲到第三方模块Matplotlib的使用,生成了一张图片——模型的厚度分布图。当时ANSA是保存了图片,再利用guitk模块显示的图表。ANSA二次开发_Python基础-基于matplotlib的模型厚度分布图JinTian,公众号:TodayCAEerANSA二次开发_Python基础-基于matplotlib的模型厚度分布图那为什么现在又拿这张图片来写呢?这是因为两者的载体不一样了。这次是在HyperWork中实现的。相较于ANSA,HyperWork的显示是直接支持QT的,所以可以跳出窗口实现自由缩放加Matplotlib所提供的功能,文章中介绍Matplotlib功能的代码同样可以放在HyperWork中显示。HyperWorks2024版本带来了更多的新功能和改进,特别是在二次开发的Python脚本支持方面,能够基于更多Python模块进行复杂的仿真分析和设计优化,功能开发。这是图表显示的功能代码max_value=max(data)num_bins=int(np.ceil(max_value/0.5))counts,bins=np.histogram(data,bins=np.arange(0,max_value+0.5,0.5))#生成颜色列表colors=cm.rainbow(np.linspace(0,1,len(counts)))#生成条形图plt.bar(bins[:-1],counts,width=0.5,align='edge',color=colors)#plt.bar(bins[:-1],counts,width=0.5,align='edge')plt.xlabel('Thickness')plt.ylabel('Count')plt.xticks(bins)plt.show()在数据处理和分析方面,Python拥有丰富的数据处理库,如NumPy、Pandas等,可以方便地处理仿真结果数据,进行统计分析和数据可视化。在第三方模块集成方面,Python能够与许多第三方模块集成,如Matplotlib用于绘图、SciPy用于科学计算等。这使得在HyperWorks中实现复杂的数据处理和可视化变得更加容易。接下来就是优势所在了HyperWorks2024的模块配置非常完整,这一点对于内网用户来说尤为方便。上述所列举的几个模块是可以直接导入,避免下载和安装所需的包。这不仅提高了工作效率,也减少了在内网环境中因网络限制而带来的困扰。HyperWorks2024结合Python脚本的应用,使得仿真和优化工作变得更加高效和灵活。功能实现很简单,只需要提取PSHELL的厚度即可,用上方提供的代码略微完善下就可以了。当然还有其他办法,第一次尝试付费阅读,需要完整源码的朋友,可选择付费查看哦,文件不大,付费前请斟酌哦。来源:TodayCAEer

未登录
还没有评论
课程
培训
服务
行家
VIP会员 学习 福利任务 兑换礼品
下载APP
联系我们
帮助与反馈