Mastercam后处理输出加工时间源代码——X版

Mastercam后处理时间源代码,该方法所输出的时间只能放在程序尾部,如果需要放在程序头,需要使用者额外增加输出到程序头的代码,至于程序时间的准确与否,未经全面测试,部分测试时间可信。
如需要MastercamV9.1版,参考下文章
Mastercam后处理时间源代码
以下代码适用于MatercamX版本之后的所有版本
由于代码较多,添加时严格按照下列方法进行。
——————如有代码缺失,跟帖留言。——————-
1:换刀时间,这个需要根据实际情况进行相应的时间设定。
单位:分钟
tlchgtime:0.066#ToolChangeTime(inMinutes)I‘ts4secnow
2:定义切削进给,快速进给等保存数据标签。
ttltime:0#Totaloperationtimetltime:0#Feedtimetrtime:0#Rapidtimetotal:0#Totalmachinetimetot_ltime:0#TotalFEEDtimetot_rtime:0#TotalRAPIDtime
3:定义记录x,y,z相对距离保存数据标签
len:0#Lengthforcalculationdx:0#Deltaxdy:0#Deltaydz:0#Deltaz
3:定义钻孔类辅助数据保存标签
drill_length_r:0#Drilllength-RAPIDdrill_length_f:0#Drilllength-FEEDactual_drl_depth:0#Actualdrilldepthvariablepeck_safe_dist:0.3#Peck/Chipbreaksafedistanceforretratctintohole
4:定义其他的辅助开关
use_TC_pos:yes\(#CalculatewithHomepositions@TC?0=No,1=Yessav_X_Pos:0#SavedXposition,useX_home/Y_home/Z_homeinrapidsatTCsav_Y_Pos:0#SavedYposition,useX_home/Y_home/Z_homeinrapidsatTCsav_Z_Pos:0#SavedZposition,useX_home/Y_home/Z_homeinrapidsatTC<p>5:定义时间输出格式</p><p>time_format:2#TimeformatofoutputtimesinNCcode:#1=2h14:25#2=2hrs,14mins,25.08sec<p>6:定义时间数据格式</p><p>fs280^20^2n#Decimal,2place,omitdecimalifwholenumber,non-modal<p>7:定义时间数据输出类型</p><p>fmt2llenfmt2rlenfmt2llen_totalfmt2rlen_totalfmt2totalfmt2ttltimefmt4thrsfmt4tminfmt8tsec<p>8:初始化所有保存数据的标签</p><p>ptime_calc!gcode\)llen=zero#Resetcounterfornexttoolrlen=zero#Resetcounterfornexttooltltime=zero#Resetcounterfornexttooltrtime=zero#Resetcounterfornexttoolttltime=zero#Resetcounterfornexttoolifuse_tch_pos,[sav_X_Pos=x\(,sav_Y_Pos=y\),sav_Z_Pos=z\(x\)=xh\(,y\)=yh\(,z\)=zh\(x\)=sav_X_Pos,y\(=sav_Y_Pos,z\)=sav_Z_Pos,]
9:统计进给距离,快速进给距离,时间等
ptooldata#Totalendingdatafortool(PathLengthandTimes)llen_total=llen_total+llen#KeeprunningtotalforProgramrlen_total=rlen_total+rlen#KeeprunningtotalforProgramtot_ltime=tot_ltime+tltime#TotalFEEDtimetot_rtime=tot_rtime+trtime#TotalRAPIDtimettltime=tltime+trtime#Calc.currentToolTimetotal=ttltime+total+tlchgtime#Calc.totalProgramTime
10:时间转换,按60进制进行转换
pthrminsec#Convertminutestohr/min/secformat thrs=int(ttltime/60) tmin=int(ttltime-thrs*60) tsec=(ttltime-thrs*60-tmin)*60
11:时间输出
ptimeout#Output“times”pthrminsec#Convertminutestohr/min/secformatiftime_format=one,[#Output’HOURS‘ifthrs=one,*thrs,“hr,”ifthrs>one,*thrs,“hrs,”#Output’MINUTES‘iftmin=one,*tmin,“min,”iftmin>one,*tmin,“min,”#Output’SECONDS‘iftsec>zero,*tsec,“sec”]else,[result=newfs(five,tsec)#Output’HOURS‘ifthrs>one,*thrs,“h”#Output’MINUTES‘and’SECONDS‘*tmin,“:”,*tsec]
12:快速进给时间计算
ptimer#Rapidtimeandlengthcalcrlen=rlen+len#RunningtotalRAPIDlengthtrtime=rlen/pst_rpd_fr\(#RunningtotalRAPIDtime<p>13:进给加工时间计算</p><p>ptimel#Feedtimeandlengthcalcllen=llen+lentltime=tltime+len/fr_pos\)
14:运行轨迹距离计算
ptime_calc#Distancecalculations#DeltaDistancesdx=x\(-prv_x\)dy=y\(-prv_y\)dz=z\(-prv_z\)#Distanceatlinearmovementifgcode\(=zero|gcode\)=one,len=sqrt(dx^2+dy^2+dz^2)#Distanceatcircularmovementifgcode\(=two|gcode\)=three,len=(abs(sweep\()/360)*2*arcrad\)*pi\(#Distanceatdrillingifgcode\)=81|gcode\(=100,[ifgcode\)=100,ptime_drill_XYifdrillcyc\(=0,ptime_drill_0#SimpleDrillifdrillcyc\)=1,ptime_drill_1#PeckDrillifdrillcyc\(=2,ptime_drill_2#ChipBreakDrillifdrillcyc\)=3,ptime_drill_3#Tappingifdrillcyc\(=4,ptime_drill_4#Bore,feedout,Reamingifdrillcyc\)=5,ptime_drill_4#Bore,feedout,Reamingifdrillcyc\(=6,ptime_drill_4#Bore,feedout,Reamingifdrillcyc\)=7,ptime_drill_4#BackBore,feedout,Reamingifdrillcyc\(=8,ptime_drill_0#SAMEmovementsas"SimpleDrill"ifdrillcyc\)=9,ptime_drill_0#Muiltfinebroing]#Timecalculationsbyfeedtypeifgcode\(=zero,ptimer#RAPIDtimeandlengthcalcifgcode\)=one|gcode\(=two|gcode\)=three,ptimel#FEEDtimeandlengthcalc!x\(,!y\),!z\(,!fr_pos\)#Updateprevious[prv_?]variables
15:G81,G82钻孔距离,时间计算
ptime_drill_0#SimpleDrilllengths#MovelengthwithFEED,straightdowntoholedepthlen=abs(refht\(-depth\))ptimelifinitht\(<>refht\),#MovelengthwithRAPID,IN&OUTofhole[#RapidbetweenInitial&Retract,MoveTOholelen=abs(initht\(-refht\))#RapidbetweenInitial&Depth,MoveOUTofholelen=len+abs(initht\(-depth\))ptimer]else,[#RapidbetweenRetract&Depth,ONLYMoveOUTofholelen=abs(refht\(-depth\))ptimer]#Convertandadddwell\(secondstototalminutesifdwell\)<>zero,total=total+(dwell\(/60)<p>16:G83钻孔距离,时间计算</p><p>ptime_drill_1 #MovelengthwithFEED,holedepthdrill_length_f=abs(refht\)-depth\()actual_drl_depth=peck1\)#ifmet_tool\(,peck_safe_dist=peck_safe_dist*scale_mmwhileactual_drl_depth<drill_length_f,[#FEEDmovesinholelen=peck1\)+peck_safe_distptimel#RAPIDmovesinholelen=(actual_drl_depth*2)-peck_safe_distptimeractual_drl_depth=actual_drl_depth+peck1\(]#Lastcut,it'sequalorlessthanpeck1\)len=(drill_length_f-actual_drl_depth)+peck_safe_dist+peck1\(ptimelifinitht\)<>refht\(,#MovelengthwithRAPID,IN&OUTofhole[#RapidbetweenInitial&Retract,MoveTOholelen=abs(initht\)-refht\()#RapidbetweenInitial&Depth,MoveOUTofholelen=len+abs(initht\)-depth\()ptimer]else,[#RapidbetweenRetract&Depth,ONLYMoveOUTofholelen=abs(refht\)-depth\()ptimer]#Convertandadddwell\)secondstototalminutesifdwell\(<>zero,total=total+(dwell\)/60)
17:G73钻孔距离,时间计算
ptime_drill_2#ChipBreakDrill#MovelengthwithFEED,holedepthdrill_length_f=abs(refht\(-depth\))actual_drl_depth=peck1\(#ifmet_tool\),peck_safe_dist=peck_safe_dist*scale_mmwhileactual_drl_depth<drill_length_f,[#FEEDmovesinholelen=peck1\(+peck_safe_distptimel#RAPIDmovesinhole,onlychipbreakmoves-BACKWARDlen=peck_safe_distptimeractual_drl_depth=actual_drl_depth+peck1\)]#Lastcut,it’sequalorlessthanpeck1\(len=(drill_length_f-actual_drl_depth)+peck_safe_dist+peck1\)ptimelifinitht\(<>refht\),#MovelengthwithRAPID,IN&OUTofhole[#RapidbetweenInitial&Retract,MoveTOholelen=abs(initht\(-refht\))#RapidbetweenInitial&Depth,MoveOUTofholelen=len+abs(initht\(-depth\))ptimer]else,[#RapidbetweenRetract&Depth,ONLYMoveOUTofholelen=abs(refht\(-depth\))ptimer]#Convertandadddwell\(secondstototalminutesifdwell\)<>zero,total=total+(dwell\(/60)<p>18:G84攻丝距离,时间计算</p><p>ptime_drill_3#Tapping#Movinglengthaddeddirectlyto"feedlength"drill_length_f=(abs(refht\)-depth\())*2llen=llen+drill_length_f#Movingtimeaddeddirectlyto"TotalFEEDtime",minutestot_ltime=tot_ltime+((drill_length_f/(feed/speed))/speed)ifinitht\)<>refht\(,#MovelengthwithRAPID,IN&OUTofhole[#RapidbetweenInitial&Retract,MoveTOhole&OFFfromholelen=(abs(initht\)-refht\())*2ptimer]#Convertandadddwell\)secondstototalminutesifdwell\(<>zero,total=total+(dwell\)/60)
19:G85,G86,G87镗孔,铰孔距离,时间计算
ptime_drill_4#Bore,feedout,Reaming#MovelengthwithFEED,holedepthlen=(abs(refht\(-depth\)))*2+shftdrl\(ptimelifinitht\)<>refht\(,#MovelengthwithRAPID,IN&OUTofhole[#RapidbetweenInitial&Retract,MoveTOhole&OFFfromholelen=(abs(initht\)-refht\())*2+shftdrl\)ptimer]#Convertandadddwell\(secondstototalminutesifdwell\)<>zero,total=total+(dwell\(/60)<p>20:钻孔其他类型距离,时间计算</p><p>ptime_drill_XY#Movesbetweenadditionalpointssav_gcode=gcode\)gcode\(=zeroptime_calcgcode\)=sav_gcode
21:在psof按如下格式增加
psof\(#Startoffilefornon-zerotoolnumberpsetup<p>22:在ptlchg后按如下格式增加</p><p>ptlchg\)#Toolchangeptooldata#Totalendingdatafortool(PathLengthandTimes)psetup
23:在pncoutput按如下格式增加
pncoutput#Movementoutputptime_calc
24:在pdrlcommonb按如下格式增加
pdrlcommonb#CannedDrillCyclecommoncall,beforeptime_calc
25:在pcancledc按如下格式增加
pcanceldc#Cancelcanneddrillcycleptime_calc
26:在peof按如下格式增加
peof\(#Endoffilefornon-zerotool ptooldata#Totalendingdatafortool(PathLengthandTimes) "(***PathLength/Time***)",e\) “(RapidPathLengh=”,*rlen_total,punit,“)”,e\( "(FeedPathLength=",*llen_total,punit,")",e\) ttltime=total #TransferTOTALprogramtime “(FullCycleTime=”,ptimeout,“)”,e\( #ProgramTotaltimeoutput ttltime=tot_rtime "(FullRapidTime:",ptimeout,")",e\) ttltime=tot_ltime “(FullFeedTime:”,ptimeout,“)”,e\(<p>27:公英制判断</p><p>punit#Systemunitifmet_tool\),“mm”else,“In”
申明:以上代码来自国外网站,非本人原创,为了方便大家,搬运过来,其中部分地方进行了修正。