inspection dimension table generator

inspection dimension table generator

Miguel.CarvajalS34Q6
Advocate Advocate
131 Views
0 Replies
Message 1 of 1

inspection dimension table generator

Miguel.CarvajalS34Q6
Advocate
Advocate

I have a problem with the generation of the tolerance dimension table. It is a customized table and the problem is that it does not take the real tolerance values, and it does not give me the value of the inspection frequency and I cannot get it to recognize the angles.

inspeccion.PNG

 I modified a code that I found in the forum that turned out to be very useful, but I still can't get it to work 100%.

 

Sub Main()
    Dim oDrawingDocument As DrawingDocument
    oDrawingDocument = ThisApplication.ActiveDocument

    Dim oSheet As Sheet
    oSheet = oDrawingDocument.ActiveSheet

    Dim oCustomTable As CustomTable
    Dim oCustomTables As CustomTables
    oCustomTables = oSheet.CustomTables

    ' Delete existing table if it exists
    For Each oCustomTable In oCustomTables
        If oCustomTable.Title = "INSTRUCCIONES DE CONTROL" Then
            oCustomTable.Delete()
        End If
    Next

    Dim oInspectionDimension As DrawingDimension
    Dim oInspectionDimensionText As DimensionText
    Dim oInspectionDimensionString As String
    Dim oCellInspectionDimension As Cell
    Dim oCellLimits As Cell
    Dim oCellIdentifier As Cell
    Dim oCellTolerance As Cell

    Dim oInspectionDimensionCount As Integer
    oInspectionDimensionCount = 0

    ' Count inspection dimensions
    For Each oInspectionDimension In oSheet.DrawingDimensions
        If oInspectionDimension.IsInspectionDimension Then
            oInspectionDimensionCount = oInspectionDimensionCount + 1
        End If
    Next

    ' Define table column titles
    Dim oColumnTitle(0 To 5) As String
    oColumnTitle(0) = "LÍMITES DE DIMENSIÓN"
    oColumnTitle(1) = "COTA NOMINAL"
    oColumnTitle(2) = "TOLERANCIA"
    oColumnTitle(3) = "IDENTIFICADOR"
    oColumnTitle(4) = "REFERENCIA"
    oColumnTitle(5) = "INSPECCIÓN %"

    ' Ensure that the table has 46 rows
    Dim rowsCount As Integer
    rowsCount = 46

    ' Create custom table with 46 rows and 6 columns
    Dim oFieldVerificationTable As CustomTable
    oFieldVerificationTable = oSheet.CustomTables.Add("INSTRUCCIONES DE CONTROL", _
    ThisApplication.TransientGeometry.CreatePoint2d(0.635, oSheet.Height - 0.635), 6, rowsCount, oColumnTitle)

    ' Adjust column widths
    Dim columnWidth As Double
    columnWidth = 3.16666 ' in mm
    For i As Integer = 1 To 6
        oFieldVerificationTable.Columns.Item(i).Width = columnWidth
    Next

    Dim oInspectionDimensionCount2 As Integer
    oInspectionDimensionCount2 = 0

    ' Populate the table with inspection dimension data
    For Each oInspectionDimension In oSheet.DrawingDimensions
        If oInspectionDimension.IsInspectionDimension Then
            oInspectionDimensionCount2 = oInspectionDimensionCount2 + 1
            oInspectionDimensionText = oInspectionDimension.Text
            oInspectionDimensionString = oInspectionDimensionText.Text

            ' Ensure symbols are properly recognized
            oInspectionDimensionString = Replace(oInspectionDimensionString, "n", ChrW(&H00D8)) ' Ø
            oInspectionDimensionString = Replace(oInspectionDimensionString, "R", "R")
            oInspectionDimensionString = Replace(oInspectionDimensionString, "°", "°")

            ' Assign values to table cells
            oCellInspectionDimension = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("COTA NOMINAL")
            oCellInspectionDimension.Value = oInspectionDimensionString

            ' Get inspection data
            Dim oInspDimShape As InspectionDimensionShapeEnum
            Dim oInspDimNumber As String
            Dim oInspDimRate As String
            Call oInspectionDimension.GetInspectionDimensionData(oInspDimShape, oInspDimNumber, oInspDimRate)

            ' Assign identifier to the table
            oCellIdentifier = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("IDENTIFICADOR")
            oCellIdentifier.Value = oInspDimNumber

            ' Check if it's an angle
            Dim isAngle As Boolean
            isAngle = InStr(oInspectionDimensionString, "°") > 0

            Dim formattedLimits As String
            Dim toleranceString As String

            If isAngle Then
                Dim nominalAngle As Double
                nominalAngle = CDbl(Replace(oInspectionDimensionString, "°", "")) ' Remove ° symbol
                Dim lowestAngle As Double
                Dim highestAngle As Double
                lowestAngle = nominalAngle - 2
                highestAngle = nominalAngle + 2
                formattedLimits = "(" & Format(lowestAngle, "0.00") & "° ÷ " & Format(highestAngle, "0.00") & "°)"
                toleranceString = "±2.00°"
            Else
                Dim nominalValue As Double
                nominalValue = oInspectionDimension.ModelValue * 10 ' Scale factor
                Dim upperTolerance As Double
                upperTolerance = oInspectionDimension.Tolerance.Upper * 10 ' Scale factor
                Dim lowerTolerance As Double
                lowerTolerance = oInspectionDimension.Tolerance.Lower * 10 ' Scale factor

                Dim lowestValue As Double
                Dim highestValue As Double
                lowestValue = nominalValue + lowerTolerance
                highestValue = nominalValue + upperTolerance

                ' Preserve Ø or R symbol
                Dim prefixSymbol As String
                If InStr(oInspectionDimensionString, ChrW(&H00D8)) > 0 Then
                    prefixSymbol = ChrW(&H00D8) ' Ø
                ElseIf InStr(oInspectionDimensionString, "R") > 0 Then
                    prefixSymbol = "R"
                Else
                    prefixSymbol = ""
                End If

                formattedLimits = "(" & prefixSymbol & Format(lowestValue, "0.00") & " ÷ " & prefixSymbol & Format(highestValue, "0.00") & ")"
                toleranceString = "+" & Format(upperTolerance, "0.00") & "/-" & Format(lowerTolerance, "0.00")
            End If

            ' Add limits and tolerance to the table
            oCellLimits = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("LÍMITES DE DIMENSIÓN")
            oCellLimits.Value = formattedLimits

            oCellTolerance = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("TOLERANCIA")
            oCellTolerance.Value = toleranceString
        End If
    Next

    iLogicVb.UpdateWhenDone = True
End Sub
0 Likes
132 Views
0 Replies
Replies (0)