Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

INSPECTION TABLE

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
37xitp4
422 Views, 2 Replies

INSPECTION TABLE

Hi,

 

I have work on this code to generate the inspection dimension into a custom table.

I have an issue to get the tolerance value based on "ToleranceTypeEnum Enumerator"
I have set it using case statement but still can't get the correct value

 

 

Public Sub InchInspectionTable()

'SET A REFERENCE TO THE ACTIVATE DRAWING
    Dim oDrawDoc As DrawingDocument
    Set oDrawDoc = ThisApplication.ActiveDocument
    
'SET REFERENCE TO THE ACTIVATE SHEET
    Dim oSheet As Sheet
    Set oSheet = oDrawDoc.ActiveSheet
    
'REMOVE EXISTING CUSTOM TABLE
    If oSheet.CustomTables.Count > 0 Then
    oSheet.CustomTables.Item(1).Delete
    End If

'CREATE CUSTOM TABLE
    Dim CustomTableTitle As String
    CustomTableTitle = "INSPECTION DIMENSIONS" 'Set the Table title
    
    Dim oTitles(1 To 4) As String 'set number of column
    oTitles(1) = "INSPECTION LABEL" 'Set the table header 1
    oTitles(2) = "DESIGNED DIMENSION" 'Set the table header 2
    oTitles(3) = "UPPER TOLERANCE" 'Set the table header 3
    oTitles(4) = "LOWER TOLERANCE" 'Set the table header 4
    
    Dim InsP As Point2d
    Set InsP = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)

    oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.HeadingGap = 0.125
    oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.ColumnValueHorizontalJustification = kAlignTextCenter

    Dim oGenDimCount As Integer
    oGenDimCount = 0
    Dim oDim As DrawingDimension
    For Each oDim In oSheet.DrawingDimensions
        If oDim.IsInspectionDimension Then
            oGenDimCount = oGenDimCount + 1
        End If
    Next
    
    Debug.Print "Inspection Dims Count = " + CStr(oGenDimCount)
    Debug.Print "Drawing Dims Count = " + CStr(oSheet.DrawingDimensions.Count)
    
    Dim oCustomTable As CustomTable
    Set oInspDimTable = oSheet.CustomTables.Add(CustomTableTitle, InsP, 4, oGenDimCount, oTitles)
    
'SET THE VALUE OF THE TABLE
    Dim oInspDimShape As InspectionDimensionShapeEnum
    Dim oDesignedDimension As Variant
    Dim oAngularDesignedDimension As Variant
    Dim oInspDimNumber As String
    Dim oInspDimRate As String
    Dim i As Integer
    Dim oCellInspDimNum As Cell
    Dim oCellInspDim As Cell
    Dim oCellInspUpTol As Cell
    Dim oCellInspLowTol As Cell
    
    i = 1
    For Each oDim In oSheet.DrawingDimensions
        If oDim.IsInspectionDimension And oDim.Type = 117474560 Or oDim.IsInspectionDimension And oDim.Type = 117475072 Or oDim.IsInspectionDimension And oDim.Type = 117475328 Then 'Linier Dimension
            oDim.GetInspectionDimensionData oInspDimShape, oInspDimNumber, oInspDimRate

            oDesignedDimension = ThisApplication.UnitsOfMeasure.GetStringFromValue(oDim.ModelValue, 11272)
                
            Debug.Print oInspDimNumber
            Debug.Print oDesignedDimension
            Debug.Print "Tolerance type = " + CStr(oDim.Tolerance.ToleranceType)
            Debug.Print "Tolerance Upper = " + CStr(oDim.Tolerance.Upper)
            Debug.Print "Tolerance Lower = " + CStr(oDim.Tolerance.Lower)
            Debug.Print "Tolerance Precision = " + CStr(oDim.TolerancePrecision)
            Debug.Print ""
                
            Set oCellInspDimNum = oInspDimTable.Rows.Item(i).Item("INSPECTION LABEL")
            oCellInspDimNum.Value = oInspDimNumber
                
            Set oCellInspDim = oInspDimTable.Rows.Item(i).Item("DESIGNED DIMENSION")
            oCellInspDim.Value = oDesignedDimension
                
                Select Case Tolerance
                
                    Case Is = oDim.Tolerance.ToleranceType = 31236 'Deviation Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "A"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "B"
                
                    Case Is = oDim.Tolerance.ToleranceType = 31238 'Limit Linear Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "C"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "D"
                    
                    Case Is = oDim.Tolerance.ToleranceType = 31242  'Limits/Fits-Linear Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "E"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "F"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31243 'Limits/Fits-Show Size Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "G"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "H"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31244  'Limits/Fits-Show Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "I"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "J"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31241 'Limits/Fits-Stacked Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "K"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "L"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31237 'Limits-Stacked Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "M"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "N"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31239 'MAX Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "O"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "P"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31240 'MIN Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "Q"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "R"
                        
                    Case Is = oDim.Tolerance.ToleranceType = 31235 'Symmetric Tolerance
                        Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
                        oCellInspUpTol.Value = "S"
                        
                        Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
                        oCellInspLowTol.Value = "T"
                    End Select
            i = i + 1
        End If
    Next
    
    oInspDimTable.Sort "INSPECTION LABEL", True
    Dim oRow As Row
    For Each oRow In oInspDimTable.Rows
        If oCellInspDimNum.Value <> oInspDimNumber Then
            oRow.Delete
        End If
    Next
    
End Sub

 

 

 

2 REPLIES 2
Message 2 of 3
dgreatice
in reply to: 37xitp4

updated you code:

Public Sub InchInspectionTable()

'SET A REFERENCE TO THE ACTIVATE DRAWING
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

'SET REFERENCE TO THE ACTIVATE SHEET
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

'REMOVE EXISTING CUSTOM TABLE
If oSheet.CustomTables.Count > 0 Then
oSheet.CustomTables.Item(1).Delete
End If

'CREATE CUSTOM TABLE
Dim CustomTableTitle As String
CustomTableTitle = "INSPECTION DIMENSIONS" 'Set the Table title

Dim oTitles(1 To 4) As String 'set number of column
oTitles(1) = "INSPECTION LABEL" 'Set the table header 1
oTitles(2) = "DESIGNED DIMENSION" 'Set the table header 2
oTitles(3) = "UPPER TOLERANCE" 'Set the table header 3
oTitles(4) = "LOWER TOLERANCE" 'Set the table header 4

Dim InsP As Point2d
Set InsP = ThisApplication.TransientGeometry.CreatePoint2d(15, 15)

oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.HeadingGap = 0.125
oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.ColumnValueHorizontalJustification = kAlignTextCenter

Dim oGenDimCount As Integer
oGenDimCount = 0
Dim oDim As DrawingDimension
For Each oDim In oSheet.DrawingDimensions
If oDim.IsInspectionDimension Then
oGenDimCount = oGenDimCount + 1
End If
Next

Debug.Print "Inspection Dims Count = " + CStr(oGenDimCount)
Debug.Print "Drawing Dims Count = " + CStr(oSheet.DrawingDimensions.Count)

Dim oCustomTable As CustomTable
Set oInspDimTable = oSheet.CustomTables.Add(CustomTableTitle, InsP, 4, oGenDimCount, oTitles)

'SET THE VALUE OF THE TABLE
Dim oInspDimShape As InspectionDimensionShapeEnum
Dim oDesignedDimension As Variant
Dim oAngularDesignedDimension As Variant
Dim oInspDimNumber As String
Dim oInspDimRate As String
Dim i As Integer
Dim oCellInspDimNum As Cell
Dim oCellInspDim As Cell
Dim oCellInspUpTol As Cell
Dim oCellInspLowTol As Cell

i = 1
For Each oDim In oSheet.DrawingDimensions
If oDim.IsInspectionDimension And oDim.Type = 117474560 Or oDim.IsInspectionDimension And oDim.Type = 117475072 Or oDim.IsInspectionDimension And oDim.Type = 117475328 Then 'Linier Dimension
oDim.GetInspectionDimensionData oInspDimShape, oInspDimNumber, oInspDimRate

oDesignedDimension = ThisApplication.UnitsOfMeasure.GetStringFromValue(oDim.ModelValue, 11272)

Debug.Print oInspDimNumber
Debug.Print oDesignedDimension
Debug.Print "Tolerance type = " + CStr(oDim.Tolerance.ToleranceType)
Debug.Print "Tolerance Upper = " + CStr(oDim.Tolerance.Upper)
Debug.Print "Tolerance Lower = " + CStr(oDim.Tolerance.Lower)
Debug.Print "Tolerance Precision = " + CStr(oDim.TolerancePrecision)
Debug.Print ""

Set oCellInspDimNum = oInspDimTable.Rows.Item(i).Item("INSPECTION LABEL")
oCellInspDimNum.Value = oInspDimNumber

Set oCellInspDim = oInspDimTable.Rows.Item(i).Item("DESIGNED DIMENSION")
oCellInspDim.Value = oDesignedDimension

Select Case oDim.Tolerance.ToleranceType

Case kDeviationTolerance 'Deviation Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "A"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "B"

Case kLimitLinearTolerance 'Limit Linear Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "C"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "D"

Case kLimitsFitsLinearTolerance 'Limits/Fits-Linear Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "E"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "F"

Case kLimitsFitsShowSizeTolerance 'Limits/Fits-Show Size Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "G"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "H"

Case kLimitsFitsShowTolerance 'Limits/Fits-Show Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "I"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "J"

Case kLimitsFitsStackedTolerance 'Limits/Fits-Stacked Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "K"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "L"

Case kLimitsStackedTolerance 'Limits-Stacked Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "M"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "N"

Case kMaxTolerance 'MAX Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "O"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "P"

Case kMinTolerance 'MIN Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "Q"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "R"

Case kSymmetricTolerance 'Symmetric Tolerance
Set oCellInspUpTol = oInspDimTable.Rows.Item(i).Item("UPPER TOLERANCE")
oCellInspUpTol.Value = "S"

Set oCellInspLowTol = oInspDimTable.Rows.Item(i).Item("LOWER TOLERANCE")
oCellInspLowTol.Value = "T"
End Select
i = i + 1
End If
Next

oInspDimTable.Sort "INSPECTION LABEL", True
Dim oRow As Row
For Each oRow In oInspDimTable.Rows
If oCellInspDimNum.Value <> oInspDimNumber Then
oRow.Delete
End If
Next

End Sub

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 3 of 3
rom.poteaux4DZ5Y
in reply to: 37xitp4

Why would i get the Sub Main() error?

rompoteaux4DZ5Y_0-1680783434914.png

i'm in inventor 2023 and in text file for my external rules. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report