既然我们可以更改每个端口的尺寸,那么我们必须确定哪个面具有最大的端口,以便可以相应地调整块的尺寸。这就需要另一个规则。
若要确定最大的端口,先检验三个端口尺寸参数的值,并保留最大值。正如 block_shape_rule 一样,三通样式块的行为必然不同于弯头样式块。
对于三通样式块,所有三个端口都会被用到,因此我们会检查所有端口的尺寸。而对于弯头样式块,我们不会检查被抑制的端口 B。我们使用 MaxOfMany 函数从一组输入值中获取最大值。
If block = "tee" Then port = MaxOfMany(port_a_size,port_b_size,port_c_size) ElseIf block = "elbow" Then port = MaxOfMany(port_a_size,port_c_size) End If
名为 port 的新本地变量中存放着可用最大端口的大小。现在,我们必须告诉模型如何使用此信息。模型从嵌入式 Excel 电子表单中获取其信息,因此我们期望通过该电子表单来更新模型的整体尺寸。
i = GoExcel.FindRow("3rd Party:Embedding 1", "Sheet1", "port_size", "=", port)
我们会使用 port_size 列进行查找,并使用指定变量的值作为要查找的值。
block_depth = GoExcel.CurrentRowValue("block_depth") port_c_depth_from_front = GoExcel.CurrentRowValue("port_c_depth_from_front") block_width = GoExcel.CurrentRowValue("block_width") port_a_hor_offset = GoExcel.CurrentRowValue("hor_offset") port_b_hor_offset = GoExcel.CurrentRowValue("hor_offset") port_c_hor_offset = GoExcel.CurrentRowValue ("hor_offset")
现在我们已经确定了哪个端口最大,而且要相应地调整块顶部的大小。现在我们通过检验三通和弯头来确定在端口 A/端口 B 上哪个端口尺寸较大,从而确定块的高度。
If block = "tee" Then porta = MaxOfMany(port_a_size, port_b_size) ElseIf block = "elbow" porta = port_a_size End If
MaxOfMany 函数不能用于弯头样式块,因为只能考虑一个值。我们可以根据该值设定变量。
i = GoExcel.FindRow("3rd Party:Embedding 1", "Sheet1", "port_size", "=", porta)
port_a_vert_offset = GoExcel.CurrentRowValue("vert_offset") port_b_vert_offset = GoExcel.CurrentRowValue("vert_offset")
对于这个值,我们要添加特殊的逻辑在其他端口所用的竖直偏移以外插入额外空间。此信息是从另一个电子表单单元格中获取的。只有对于弯头样式块,我们才会这么做。
If block = "elbow" Then port_c_vert_offset = GoExcel.CurrentRowValue("vert_offset") + (GoExcel.CurrentRowValue("port_dia")/4) Else port_c_vert_offset = GoExcel.CurrentRowValue("vert_offset") End If block_height = GoExcel.CurrentRowValue("block_height")
block_size 规则已经完成。