Friday, December 30, 2011

Controlling Parameter and iProperty Values

We can use iLogic to help us enforce standards and other values I like to refer to as “tribal knowledge”. Having customized code trap errors in design to help prevent (or at least flag) those “freelance” design changes is a powerful and effective way of managing the expense of change at the earliest stages of the process and turning your 3D models into true knowledge assets.


In this example we have established the proper number of ribs needed for this model based on the material of the part and are enforcing them with a rule. We are also enforcing the overall size limits of the model so that the Length must be between 4” and 10” and the Width must fall between 2” and 3”. We’ll also have a rule that will enforce the increment value of Length and Width.




First, lets look at the code that will control the Ribs:

iProperties.StylesInEnglish = True
If (iProperties.Material.StartsWith("ABS")) Then
  HorizRibCount = 3
  HorizRibOffset = Width * 0.25
  HorizRibSpacing = Width * 0.25
  VerticalRibCount = 3
  VerticalRibOffset = Length * 0.25
  VerticalRibSpacing  = Length * 0.25
ElseIf (iProperties.Material.StartsWith("Nylon")) Then
  HorizRibCount = 2
  HorizRibOffset = Width * 1/6
  HorizRibSpacing = Width * 1/3
  VerticalRibCount = 2
  VerticalRibOffset = Length * 1/6
  VerticalRibSpacing = Length * 1/3
Else
  MessageBox.Show("The Ribs rule is not ready for this material." + vbCr + _
  "Please select either ABS or Nylon," + vbCr + _
  "or modify the Ribs rule to support " + iProperties.Material, "Ribs Rule")
End If

iLogicVb.UpdateWhenDone = True


You might not be familiar with the first line but it is a handy setting. This function supports the use of the same document in different language versions of Autodesk Inventor. Your model is more portable when you use English names for materials and colors in your rules. If you set this function to True, then any function that returns any material or color names returns the names in English. You can use names in the language of your Autodesk Inventor installation to set a material or color name. But it is recommended that you use English names for consistency. The following functions return names in English when you set the iProperties.StylesInEnglish value to True:

  • iProperties.Material
  • iProperties.MaterialOfComponent
  • iProperties.Materials
  • iProperties.PartColor
  • Feature.Color
  • Component.Color
The body of the code will determine the rib dimensions based on the material type. Any material iProperty that starts with “ABS” or “Nylon” is recognized allowing you have a family of these material types that will work in this code. If a material does not match then a dialog box will fire and warn you to make sure you update the code for the new material. The last line updates the model (same as the update button).
The next rule exams the value for length and width. If they are out of the specified range the value is trapped and returned to the minimum or maximum value allowed.

' ******* Length Limits *******
If Length < 4
  Length = 4
  MessageBox.Show("The minimum value allowed for this parameter is:  " & Length & vbCr & "The value will be automatically corrected to the minimum.", "Minimum Value Rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf Length > 10 Then
  Length = 10
  MessageBox.Show("The maximum value allowed for this parameter is: " & Length & vbCr & "The value will be automatically corrected to the maximum.", "Maximum Value Rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If

' ******* Width Limits *******
If Width < 2
  Width = 2
  MessageBox.Show("The minimum value allowed for this parameter is:  " & Width & vbCr & "The value will be automatically corrected to the minimum.", "Minimum Value Rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
ElseIf Width > 3 Then
  Width = 3
  MessageBox.Show("The maximum value allowed for this parameter is: " & Width & vbCr & "The value will be automatically corrected to the maximum.", "Maximum Value Rule", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If



Note: Use the “Parameter Limits” wizard in the iLogic rules editor to facilitate writing this type of rule.
Finally we have a rule the also examines the values of length and width and will make sure they are rounded to the nearest increment specified in the variable “inc”

inc = .25 ' rounding increment ( .125, .25, .5, etc)
Length = Round(Round(Length,4) / inc) * inc

inc = .125 ' rounding increment ( .125, .25, .5, etc)
Width = Round(Round(Width,4) / inc) * inc



The user has a lot of freedom to use this model in their designs, but only within the boundaries specified within the code, capturing “tribal knowledge” and enforcing built in standards.

Download the sample here and use the form to make some changes the the size. (Try changing the material iProperties too!)

2 comments:

  1. Awesome post. Where did you find the reference to I properties.StylesInEnglish? Could be very handy

    ReplyDelete
  2. Why thank you Capt T! A tech support call actually prompted the requirement as he was sharing data with overseas stakeholders and running into problems. I can't remember where I actually found the code but it has been something I have included whenever iLogic is referring to styles that may need to be clarified!

    ReplyDelete