Wednesday, June 29, 2011

Using iLogic to Find Dimension Overrides

Issue:
You'd like to be able to quickly identify dimension overrides in your Inventor drawings using iLogic.



Solution:
( Note that I've added an improved version of this rule at the end of this post in the Edit section)

You can use iLogic to toggle the color of the text for all overridden dimensions, making it easy to spot them.

To use this iLogic code you can hold the Shift key and right click and then choose the Select all Inventor Dimensions from the menu, or you can simply window select all of the objects in the drawing and let the iLogic filter for only the dimensions.



Once the items to check are pre-selected you can run the iLogic rule and the text of any dimensions that are "fudged" will be set to magenta:




Any dimension found to have the Hide Dimension Value check box selected will be targeted by the rule:


Dimension found to have the Override Displayed Value check box selected will be targeted by the rule also:


You can then run a second rule to set the colors back, if needed: 
One thing to know about the second rule as it is currently written, is that it sets the color back to black (RGB value 0,0,0) rather than back to ByLayer. This could lead to problems if you're not aware of this.


 
 According to the API help file and this link, you should be able to set text to ByLayer by setting ColorSourceType = kLayerColorSource
but I was not able to get this to work in the iLogic code.

Here is the first rule, used to identify the overrides:


'-------------Start of ilogic ------------------------------------------------
' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'Dim oColor As Inventor.Color
Dim oColor As Color
'(255,0,255) = magenta
oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 255)

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims() As DrawingDimension

a = 0
Dim i As Long
For i = 1 To oDoc.SelectSet.Count
            If Not oDoc.SelectSet.Item(i) Is Nothing Then
                   If TypeOf oDoc.SelectSet.Item(i) Is DrawingDimension Then
                   a = a + 1
                   ReDim Preserve oDrawingDims(0 To a)
                   oDrawingDims(a) = oDoc.SelectSet.Item(i)
                   End If
          End If
Next

For b = 1 To a
            if oDrawingDims(b).HideValue = True _
            or oDrawingDims(b).ModelValueOverridden = True then
          oDrawingDims(b).Text.Color = oColor

            Else
          End if
Next
'-------------end of ilogic ------------------------------------------------


 
Here is the second rule, used to set the color back to black:


'-------------Start of ilogic ------------------------------------------------
' Set a reference to the select set of the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'Dim oColor As Inventor.Color
Dim oColor As Color
'(0,0,0) = black
oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0)

' Find all selected occurrences and add them to an ObjectCollection.
Dim oDrawingDims() As DrawingDimension

a = 0
Dim i As Long
For i = 1 To oDoc.SelectSet.Count
            If Not oDoc.SelectSet.Item(i) Is Nothing Then
                   If TypeOf oDoc.SelectSet.Item(i) Is DrawingDimension Then
                   a = a + 1
                   ReDim Preserve oDrawingDims(0 To a)
                   oDrawingDims(a) = oDoc.SelectSet.Item(i)
                   End If
          End If
Next

For b = 1 To a
            if oDrawingDims(b).HideValue = True _
            or oDrawingDims(b).ModelValueOverridden = True then
          oDrawingDims(b).Text.Color = oColor
            Else
          End if
Next
'-------------End of ilogic ------------------------------------------------







*** Edit ***
(July 5, 2011) 
Here is an improved version of the previous rule(s). In this version the user doesn't need to pre-select the drawing dimension. Instead the rule iterates through all of the dimensions in the the active drawing sheet. Additionally, the two previous rules have been combined and the user selects between the two options via a radio button input box.
 And lastly, this rule sets the text color back to the ByLayer color by using the line:
oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
A big Thank You to Mike Deck at Autodesk for the help with the kLayerColorSource enumeration and other suggestions to improve this rule.

Here is the improved code:
'-------------Start of ilogic ------------------------------------------------
' Set a reference to the active document.
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument

'Define the drawing dims collection
Dim oDrawingDims As DrawingDimension

'Dim oColor As Inventor.Color
Dim oColor As Color

'Prompt user to choose highlight / un-highlight
Dim booleanParam as Object
booleanParam = InputRadioBox("Select an Option", _
"Hightlight Overrides", "Un-Hightlight Overrides", True, Title := "iLogic")

'Loop through all dimensions and set colors
For Each oDrawingDims In oDoc.ActiveSheet.DrawingDimensions
   If booleanParam = True then
   'set color to magenta
   oColor = ThisApplication.TransientObjects.CreateColor(255, 0, 255)
   else
   'set color to black
   oColor = ThisApplication.TransientObjects.CreateColor(0, 0, 0)
   oColor.ColorSourceType = ColorSourceTypeEnum.kLayerColorSource
   end if
  
   if oDrawingDims.HideValue = True _
   or oDrawingDims.ModelValueOverridden = True then
   oDrawingDims.Text.Color = oColor
   Else
   End if
Next
'-------------End of ilogic ------------------------------------------------