一.什么是Quick Macro?
快捷宏命令面板通常位于tecplot界面右侧的侧边栏,用于存放常用的宏命令,方便进行调用和运行。如果没有显示快捷宏面板,则需要手动打开,在Scripting->Quick Macros。
宏命令能实现很多功能能,简单来说它可以把手动的操作以代码的形式记录下来,当你需要再次进相同的操作时,直接运行这些代码,操作就可以完成,此外,代码中也可以加入其他复杂的循环、条件判断等语句,方便进行大量重复性或相似性的工作。


二.我自定义的快捷宏命令
Tecplot官方本身给出了5个自带的快捷宏命令,我自己又加入了三个个人比较常用的快捷宏命令:
第一个是一键导出图片。
通常每次导出图片都要设置图片格式、大小、质量高低、路径和名称,步骤比较繁琐,所以我使用宏设置Jpeg格式、大小为1000像素、质量100%、路径和名称与当前Layout一致,进行快捷导出。
这样在需要导出的时候,双击“Export_JPEG”这个命令,就会导出当前画面,路径和文件名与Layout一致,只是后缀不同。
第二个快捷宏命令是一键设置所有字体为“Times New Roman”。
通常导入数据开始做图时,坐标轴默认字体是”Helvetica”,一是不够美观,二是不符合学术论文作图规范,而每个坐标轴Title和Label都需要分别设置一次字体,这样就至少需要操作4次,非常麻烦。因此我写了这个宏命令,不论作图类型是极坐标、XY线还是二维、三维,都可以一键设置所有坐标轴标题和数字字体为”Times New Roman”。

第三个快捷宏命令是一键设置字体大小为指定值。
跟第二个快捷宏命令类似,设置各个坐标轴字体大小也比较麻烦,通常一幅图里所有字体大小应该接近,此外,在写论文的时候经常会出现把图片插入文章后发现图中字体大小不合适的情况,就需要频繁修改。因此我写了这第三个宏命令,双击运行后输入字体大小,然后就会修改好所有字体大小。
2024年11月30日进行了更新,新版包含了5个函数,如下图所示,相应更新的代码也最最后附上
1.“Export_JPEG_All_frames”跟原本的“Export_JPEG”,为一键导出图片。
2.“Export_JPEG_Current_frame”导出某一个激活状态的frame图片,运行后在弹出的对话框中输入文件名后缀。
3.“Export_JPEG_All_frames_set_width”可以设置图片宽度。
4.“Times New Roman”一键修改字体为新罗马,更新了图中图例字体的同步修改。
5.“Font size”一键修改字体大小,更新了图中图例字体的同步修改。
三.如何添加自定义的快捷宏命令?
在Tecplot安装目录下,找到tecplot.mcr文件,以文本形式打开,在文件最后加入自定义的Macrofunction,这里的Macrofunction其实就是自定义的实现特定功能的代码,旧版本的代码放在新版本的Tecplot宏中一般是可以运行的。
复制写好的宏命令代码到这个文件的末尾,保存文件,然后打开Tecplot(如果已经打开了Tecplot则需要重启软件)后就会显示在快捷宏命令面板上。运行方法:双击!
Tecplot安装目录下的tecplot.mcr文件
最后我把这三个常用的宏命令附在后面,供大家交流学习!
如果你觉得文章内容有点用,请点赞收藏,感谢!
#My coustom macro1
$!MACROFUNCTION
NAME = "Export_JPEG_All_frames"
SHOWINMACROPANEL = TRUE
$!ExportSetup ExportFormat = JPEG
$!ExportSetup JPEGEncoding = Progressive
$!ExportSetup Quality = 100
$!ExportSetup ImageWidth = 1000
$!RedrawAll
$!ExportSetup ExportFName = '|LAYOUTFNAME|.jpeg'
$!Export
ExportRegion = AllFrames
$!ENDMACROFUNCTION
#My coustom macro2
$!MACROFUNCTION
NAME = "Export_JPEG_Current_frame"
SHOWINMACROPANEL = TRUE
$!PROMPTFORTEXTSTRING |name|
INSTRUCTIONS = "Enter image name"
$!ExportSetup ExportFormat = JPEG
$!ExportSetup JPEGEncoding = Progressive
$!ExportSetup Quality = 100
$!ExportSetup ImageWidth = 1000
$!RedrawAll
$!ExportSetup ExportFName = '|LAYOUTFNAME|_|name|.jpeg'
$!Export
ExportRegion = CurrentFrame
$!ENDMACROFUNCTION
#My coustom macro3
$!MACROFUNCTION
NAME = "Export_JPEG_All_frames_set_width"
SHOWINMACROPANEL = TRUE
$!PROMPTFORTEXTSTRING |Width|
INSTRUCTIONS = "Enter image width"
$!ExportSetup ExportFormat = JPEG
$!ExportSetup JPEGEncoding = Progressive
$!ExportSetup Quality = 100
$!ExportSetup ImageWidth = |Width|
$!RedrawAll
$!ExportSetup ExportFName = '|LAYOUTFNAME|.jpeg'
$!Export
ExportRegion = AllFrames
$!ENDMACROFUNCTION
#My coustom macro4
$!MACROFUNCTION
NAME = "Times New Roman"
SHOWINMACROPANEL = TRUE
$!IF |PLOTTYPE| == 1
$!XYLineAxis YDetail 1 {Title{TextShape{FontFamily = 'Times New Roman'}}}
$!XYLineAxis YDetail 1 {TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!XYLineAxis XDetail 1 {TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!XYLineAxis XDetail 1 {Title{TextShape{FontFamily = 'Times New Roman'}}}
$!GlobalLinePlot Legend{TextShape{FontFamily = 'Times New Roman'}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 2
$!TwoDAxis YDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!TwoDAxis YDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!TwoDAxis XDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!TwoDAxis XDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!GlobalContour 1 Legend{NumberTextShape{FontFamily = 'Times New Roman'}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 3
$!ThreeDAxis XDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!ThreeDAxis XDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!ThreeDAxis YDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!ThreeDAxis YDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!ThreeDAxis ZDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!ThreeDAxis ZDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 4
$!PolarAxis ThetaDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!PolarAxis ThetaDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!PolarAxis RDetail{TickLabel{TextShape{FontFamily = 'Times New Roman'}}}
$!PolarAxis RDetail{Title{TextShape{FontFamily = 'Times New Roman'}}}
$!RedrawAll
$!ENDIF
$!LOOP |NUMFRAMES|
$!FrameControl ActivateByNumber
Frame = |LOOP|
$!FrameLayout ShowBorder = No
$!RedrawAll
$!ENDLOOP
$!ENDMACROFUNCTION
#My coustom macro5
$!MACROFUNCTION
NAME = "Font size"
SHOWINMACROPANEL = TRUE
$!PROMPTFORTEXTSTRING |Fontsize|
INSTRUCTIONS = "Enter font size"
$!IF |PLOTTYPE| == 1
$!XYLineAxis XDetail 1 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 1 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 1 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 1 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 2 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 2 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 2 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 2 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 3 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 3 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 3 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 3 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 4 {TickLabel{TextShape{Height = |Fontsize|}}}
$!XYLineAxis XDetail 4 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 4 {Title{TextShape{Height = |Fontsize|}}}
$!XYLineAxis YDetail 4 {TickLabel{TextShape{Height = |Fontsize|}}}
$!GlobalLinePlot Legend{TextShape{Height = |Fontsize|}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 2
$!TwoDAxis XDetail{Title{TextShape{Height = |Fontsize|}}}
$!TwoDAxis XDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!TwoDAxis YDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!TwoDAxis YDetail{Title{TextShape{Height = |Fontsize|}}}
$!GlobalContour 1 Legend{NumberTextShape{Height = |Fontsize|}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 3
$!ThreeDAxis YDetail{Title{TextShape{Height = |Fontsize|}}}
$!ThreeDAxis YDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!ThreeDAxis XDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!ThreeDAxis XDetail{Title{TextShape{Height = |Fontsize|}}}
$!ThreeDAxis ZDetail{Title{TextShape{Height = |Fontsize|}}}
$!ThreeDAxis ZDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!RedrawAll
$!ENDIF
$!IF |PLOTTYPE| == 4
$!PolarAxis RDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!PolarAxis RDetail{Title{TextShape{Height = |Fontsize|}}}
$!PolarAxis ThetaDetail{Title{TextShape{Height = |Fontsize|}}}
$!PolarAxis ThetaDetail{TickLabel{TextShape{Height = |Fontsize|}}}
$!RedrawAll
$!ENDIF
$!ENDMACROFUNCTION
文章关键词总结:Tecplot快捷宏命令,一键导出图片,一键修改字体样式,一键修改字体大小