Mastercam后处理程序头输出加工时间--纯代码版方法。
此方法由官方提供,其原理利用了mill.set文件及buffer的方式来实现。
实现的原理及过程如下:
首先利用后处理调用mp.dll及mill.set,获取加工时间,并把加工时间保存为doc文件。
其次正常后处理程序,并向后处理中写入一个标志字符串。
最后再后处理运行结束前利用buffer重读nc文件,并搜索标志字符串。
Mastercam后处理基于钻孔开发测头(探针)源代码
找到标志字符串后替换标志字符串,并回写刀程序中,即可完成程序头或任意地方出加工时间。
1:定义各项数据
# Define strings used in building up the command line parameters for the DLL call
sspace : " " # SPACE character
ssq : "'" # Single Quote character
sdq : '"' # Double Quote character
sdoc : ".doc" # .doc extension
spath_in : "" # Will be the "path\name" of the NCI input file
spath_out : "" # Will be the "path\name" of the DOC output file
sparams : "" # Will be the command parameter line passed to the DLL
Mastercam后处理 3+2刀尖跟随计算源代码
2:定义mp.dll文件路径,此路径可用绝对路径,也可用相对路径
sdll : "D:\Program Files\Mastercam 2022\Mastercam\apps\MP.dll" # Name of the .DLL to be called - update path as needed
3:定义mill.set文件路径,此路径可用绝对路径,也可用相对路径
s_setfile : "C:\Users\Public\Documents\Shared Mastercam 2022\mill\Posts\Mill.set" # Define the path and name of the .set file to be used.
4:定义保存时间数据的函数
# Define strings used to read cycle time from .set output and write it to .pst output
set_time : "" #String to hold cycle time read from setup sheet output - entire line from .set output
scycle_time : "" #String to hold cycle time read from setup sheet output - time only, prefix stipped from set_time string
scycle_time_out : "(cycle_time_here)" #Keyword - This will be output where cycle time output is desired, then replace with the cycle time during ppost$.
loc_found : 0 #Flag to indicate that cycle time output location has been found.
5:定义buff1数据
# --------------------------------------------------------------------------
#Buffer 1, Doc file created by setup sheet
wc1 : 1 #Buffer 1 write counter
rc1 : 1 #Buffer 1 read counter
size1 : 0 #Buffer 1 size
string1 : "" #Buffer 1
fbuf 1 0 256 1 1 #Buffer 1
6:定义buff2数据
#Buffer 2, NC file after posting
wc2 : 1 #Buffer 2 write counter
rc2 : 1 #Buffer 2 read counter
size2 : 0 #Buffer 2 size
string2 : "" #Buffer 2
fbuf 2 1 256 1 1 #Buffer 2
7:在ppost$下完成整个加工时的获取,输出,回写到程序中
ppost$ # This posblock is call AFTER all the files from the PST run are closed!
spath_in = spathnci$ + snamenci$ + sextnci$
spath_out = spathnc$ + snamenc$ + sdoc
sparams = ssq + sdq + spath_in + sdq + sspace + sdq + s_setfile + sdq + sspace + sdq + spath_out + sdq + ssq
result = dll(sdll, sparams)
sbufname1$ = spath_out
size1 = rbuf(one, zero)
rc1 = size1
set_time = rbuf(one, rc1)
end_str_ix$ = zero
if end_str_ix$ = zero, result = strstr(":", set_time)
if end_str_ix$ = zero, result = strstr("=", set_time)
scycle_time = brksps(end_str_ix$, set_time)
sbufname2$ = spathnc$ + snamenc$ + sextnc$
while loc_found = zero,
[
string2 = rbuf(two, rc2)
if string2 = scycle_time_out,
[
wc2 = rc2 - one
scycle_time = sopen_prn + "CYCLE TIME =" + scycle_time + sclose_prn
scycle_time = wbuf(two, wc2)
loc_found = one
]
]
8:在psof$或其他任何想要输出加工时间的地方下面增加下面的代码。
psof$
*scycle_time_out,e$
GIF
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删