Rules and Forms in iLogic

The iLogic Browser lists iLogic rules, forms, global forms and external rules.

In the iLogic Browser, rules are arranged under two tabs:

Forms are arranged under two tabs:

Rules in iLogic

A rule is a small Visual Basic (VB.NET) program that can monitor and control other Inventor parameters, features, or components.

iLogic embeds rules as objects directly into part, assembly, and drawing documents. The rules determine and drive the design parameter and attribute values. By controlling these values, you can define the behavior of model attributes, features, and components.

Knowledge is saved and stored directly in the documents, like the way in which geometric design elements are stored.

Parameters in rules

You can use standard Inventor parameter names in rules as Visual Basic variables. When you run the rule, the value of the parameter is assigned to the variable. For a numeric parameter, the value is a real number expressed in the document units specified in Tools Document Settings. Text parameters become String variables in the rule. True/false parameters become Boolean variables.

Parameters can appear in two different ways:

  • VB.NET variables that are linked to numeric or non-numeric parameters. The variables are highlighted in blue:

    When a rule starts running, iLogic reads the values for these parameters from the model into the rule. When the rule has finished running, iLogic saves the changed values back to the model.

    To save the values before the rule has finished running, use the RuleParametersOutput function. This function is useful if you want to change the model immediately.

  • Parameters accessed using the Parameter function. For example:

    When you assign values using this method, the values are saved to the model immediately, before the next line in the rule runs. When you read a value using the Parameter function, it is immediately read from the Inventor model.

Default entity names in rules

Before you use one of the following Autodesk Inventor entity names in a rule, change its name if it was assigned a default name when it was created:

  • feature
  • sketch
  • work feature
  • pattern
  • constraint
  • iMate

Use a meaningful name. The name change makes it easier to see what the rule is doing.

Another reason to change default names is to make them more portable. In localized versions of Autodesk Inventor, default item names are translated to the language of that version. The names are automatically changed in the model browser, but not in an iLogic rule. Therefore, the rule may be unable to find items using the default name. If someone else uses the model in a different language version of Inventor, the default names must be changed. This recommendation applies only to items that are called out by name in the rule. For example, the Measure functions can use work feature names. If you have work features, but you do not use them in Measure functions, then you do not have to rename them.One exception to this recommendation is embedded Excel spreadsheets. Do not rename them.

On non-English versions of Autodesk Inventor, use an English name in the rule. For example:

"3rd Party:Embedding 1"
Note: Some entities such as iMates allow you to specify a name when you create them.

When rule runs

Rules usually run automatically in response to changes in parameter values, if the parameters are used directly as variables in the rule. You can also trigger rules by events.

A rule runs immediately after you edit it, unless it is suppressed. When rules run, changes in the parameters do not update the model until after the rule runs. If necessary, you can force parameter changes to take effect immediately using either:

  • the Parameter function
  • the RuleParametersOutput() function in the rule

Rule order

  • Rules are run in the order in which they appear in the browser, unless specified otherwise by inclusion of the iLogicVb.RunRule("ruleName") function.
  • If more than one rule references a parameter that changes, the rule that appears first in the list runs first. It happens regardless of how the parameter is changed.
  • You can use the Event Triggers command to change the rule order in the list associated with document events, independent of the main iLogic Browser list.

How rule is processed

When you create or edit a rule, the rule text is converted into valid VB.NET code and then compiled. Some Inventor parameter names are not valid as VB.NET variable names. To allow for the full range of Inventor parameter names, iLogic internally substitutes new variable names for the Inventor parameters.

Keywords used as parameter names

Although you can use Visual Basic keywords as parameter names, it is not recommended for new documents. However, when you add rules to existing documents, you usually do not have to change any parameter names. If a name is the same as a keyword, and you require that keyword in the rule, you can:

  • Change the Inventor parameter name, if possible (recommended).
  • Use the keyword in the rule, but with different letters capitalized. For example, use Class if the Inventor parameter is named class. Inventor parameter names are case-sensitive, but VB is not. In our example, class is replaced with another name before VB sees the code, but Class remains intact.

Internal conversion of rules

Rule text is converted internally to valid VB.NET code, which is not visible and is stored with the rule. This type of storage eliminates the need for iLogic to generate the code whenever the rule is run. The code only changes when you edit the rule.

The VB compiler error messages actually refer to this intermediate code. In rare cases with some complex code, you can receive an error that does not correspond to the rule code. When this situation occurs, simplify your code. If necessary, verify that you have a Sub Main() and End Sub statement.

When iLogic converts the rule to valid VB.NET code for compilation, it replaces units with conversion factors.

Units in rules

You can use Inventor units in rules in the same manner as they are used in standard Inventor parameter equations.

  • Rules do not require units. For example, suppose a number is assigned to a parameter that is not unitless, but no units are specified in the expression. In this case, iLogic assumes that the number uses the document units that conform to the parameter. This type of assumption also applies to compound units, such as mi/hr. Document units are set in Tools Document Settings Units in Inventor.
  • Unit names can only be used directly after numbers in the rule text. They cannot be used after parameters, variables, or expressions.

Example - document units

In this example, a part file uses document units of inches:

d0 = 4.5 in
d18 = 7.2 in
sum = d0 + d18MessageBox.Show(sum,”Document Units - Inches”)

Unless otherwise specified, iLogic assumes the units of the numbers are defined as the document units. In this case, the sum equals 11.7. A message box displays the value and indicates that the document units are expressed in inches.

To assign a value of 7.2 mm to the parameter d18, instead of 7.2 in, specify that d18 is expressed in millimeters:

d0 = 4.5 in
d18 = 7.2 mm
sum = d0 + d18
MessageBox.Show(sum,”Document Units - Inches”)

In this case, the sum equals 4.78346456692913. A message box displays the value and indicates that the Document Units are expressed in inches

To perform the previous calculation for a part file with document units expressed in millimeters, include the inch unit for any parameter expressed in inches (such as d0 = 4.5 in).

Finally, if you omit the unit of length from a statement, iLogic uses the Document Units value.

Example - mixed document units

In this example, a part file uses document units of inches. In the iLogic Parameter Editor:

  • parameter x is set to 1 in
  • parameter y is set to 12.5 mm

A rule has been written as:

result = x + y
MessageBox.Show(result,“Mixed Units Defined in Parameter Editor”)

When performing the addition, iLogic converts the value of parameter y from 12.5 mm to .4921 inches. A message box displays the value of 1.49212598425197 and indicates that mixed units are defined in the Parameter Editor.

Conversely, if the document units are defined as millimeters, then iLogic converts the value of parameter x from 1 in to 25.4 mm. A message box displays the value of 37.9 and indicates that mixed units are defined in the Parameter Editor.

Unit names

The unit specification is applied before any other mathematical operation is performed and has precedence over all other operators. Unit names:

  • Can be used only directly after numbers in the rule text.
  • Cannot be used after parameters, variables, or expressions.
  • Must include a space between the number and the unit.

The following are examples of valid use of unit names:

12 in
144 in
144 in^2
125.2 mm
60 mi/hr

You can use compound unit specifications in rules. Compound unit specifications follow the Inventor format. To incorporate a complicated unit specification into a rule, create an equation for it in the Parameters dialog box. Then, use Capture Current State on that parameter in the Rule Editor.

External rules

External rules can be used as iLogic rules, or as small programs that you run manually (like VBA macros). They are stored in text or VB files, outside of any Inventor document (part, assembly, or drawing). You can run them manually or from other rules.

When you view the list of external rules in the iLogic Browser, the list is the same for whatever document you have open. It is not tied to each individual document.

You can also run external rules as event-driven rules.

Wizards

iLogic provides several wizards you can use to create sophisticated rules for certain tasks. These wizards are available on the Wizards tab of the Edit Rule dialog box:

  • Create Rule for a Dialog - Use a custom dialog box to drive parameter values.
  • Capture Current View - Capture view orientation and zoom display values.
  • Message Box - Create a rule that displays a Windows message box.
  • Parameter Limits - Set minimum and maximum values for parameters.

Forms

Create and connect a custom user interface to the parameters, properties, and rules of an Inventor part, assembly or drawing document.

Use drag and drop methods to design a user interface with no need for programming. Use the controls to drive changes to an existing design. Form definitions can be document specific and saved with a design document or stored for use across multiple documents.

Note: It is not necessary to have rules to create forms.