Create Block Size Rule

Now that we can change the size of each port, we must determine which face has the largest port, so that the block can be sized appropriately. It requires another rule.

  1. Add a new rule named block_size_rule.

    To determine the largest port, we examine the values of the three port size parameters, and retain the largest value. As with block_shape_rule, the behavior for tee-style blocks must be different than for elbow-style blocks.

    For tee-style blocks, all three ports are used, so we check the sizes for all them. For elbow-style blocks, we do not check Port B, which is suppressed. We use the MaxOfMany function to get the largest value from a set of input values.

  2. Begin block_size_rule as shown, by typing it directly into the text area or by inserting from the available generic statements on the toolbar. To insert the MaxOfMany function, expand the Math node in the Snippets area, and double-click MaxOfMany.

    Copy Code Block

    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

    A new local variable named port holds the size of the largest available port. Now we have to tell the model what to do with this information. The model obtains its information from an embedded Excel spreadsheet, so we look at the spreadsheet to update the overall sizes of the model.

  3. Press Enter twice to add some whitespace in the rule.
  4. As with the rule you created previously, insert a copy of the FindRow (embedded) function. Modify it to get the values for other parameters from the embedded spreadsheet by locating the appropriate row of information.

    Copy Code Block

    i = GoExcel.FindRow("3rd Party:Embedding 1", "Sheet1", "port_size", "=", port)

    We are using the port_size column for the lookup, and the value of the assigned variable as the value to look for.

  5. Set model parameters with information from the embedded Excel spreadsheet, using the found row for the largest port size.

    Copy Code Block

    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")

    We have now determined which port is the largest, and we are sizing the top of the block accordingly. Now, we determine the height of the block by examining the tee and elbow to determine which port size is bigger on the Port A / Port B face.

  6. Create another statement that uses another local variable porta to hold onto this value. Because Port B is not used for elbow-style blocks, the statement includes different steps depending on this setting.

    Copy Code Block

    If block = "tee" Then
    porta = MaxOfMany(port_a_size, port_b_size)
    ElseIf block = "elbow"
    porta = port_a_size
    End If

    The MaxOfMany function, is not used for elbow-style blocks, since only one value must be considered. We can set the variable from that value.

  7. Create another FindRow (embedded) statement to get the height values of the block from the Excel spreadsheet.

    Copy Code Block

    i = GoExcel.FindRow("3rd Party:Embedding 1", "Sheet1", "port_size", "=", porta)
  8. Use the CurrentRowValue function to set the height of the block.

    Copy Code Block

    port_a_vert_offset = GoExcel.CurrentRowValue("vert_offset")
    port_b_vert_offset = GoExcel.CurrentRowValue("vert_offset")
  9. Finally, set the value for two additional parameters. The first parameter sets the block height. The second parameter sets the vertical offset of Port C.

    For this value, we add special logic to insert extra space beyond the vertical offset used for the other ports. This information is obtained from another spreadsheet cell. We only do it for elbow-style blocks.

    Copy Code Block

    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")

    The block_size rule is complete.

  10. Click OK in the Edit Rule dialog box.
  11. Change any of the port sizes in the Parameters dialog box, and watch the model update.

Previous | Next