主要利用DO循环实现数据的取值以及连续求和。
使用DO循环语句可以多次反复执行同一段程序,执行的次数可以是设定的数字、变量。
DO…ENDDO语句块
DO…ENDDO语句块以DO开头,ENDDO结尾,可以反复多次执行一组程序行,支持嵌套。格式如下:
DO/变量, 初始值, 结束值, 步长
$$ DMIS语句
ENDDO
变量:已定义的整数型变量
初始值:循环开始后变量开始计数的数值,为整数值
结束值:变量达到这个值后循环停止,为整数值
步长:变量每循环一次的增加值,可选项,不写默认为1
示例:圆1测量任意次,求直径平均值。
$$/* Header
DMISMN/'Created by [爱科腾瑞科技(北京)有限公司] on 星期四, 八月 01, 2019', 4.0
UNITS/MM, ANGDEC, MMPS
WKPLAN/XYPLAN
PRCOMP/ON
TECOMP/ON
FLY/1.0000
MODE/MAN
SNSET/APPRCH, 2.0000
SNSET/RETRCT, 2.0000
SNSET/DEPTH, 0.0000
SNSET/SEARCH, 10.0000
SNSET/CLRSRF, 20.0000
RECALL/D(MCS)
SNSLCT/S(L20-D2.0)
GEOALG/BF, LSTSQR
GEOALG/ANGLB, DEFALT
GEOALG/CIRCLE, LSTSQR
GEOALG/ARC, LSTSQR
GEOALG/PLANE, LSTSQR
$$
$$
$$*/
MODE/MAN
F(PLN1)=FEAT/PLANE,CART,33.4981,36.5016,0.0000,0.0000,0.0000,1.0000
$$ Measurement points are created through actual points
MEAS/PLANE, F(PLN1), 4
PTMEAS/CART, 3.7133, 58.9487, -0.0000, 0.0000, 0.0000, 1.0000
PTMEAS/CART, 7.1867, 9.0106, -0.0000, 0.0000, 0.0000, 1.0000
PTMEAS/CART, 60.5709, 5.0389, -0.0000, 0.0000, 0.0000, 1.0000
PTMEAS/CART, 62.5214, 73.0081, -0.0000, 0.0000, 0.0000, 1.0000
ENDMES
D(CRD1) = DATSET/FA(PLN1), ZDIR
F(LN1)=FEAT/LINE,BND,CART,6.9280,0.0000,-2.8142,59.9460,0.0000,-3.0830,0.0000,-1.0000,0.0000
$$ Measurement points are created through actual points
MEAS/LINE, F(LN1), 2
PTMEAS/CART, 6.9280, 0.0000, -2.8142, 0.0000, -1.0000, 0.0000
PTMEAS/CART, 59.9460, 0.0000, -3.0830, 0.0000, -1.0000, 0.0000
ENDMES
F(PT1)=FEAT/POINT,CART,0.0000,5.6942,-3.5011,-1.0000,0.0000,0.0000
MEAS/POINT, F(PT1), 1
PTMEAS/CART, 0.0000,5.6942,-3.5011,-1.0000,0.0000,0.0000
ENDMES
D(CRD2) = DATSET/FA(PLN1), ZDIR, ZORIG, FA(LN1), XDIR, YORIG, FA(PT1), XORIG
D(CRD2) = TRANS/ZORIG, -0, YORIG, -0, XORIG, -0
$$ Set.CAD2PCS.CADM_1
$$ Set.CADViewCenter.CADM_1
MODE/AUTO,PROG,MAN
$$ MACRO: EASI_CLEARPLN_GOTO
$$ FUNCTION: CLEARANCE SURFACE IMPLEMENTATION
$$ Move machine CLEAR SURFACE DIST above the current clear surface
$$ plane and then move machine parallel to the clear surface plane
$$ ALL Macro parameters are in PCS and Current UNITS
$$ Last update: 3-1-04 Add mode checking. only works in PROG MODE
$$ Last update: 8-24-04 Clear position is based on the surface of
$$
$$ This sample DMIS Macro is provided by External-Array Software, Inc.
$$ It should be modified for your own use. There is no guarantee for
$$ the quality of this Macro. November, 2003
M(EASI_CLEARPLN_GOTO) = MACRO/ISNOM, TARX, TARY, TARZ
DECL/LOCAL, REAL, CCX, CCY, CCZ, CCI, CCJ, CCK
DECL/LOCAL, REAL, CURX, CURY, CURZ, TD, CLRDIST, SDIAM
DECL/LOCAL, CHAR, 255, CLRLABEL, FLABEL, MMODE, SNAME
MMODE = VALUE/MODE
CLRLABEL = VALUE/SNSET, CLRSRF
IF/ ( (LEN(CLRLABEL) .GT. 0) .AND. (MMODE .EQ. 'PROG,MAN') )
CLRDIST = VALUE/SNSET, CLRSRF, DIST
FLABEL = ASSIGN/'FA'
IF/ ISNOM .EQ. 0
FLABEL = ASSIGN/'F'
ENDIF
CCX = OBTAIN/FLABEL(@CLRLABEL), 3
CCY = OBTAIN/FLABEL(@CLRLABEL), 4
CCZ = OBTAIN/FLABEL(@CLRLABEL), 5
CCI = OBTAIN/FLABEL(@CLRLABEL), 6
CCJ = OBTAIN/FLABEL(@CLRLABEL), 7
CCK = OBTAIN/FLABEL(@CLRLABEL), 8
SNAME = VALUE/SNSLCT
SDIAM = OBTAIN/SS(SNAME), 8
CCX = ASSIGN/CCX + CCI * SDIAM/2
CCY = ASSIGN/CCY + CCJ * SDIAM/2
CCZ = ASSIGN/CCZ + CCK * SDIAM/2
CURX = VALUE/GOTOM, XAXIS
CURY = VALUE/GOTOM, YAXIS
CURZ = VALUE/GOTOM, ZAXIS
TD = ASSIGN/(CURX - CCX) * CCI + (CURY - CCY) * CCJ + (CURZ - CCZ) * CCK
IF/ TD .LT. CLRDIST
TD = ASSIGN/(CLRDIST - TD)
GOTO/CURX+CCI*TD, CURY+CCJ*TD, CURZ+CCK*TD
ENDIF
TD = ASSIGN/(TARX - CCX) * CCI + (TARY - CCY) * CCJ + (TARZ - CCZ) * CCK
IF/ TD .LT. CLRDIST
TD = ASSIGN/(CLRDIST - TD)
GOTO/TARX+CCI*TD, TARY+CCJ*TD, TARZ+CCK*TD
ENDIF
ENDIF
ENDMAC
SNSET/APPRCH, 2.0000
SNSET/RETRCT, 2.0000
SNSET/DEPTH, 0.0000
SNSET/SEARCH, 10.0000
SNSET/CLRSRF, FA(PLN1), 20.0000
DECL/COMMON,INTGR,I
DECL/COMMON,INTGR,NUM
DECL/COMMON,CHAR,255,C1
NUM = PROMPT/'要测量特征多少次', 500, 2
DECL/COMMON,REAL,DD[NUM]
DO/I,1,NUM,1
C1 = ASSIGN/CONCAT('J','-',STR(I))
F(@C1)=FEAT/CIRCLE,INNER,CART,15.9115,22.5000,-2.0000,0.0000,0.0000,1.0000, 10.0000
$$ Empty Meas Block
MEAS/CIRCLE, F(@C1), 5
ENDMES
DD[I]= OBTAIN/FA(@C1),10
ENDDO
DECL/COMMON,INTGR,J
DECL/COMMON,REAL,AVERAGE
DECL/COMMON,CHAR,255,C2
AVERAGE = ASSIGN/DD[1]
DO/J,2,NUM,1
AVERAGE = ASSIGN/AVERAGE+DD[J]
ENDDO
AVERAGE = ASSIGN/(AVERAGE+DD[J])/NUM
C2 = ASSIGN/CONCAT('总共测量',STR(NUM),'次,','实测平均值:',STR(AVERAGE))
TEXT/OUTFIL, C2
TEXT/OPER, C2