Create Rules in the Assembly

In the next several lessons, you create a series of rules to manage the contents of the assembly.

Pass Parameters from the Assembly to the Parts

This model includes a part named manifold_block:1, which has iLogic rules in it. We must pass the assembly level parameter to the part.

  1. Create a rule named assembly_to_parts_rule.

    This rule sets parameters in the part based on the corresponding values of the control parameters in the assembly. Our Parameter function specifies the component name as well as the parameter name.

    Copy Code Block

    Parameter("manifold_block:1", "block") = block 
    Parameter("manifold_block:1", "component_type") = component_type
    Parameter("manifold_block:1", "port_a_size") = port_a_size
    Parameter("manifold_block:1", "port_b_size") = port_b_size
    Parameter("manifold_block:1", "port_c_size") = port_c_size
  2. Click OK when you have completed this rule.

Edit Part-level Rules in an Assembly

In the Manifold Block Part tutorial, we added a rule to the manifold block part that controls the tee and elbow styles. We must also add it at the assembly level. Rather than rewrite the existing rule, we copy the original.

  1. Double-click manifold_block:1 from the Model browser. The other components become transparent.
  2. On the ribbon, click Manage tab iLogic panel Rule Browser .
  3. Double-click component_type_rule.
  4. Copy the rule text to the clipboard.
  5. Click Cancel on the Edit Rule dialog box to close it.
  6. Double click my_manifold_block.iam in the Model browser.
  7. Add a new rule named component_type_rule.
  8. Paste the copied rule text from component_type_rule into the rule text area of the Edit Rule dialog box.

    Copy Code Block

    If component_type = "standard" Then
    port_b_size = port_a_size
    port_c_size = port_a_size
    End If
  9. Click OK to save this assembly-level rule.

Add port_a_rule

When we change the port size of Port A, we must perform several tasks:

We add a rule to do it:

  1. Make sure your manifold block assembly is active.
  2. Create a rule named port_a_rule.

    The first part of this rule adjusts the screw pattern spacing, based on information stored iPart table of the union part.

  3. Add a code block that looks up the row being used based on the port_a_size parameter. Then assigns values to two different assembly parameters from two other columns.

    Copy Code Block

    i = iPart.FindRow("port_a_union", "port_size", "=", port_a_size)
    port_a_y_dist_between_screws = iPart.CurrentRowValue("y_dist_betwn_screw")
    port_a_x_dist_between_screws = iPart.CurrentRowValue("x_dist_betwn_screw")
    Note: The iPart-related statements used here can be found in the Snippets area under the iParts node of the System tab.

    The next part of the rule selects the appropriate iPart row inside the screw part based on the selected port size.

  4. Use a series of If statements to set the appropriate iPart member according to the current value of the port_a_size parameter.

    Copy Code Block

    If port_a_size = .50 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-01") 
    ElseIf port_a_size = 0.75 Then 
    iPart.ChangeRow("port_a_union_screw", "Screw-02")
    ElseIf port_a_size = 1.00 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-02")
    ElseIf port_a_size = 1.25 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-03")
    ElseIf port_a_size = 1.50 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-04")
    ElseIf port_a_size = 2.00 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-04")
    ElseIf port_a_size = 2.50 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-05")
    ElseIf port_a_size = 3.00 Then
    iPart.ChangeRow("port_a_union_screw", "Screw-06")
    End If
  5. For the last part of this rule, add a statement that gets the part number for the flare flange and stores it in an assembly parameter, which is used in another rule later in this tutorial.

    Copy Code Block

    port_a_union_part_number = iProperties.Value("port_a_union", "Project", "Part Number")
  6. Click OK to save the rule, and save the assembly file.

Add port_b_rule

Port B is different from Port A and Port C, because it does not exist in an elbow manifold block. If the manifold block is an elbow style block, we must suppress the union cap and the union screws used for this port. We must also suppress the mate constraints associated with the union cap.

Because we are suppressing components, we set a level of detail before we write the rule. Rules affecting items related to the level of detail in an assembly require that a custom level of detail be defined and saved before writing the rules. If the custom level of detail is not defined, iLogic generates an error message.

Set a Level of Detail

  1. In the Model browser, expand the Representations node and then the Level of Detail node.
  2. Right-click the Level of Detail node, and select New Level of Detail.

    A new level of detail is added.

  3. Slowly double-click LevelofDetail1, then and rename it to iLogic.

Write the Rule

Now, we can write the rule.

  1. Create a rule named port_b_rule.
  2. For the first part of the rule, determine if we are making a tee-style block, and store that in a separate variable isTee. The isTee variable holds a value of True or False.

    Copy Code Block

    If block = "elbow" Then
    isTee = False
    ElseisTee = True
    End If

    We use this variable later to set other parameters.

  3. Add lines to the rule to turn off the constraints that locate the union and union screw when the manifold block is an elbow style. Turn on the constraints when the manifold block is a tee style.

    Copy Code Block

    Constraint.IsActive("port_b_cap_center") = isTee
    Constraint.IsActive("port_b_cap_hole") = isTee
    Constraint.IsActive("port_b_cap_face") = isTee
    Constraint.IsActive("port_b_cap_screw") = isTee

    Note that we can use the isTee variable to turn these constraints on or off according to the value of the block parameter.

    Note: The naming convention used for these constraints has made it easier to refer to them in this rule. Remember that you can also use the Model tree information in the Edit Rule dialog box to help complete the names of the constraints.
  4. Add two lines that conditionally include the port_b_union part and corresponding screw pattern:

    Copy Code Block

    Component.IsActive("port_b_union") = isTee
    Component.IsActive("port_b_screw_pattern") = isTee

    These lines use the isTee variable. When the screw pattern is suppressed, the screw component is also suppressed.

  5. For instances in which we are using Port B, add a section that sets the port size, screw pattern parameter values, and port_b_union part number.

    Copy Code Block

    if isTee Then
    i = iPart.FindRow("port_b_union", "port_size", "=", port_b_size)
    port_b_y_dist_between_screws = iPart.CurrentRowValue("y_dist_betwn_screw")
    port_b_x_dist_between_screws = iPart.CurrentRowValue("x_dist_betwn_screw")
    port_b_union_part_number = iProperties.Value("port_b_union", "Project", "Part Number")
    End If

    We enclosed this entire block in an If isTee statement, so that these lines are only processed for a tee-style manifold block. The statement If isTee Then is equivalent to If isTee = True Then, but it provides a more concise expression format.

    We first choose the appropriate row in the s iPart table of the union part, corresponding to the value of the port_b_size parameter, and then extract the values to use for the x and y pattern offsets. Then, we extract the Part Number from the union part, and store its value in another parameter for later reference.

  6. For the last part of this rule, we choose the member within the s iPart table of the screw part to use for Port B. It is based on the value of the port_b_size parameter. Use a series of If/Then/Else statements to control it.

    Copy Code Block

    If port_b_size = .50 then
    iPart.ChangeRow("port_b_union_screw", "Screw-01")
    elseif port_b_size = .75 then
    iPart.ChangeRow("port_b_union_screw", "Screw-02")
    elseif port_b_size = 1.00 then
    iPart.ChangeRow("port_b_union_screw", "Screw-02")
    elseif port_b_size = 1.25 then
    iPart.ChangeRow("port_b_union_screw", "Screw-03")
    elseif port_b_size = 1.50 then
    iPart.ChangeRow("port_b_union_screw", "Screw-04")
    elseif port_b_size = 2.00 then
    iPart.ChangeRow("port_b_union_screw", "Screw-04")
    elseif port_b_size = 2.50 then
    iPart.ChangeRow("port_b_union_screw", "Screw-05")
    elseif port_b_size = 3.00 then
    iPart.ChangeRow("port_b_union_screw", "Screw-06")
    End If
  7. Click OK to close the dialog box and save the rule.
  8. Save your assembly file.

Add port_c_rule

The rule for Port C is almost the same as for Port A, except that everything referencing Port A must reference Port C instead.

  1. Open the Rule Browser.
  2. Double click port_a_rule.
  3. Use the mouse to highlight the entire rule.
  4. Press Ctrl+C to copy the rule text.
  5. Click OK on the Edit Rule dialog box to close it.
  6. Add a new rule named port_c_rule.
  7. In the Edit Rule dialog box, click in the rule text area, and press Ctrl+V to paste the rule.
  8. Click the Search and Replace tab at the top of the dialog box.
  9. Enter port_a in Find what.
  10. Enter port_c in Replace with.
  11. Place a check mark in Match Case.
  12. Click Replace All in This Rule.

    Copy Code Block

    i = iPart.FindRow("port_c_union", "port_size", "=", port_c_size)
    port_c_y_dist_between_screws = iPart.CurrentRowValue("y_dist_betwn_screw")
    port_c_x_dist_between_screws = iPart.CurrentRowValue("x_dist_betwn_screw")
    
    If port_c_size = .50 then
    iPart.ChangeRow("port_c_union_screw", "Screw-01")
    elseif port_c_size = .75 then
    iPart.ChangeRow("port_c_union_screw", "Screw-02")
    elseif port_c_size = 1.00 then
    iPart.ChangeRow("port_c_union_screw", "Screw-02")
    elseif port_c_size = 1.25 then
    iPart.ChangeRow("port_c_union_screw", "Screw-03")
    elseif port_c_size = 1.50 then
    iPart.ChangeRow("port_c_union_screw", "Screw-04")
    elseif port_c_size = 2.00 then
    iPart.ChangeRow("port_c_union_screw" "Screw-04")
    elseif port_c_size = 2.50 then
    iPart.ChangeRow("port_c_union_screw", "Screw-05")
    elseif port_c_size = 3.00 then
    iPart.ChangeRow("port_c_union_screw", "Screw-06")
    End If
    
    port_c_union_part_number = iProperties.Value("port_c_union", "Project", "Part Number")
  13. Click OK to close the dialog box.
  14. Save your assembly file.

Previous | Next