メッセージ1/8
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- パーマリンクを表示
- 印刷
- 報告
Hello, I need help with a code.
I derive all inspection dimensions into a table.
If the date identifier is K4 as an example, this should also be extracted in column 1. Unfortunately I can't manage this at the moment.
Code:
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 = "FIELD VERIFICATION DIMENSIONS" Then
oCustomTable.Delete()
End If
Next
Dim oInspectionDimension As DrawingDimension
Dim oInspectionDimensionText As DimensionText
Dim oInspectionDimensionString As String
Dim oCellInspectionDimensionItem As Cell
Dim oCellInspectionDimension As Cell
Dim oCellLowestValue As Cell
Dim oCellHighestValue As Cell
Dim oCellMeasurementValue 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 4) As String ' Adjust size to 5 since we removed the symbol column
oColumnTitle(0) = "Inspection Number"
oColumnTitle(1) = "Inspection Dimension"
oColumnTitle(2) = "Lowest value"
oColumnTitle(3) = "Highest value"
oColumnTitle(4) = "Measurement Value"
' Get the table style and title
Dim oActiveTableStyle As TableStyle
Dim oTableTitle As String
oActiveTableStyle = oDrawingDocument.StylesManager.TableStyles("Inspection_Table")
oTableTitle = oActiveTableStyle.Title
' Create a custom table with specified dimensions and titles
Dim oFieldVerificationTable As CustomTable
oFieldVerificationTable = oSheet.CustomTables.Add(oTableTitle, ThisApplication.TransientGeometry.CreatePoint2d(0.635, oSheet.Height - 0.635), 5, oInspectionDimensionCount, oColumnTitle)
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
' Replace the letter "n" with the diameter symbol (Ø) in the dimension text
oInspectionDimensionString = Replace(oInspectionDimensionString, "n", ChrW(&H00D8)) ' Ø character
' Extract symbols from the dimension string
Dim symbolPrefix As String
Dim symbolSuffix As String
symbolPrefix = ""
symbolSuffix = ""
' Check for symbols at the start and end of the string
If Len(oInspectionDimensionString) > 0 And Not IsNumeric(Left(oInspectionDimensionString, 1)) Then
symbolPrefix = Left(oInspectionDimensionString, 1)
End If
If Len(oInspectionDimensionString) > 1 And Not IsNumeric(Right(oInspectionDimensionString, 1)) Then
symbolSuffix = Right(oInspectionDimensionString, 1)
End If
' Assign values to table cells
oCellInspectionDimensionItem = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Inspection Number")
oCellInspectionDimensionItem.Value = "K" & oInspectionDimensionCount2 ' Prefix "K" to inspection number
oCellInspectionDimension = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Inspection Dimension")
oCellInspectionDimension.Value = oInspectionDimensionString
' Check if the dimension is an angle
Dim isAngle As Boolean
isAngle = InStr(oInspectionDimensionString, "°") > 0
If isAngle Then
' If it is an angle, calculate values as nominal - 2° and nominal + 2°
Dim nominalAngle As Double
nominalAngle = CDbl(Replace(oInspectionDimensionString, "°", "")) ' Remove the ° symbol and convert to double
Dim lowestAngle As Double
Dim highestAngle As Double
lowestAngle = nominalAngle - 2
highestAngle = nominalAngle + 2
' Format the angles to include the ° symbol and two decimal places
Dim formattedLowestAngle As String
formattedLowestAngle = Format(lowestAngle, "0.00") & "°"
Dim formattedHighestAngle As String
formattedHighestAngle = Format(highestAngle, "0.00") & "°"
' Add lowest angle to the table
oCellLowestValue = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Lowest value")
oCellLowestValue.Value = formattedLowestAngle
' Add highest angle to the table
oCellHighestValue = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Highest value")
oCellHighestValue.Value = formattedHighestAngle
Else
' Calculate the lowest and highest values for non-angle dimensions
Dim nominalValue As Double
nominalValue = oInspectionDimension.ModelValue
Dim upperTolerance As Double
upperTolerance = oInspectionDimension.Tolerance.Upper
' Calculate lowest value using symmetrical tolerance
Dim lowestValue As Double
lowestValue = (nominalValue - upperTolerance) * 10 ' Assuming a scaling factor of 10
' Calculate highest value
Dim highestValue As Double
highestValue = (nominalValue + upperTolerance) * 10 ' Assuming a scaling factor of 10
' Format lowest and highest values to 2 decimal places
Dim formattedLowestValue As String
formattedLowestValue = Format(lowestValue, "0.00")
Dim formattedHighestValue As String
formattedHighestValue = Format(highestValue, "0.00")
' Add lowest value to the table with symbols
oCellLowestValue = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Lowest value")
oCellLowestValue.Value = symbolPrefix & formattedLowestValue & symbolSuffix
' Add highest value to the table with symbols
oCellHighestValue = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Highest value")
oCellHighestValue.Value = symbolPrefix & formattedHighestValue & symbolSuffix
End If
' Add measurement value to the table
oCellMeasurementValue = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Measurement Value")
oCellMeasurementValue.Value = "" ' Assign your measurement value here
End If
Next
' Apply the table style to the created table
oFieldVerificationTable.Style = oActiveTableStyle
' Ensure that the document updates after the script execution
iLogicVb.UpdateWhenDone = True
解決済! 解決策の投稿を見る。