Work with rules in iLogic

Create rule

Before you create a rule, create any parameters that you want to include in the rule.

  1. On the ribbon, click Manage tab iLogic panel Add Rule .
  2. In the Rule Name dialog box, enter the name of the new rule, and click OK.
  3. Use the Edit Rule dialog box to define the rule.
    • In a part or drawing document, click a parameter group to display that list of parameters in the Parameters tab on the right. Then, double-click a parameter in the list to insert that name into the rule text.

      In an assembly document, select the 3D Model tab to display the assembly components, or select the File Tree tab to display the subassembly and part files. Expand a part file item to display the parameters and features within that file.

      Note: When you click a non-parameter item in the Model tree, its name is listed under the Names tab (next to the Parameters tab). You can double-click an item in this list to insert the name into the rule. Many of the Drawing snippets require a view name. Double-clicking on the appropriate item in the list can provide you with a view name from the current drawing for inclusion into the rule.
    • Right-click on an item, and select Capture Current State to insert text into the rule that assigns values to the item.

      For example, capture the current state of a parameter to insert the parameter and its current value, such as d0 = 4.0 in.

      Parameters are always captured with their units, but units are not required when you write new equations. You can right-click on a parameter group to capture the state of all parameters of a specific type. You can also right-click on a feature or component to capture its current IsActive state (suppressed or unsuppressed).

    • Use the snippets listed under the System and Custom tab in the Snippets area to add functions which can then be customized for the rule. Double-click a snippet to add it to the rule.
    • Use the choices on the editing toolbar above the rule text area to manipulate the appearance of the rule. You can also use the choices to insert conditional statements, keywords, and operators.
  4. Click OK to save the rule.

Edit rule

  1. On the ribbon, click Manage tab iLogic panel iLogic Browser if the browser is not currently displayed.
  2. In the iLogic Browser, click the Rules tab to edit a rule in the open document. Or, click the External Rules tab to edit a rule for the component that is in an external file.
  3. Double-click the rule, or right-click and select Edit Rule from the context menu.
  4. Use the Edit Rule dialog box to edit the rule. As you enter text, the appropriate color coding is applied to your text for readability.
  5. Click OK when finished.

Rename rule

To rename a rule, click twice slowly (two discrete clicks) on the name in the iLogic Browser to enable editing, and then change the existing name.

Insert rule syntax

Use the drop-down lists on the toolbar above the rule text area within the Edit Rule dialog box to insert syntax strings into a rule, instead of entering the syntax manually. Once inserted, you can customize the strings as necessary. Choices are available for:

  • conditional statements
  • keywords
  • operators

To insert a string:

  1. Position the cursor at the destination in the rule.
  2. Select the string from one of the drop-down lists. The string is inserted using the appropriate color coding for readability.
  3. Edit the inserted string as necessary.

Insert code snippet in rule

Use the choices in the Snippets area of the Edit Rule dialog box to insert code snippets in a rule. You can then modify the inserted snippet as necessary.

  1. Position the cursor in the rule text area at the point of insertion.
  2. Click the System or Custom tab in the Snippets area to display the available categories for that tab.
  3. Double-click a snippet to insert it at the cursor location. Each component of the snippet, such as conditional text, functions, and placeholders for variables and parameters, is color-coded for readability.
  4. Edit the inserted snippet.

Work with collapsible code regions in rules

Create collapsible code regions and comments

Define collapsible code regions and comments to reduce clutter in the rule text area.

Code region

  • Insert a single quote, followed by a left square bracket, to identify the beginning of a collapsible code region. Use a single quote, followed by a right square bracket, to indicate the end of the collapsible region.
  • Click the node icon (-) to collapse the code.

Comment

  • Insert three single quotes at the beginning of a line to define it as a collapsible comment. If the comment spans multiple lines, insert three single quotes at the beginning of each line.
  • Click the node icon (-) to collapse the comment.

Manipulate outlining of collapsible code regions and comments

Use the following context menu choices in the rule text area to work with collapsible code regions and comments:

  • Right-click, then select OutliningToggle Outlining Expansion to toggle the expansion of the code region or comment at the cursor location.
  • Right-click, then select OutliningToggle All Outlining to toggle the expansion of all collapsible code regions and comments in the rule.
  • Right-click, then select OutliningStop Outlining to disable all outlining capabilities and expand any collapsed code regions or comments. The outlining tree is also removed from display. To enable outlining capabilities, right-click and select OutliningStart Automatic Outlining.

Prevent rule from running automatically

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the Suppressed check box.
  4. Click OK.
    Note: You can run a suppressed rule manually. You can also suppress a rule in the iLogic Browser.

Run rule without displaying Inventor dialog boxes

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the Silent Operation check box.
  4. Click OK.

Run dependent rules immediately when referenced parameters change value

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the check box labeled Fire dependent rules immediately.
  4. Click OK.
    Note: By running dependent rules immediately, you can include explicit model updates after you set the parameters. At the time of update, the parameters have changed and the dependent rules have run.

Prevent rule from running when parameters change

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the check box labeled Don’t run automatically.
  4. Click OK.
    Note: If this option is selected, you can only run the rule manually, or with event triggers, or with iLogicVB.RunRule.

Share code between rules

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the check box labeled Straight VB code.
  4. Click OK.

iLogic does not pre-process the code in a rule identified as Straight VB code; therefore, Inventor parameter names are not recognized in the rule. The rule should contain Classes or Modules that can be called from other rules. Use this option to share code between rules, or as a way to keep code modular. However, note that shared code is more difficult to write.

Choose alternative font style and size for Rule Editor

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Click Select Font.
  4. Choose a Font and Size. The Sample text box displays the results of your selections.
  5. Click OK.

Select syntax for Capture Current State option

This option affects only assemblies, when Capture Current State is used on a parameter in a component within the assembly:

  1. Open the rule in the Rule Editor.
  2. Select the Options tab.
  3. Select the Use component names checkbox to include component names (for example, Parameter("PartA:1", "d0") = 5.6 in) as part of the syntax. This choice is recommended for portability.

    Alternatively, clear the checkbox to exclude the component names (for example, PartA.ipt.d0 = 5.6 in).

  4. Click OK.
    Note: You can insert a parameter into a rule by clicking its name while creating rules at the assembly level. If you later change the component name to something other than its original filename, using parameter syntax makes it easier to find the component.

Run rules

To run a rule manually, right-click on the rule in the iLogic Browser, and select Run Rule from the context menu.

To ensure that the parameters in the rule are synchronized with the model, select Regenerate Rule from the context menu before running the rule.

To run another rule explicitly within a rule, use the iLogicVb.RunRule function.

Reorder tree in iLogic Browser

Drag and drop any rule in the iLogic Browser to change its order in the tree. Any rule at or below the rule you drop moves down in the tree.

Regenerate rule

To synchronize the parameters in a specific rule with your model.

  1. Select the rule in the iLogic Browser.
  2. Right-click, and select Regenerate Rule from the context menu.

This command reconnects the rule to Inventor parameters, recompiles the rule, and then runs it.

Regenerate all rules in current document

Use this command to synchronize the parameters in all rules with your model.

  1. Select the document in the iLogic Browser.
  2. Right-click, and select Regenerate All Rules from the context menu.

Alternatively, you can use the Regenerate All Rules command on the ribbon. Select Manage tab iLogic panel Regenerate All Rules .

Delete rule

  1. On the ribbon, click Manage tab iLogic panel iLogic Browser .
  2. Right-click on the rule, and select Delete from the context menu.
  3. Click OK when prompted to confirm your selection.

Delete all rules in document

Use this command when you have finished configuring the model and want to save or export a sample configuration. All rules are removed.

Note: If you run this command in an assembly, all rules in the subassemblies and parts are also deleted.

Work with external rules

Create external rule

The iLogic Browser includes a tab for external rules. From this tab, you can load an external rule or create a new one.

To make an existing rule external:

  1. Open the rule.
  2. Copy the code.
  3. Create a new external rule, and paste the code into the new rule.

Save external rules as .iLogicVb files (this extension is recommended), or as .vb or .txt files. Save external rules to a folder that can be found when running them from another rule. iLogic looks for external rule files in the following folders, in the order listed:

  • The folder in which the current Inventor document is located (allows models to be copied with associated rules)
  • The current Inventor Project Workspace folder
  • The list of folders set in iLogic Configuration (generally for work group or company rules)

The iLogic Browser provides a context menu for the top node (External Rules in Files) and for each rule in the tree.

Create external rule icon

You can include an icon for an external rule that displays in the iLogic Browser. Create a .bmp file (size 16 X 16 is recommended) with the same name as the rule file, in the same folder.

For example, if your external rule is named Custom Checks Rule.iLogicVb, name the icon file as Custom Checks Rule.bmp.

After you create the bitmap image, restart Autodesk Inventor to display the icon. You cannot edit the icon while Autodesk Inventor is running.

Edit external rule

To edit an external rule, open the Edit Rule dialog box, and double-click the rule in the tree to edit it.

You can also use an external program such as Notepad to edit a rule. After you save it, use Reload From File from the context menu in the tree to bring the changes into Inventor.

External rules and parameters

External rules do not run automatically in response to particular parameter changes. Unlike internal rules, parameter names are not automatically available as rule variables.

For example, the following rule statement does not work:

d1 = d0 * 0.5

Instead, use the following:

Parameter("d1") = Parameter("d0") * 0.5

This statement works on any part or assembly with parameters named d0 and d1. It can be used to operate on related parts that share something in common.

Use wizards to create special rules

Attention: Use the iLogic Form Designer to create custom user interface forms. The user interface can contain controls to trigger rules, change parameter values, and set iProperties. iLogic Form Designer does not require any programming. Use Visual Basic to design and program a form when the user interface needed is beyond the capabilities of iLogic Form Designer.

Control dialog box based on model parameters

  1. Click Create Rule for a Dialog on the Wizards tab of the Edit Rule dialog box.

    The Open DLL File dialog box displays the contents of the iLogicAdd folder, which contains previously created DLL files.

    Note: You may need to create the iLogicAdd folder as C:\Program Files\Autodesk\Inventor {version}\Bin\iLogicAdd.
  2. Select a DLL to populate the Rule for External DLL dialog box with the appropriate class and variable names.
  3. Click OK to generate the code.

Capture current display view

  1. Click Capture Current View on the Wizards tab of the Edit Rule dialog box.
  2. Select a Size Option from the Capture View dialog box.
    • Save and Restore current view extents - Restores the view to the orientation and zoom settings from when the rule captured the view.
    • Don’t change view size on restore - Moves the model to the center of the display and sets the orientation, but does not change the zoom.
    • Fit to model extents on restore - Moves the model to the middle of the display and fills the display (same as Zoom All).
  3. Click OK to generate the code.

Generate message box

Use this wizard to create a rule that generates a message box.

  1. Click Message Box on the Wizards tab of the Edit Rule dialog box.
  2. Enter the Title to appear at the top of the message box.
  3. Select the combination of buttons to appear on the message box.
  4. Indicate the default button by selecting the number that corresponds to its relative placement in the order, based on the Buttons selection.

    For example, if you have chosen YesNoCancel as your button scheme, and your default button is No, select 2.

  5. Select a status Icon to be displayed in the message box.
  6. Enter the text to be displayed in the message box, surrounded by quotes.
  7. Click Preview to display the message box using your selections.
  8. Click OK to generate the code.

Display diagnostic information when parameter values fall outside specified range

  1. Click Parameter Limits on the Wizards tab of the Edit Rule dialog box.
  2. Enter the Name of the parameter.
  3. Specify the maximum and minimum values.
  4. Enter the message Title and message text to display for violations of the maximum and minimum values.
  5. Click Apply to generate the code, or click Default Message to reset the messages to their default text.

Use rule to display dialog box

You can use a rule to display a dialog box for user input. The dialog box can be contained in the rule; however, it is easier and more flexible to include it in an external DLL (class library).

Use Visual Studio version 2005 or 2008. Visual Basic Express is available as a free download from Microsoft.

Get started with Visual Basic 2008

  1. Download and install Visual Basic 2008 Express from the Microsoft® web site if it is not already installed on your computer. The download is free.
  2. Open Visual Basic 2008 Express, and create a project of type Class Library.
  3. Name the project ClassLibrary1 (the default name), and click OK. Write the name on a piece of paper exactly as you have typed it. This name is important later in these instructions.

    A new window displays, with the Solution Explorer in the top right corner.

  4. In the Solution Explorer, right-click the project name and select Add, then select New Item from the submenu. The Add New Item dialog box displays.
  5. Select the Dialog template, and click Add.

    A graphical view of your dialog box displays in the Windows Form Designer. You can use this interface to add controls to your dialog box.

    The ToolBox on the left side of the screen lists the controls that you can add to the dialog box. For this project, you add a TextBox to show the value of an Inventor parameter and allow you to edit that parameter.

  6. Click and drag TextBox from the Common Controls group of the ToolBox panel to the dialog box, and place it in the gray area of the dialog box. You can resize the dialog box as required.
  7. Add a Label for the TextBox to show the parameter name.
  8. Being careful to avoid the Label and the TextBox, double-click the dialog box background to display the code editor. The following code displays.
  9. Move your cursor immediately below the line-
    Public Class Dialog1
  10. Add this line -
    Public d0 As Double
  11. Position your cursor at the top of subroutine OK_Button_Click, in front of the Me.DialogResult... statement, and press Enter to add a new line.
  12. On the new line, add -
    d0 = TextBox1.Text

    Your code looks like -

  13. Save your work using File Save or, alternatively, File Save All.

    You are almost ready to build the project. When you perform the build operation, Visual Basic creates a DLL file. You can specify where Visual Basic creates this file by modifying the output path for the build operation.

  14. Click the tab with the project title on it, and click the Compile tab again. The output path is -

    Program Files\Autodesk\Inventor {version}\Bin\iLogicAdd\

  15. To build the project, click the Build tab in the menu at the top. If the build proceeds without problems, the message Build succeeded displays in the status bar in the bottom left corner of the screen.
  16. Save your work again using Save All, and open Inventor.
  17. Use Add Rule to create a rule named Form Rule that consists of the following -.
    AddReference "ClassLibrary1"
    Sub Main()
    dim dlg as new ClassLibrary1.Dialog1
    dlg.d0 = d0
    i = dlg.ShowDialog()
    if (i = vbOK)then
    d0 = dlg.d0
    end if
    End Sub
    Note: You can also use Create Rule for a Dialog on the Wizards tab in the Edit Rule dialog box to create this code.

    This rule sends the current value of the Inventor parameter d0 to the dialog box, then shows the dialog box. The person using the dialog box can edit the value in the dialog. When this person clicks OK, the value from the dialog is assigned back to the parameter.

Create dialog box

To create a dialog box that enables you to display and modify some parameter values:

  1. Open Visual Studio.
  2. Create a project of type Class Library.
  3. In the Solution Explorer, right-click on the project name, and select Add New Item Dialog.

    A graphical view of your dialog box displays in the Windows Form Designer. You can use this interface to add controls to your dialog box.

  4. Click View Toolbox to preview the available controls.
  5. Add the TextBox control if you want the ability to display the value of an Inventor parameter and edit it. Add a Label for each Textbox to display the parameter name.
  6. Double-click the dialog box background.

    The code editor displays in a new subroutine named Dialog1_Load.

  7. In this subroutine, add this line before the end of the subroutine -
    TextBox1.Text = d0
  8. Move your cursor below the line -
    Public Class Dialog1
  9. Add this line -
    Public d0 As Double
  10. At the top of the subroutine named OK_Button_Click, add this line -
    d0 = TextBox1.Text

    Your code now looks like -

    Imports System.Windows.Forms
    Public Class Dialog1
    Public d0 As Double 
    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click  
      d0 = TextBox1.Text
      Me.DialogResult = System.Windows.Forms.DialogResult.OK
      Me.Close()
    End Sub
    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
      Me.DialogResult = System.Windows.Forms.DialogResult.Cancel  
      Me.Close()
    End Sub
    Private Sub Dialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       TextBox1.Text = d0
    End Sub
    End Class
  11. Build the project and save it using File Save All.

A DLL is created when the project is built. You can either:

  • Copy the DLL to the iLogicAdd directory, which is located under the Autodesk Inventor program bin directory (usually in C:\Program Files\Autodesk\Inventor {version}\Bin\iLogicAdd).
  • Change the project settings to send the DLL to that directory automatically. Use the iLogic Configuration command to change the directory where iLogic looks for the DLL. See “Expanding iLogic capabilities” for more information on using DLL files in rules.

The following sample rule uses the dialog box:

AddReference "ClassLibrary1"
Sub Main()
dim dlg as new ClassLibrary1.Dialog1
dlg.d0 = d0
i = dlg.ShowDialog()
if (i = vbOK) then
d0= dlg.d0
end if
End Sub

This rule sends the current value of the Inventor parameter d0 to the dialog box, and then shows the dialog box. The person using the dialog box can edit the value in the dialog box. If that person clicks OK, the value from the dialog box is assigned back to the parameter.

You can generate similar code for a dialog box automatically. On the Edit Rule dialog box, select the Wizards tab, and then select Create Rule for a Dialog.