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
Solved! Go to Solution.
Solved by dgreatice. Go to Solution.
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
Why would i get the Sub Main() error?
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.