建立一个6*6*6的立方体,共计216个单元,343个节点。Z方向0~3米分组为a,3~6m分组为b。拟遍历b分组中的所有节点(Z方向3~6m范围内的所有节点)并计数,命令流如下:
model newzone create brick size 6 6 6 group 'a'zone group 'b' range position-z 3 6zone gridpoint group 'test' range position-z 3 6;对节点单独分组fish def test1count = 0loop foreach gpnt gp.listif gp.group(gpnt) = 'test' thencount = count + 1endifendloopio.out('The value of count is: ' + string(count) + '.')end@test1
运行@test1函数时,首先遍历整个模型节点,然后判定当前节点是否位于节点分组test中,若是,则count的值在原来的基础上加一,以达到计数的效果。运行后的输出为:The value of count is: 196. 显然,上述函数成功地遍历了b组中的所有节点。将第四行命令去掉,则输出为:The value of count is: 0. 可以看出,上述函数遍历失败,这是因为此时模型中并没有一个叫做test的节点分组。


模型以及遍历的目的同上,命令流如下:
model newzone create brick size 6 6 6 group 'a'zone group 'b' range position-z 3 6fish def test2count = 0loop foreach gpnt gp.listif gp.isgroup(gpnt,'b') = 1 thencount = count + 1endifendloopio.out('The value of count is: ' + string(count) + '.')end@test2

图(2)@test2函数运行输出
model newzone create brick size 6 6 6 group 'a'zone group 'b' range position-z 3 6fish def test3count = 0loop foreach gpnt gp.listif gp.isgroup(gpnt,'a') | gp.isgroup(gpnt,'b') thencount = count + 1endifendloopio.out('The value of count is: ' + string(count) + '.')end@test3
