Code:
'----------------------------------------------
' iLogic: Prüfmaße aus IDW in Tabelle schreiben
'----------------------------------------------
Dim oDoc As DrawingDocument
oDoc = ThisApplication.ActiveDocument
' Name der Tabelle auf dem Blatt
Dim tableName As String = "Prüfmass Tabelle"
' Aktives Blatt
Dim oSheet As Sheet = oDoc.ActiveSheet
' Prüfen, ob Tabelle bereits existiert
Dim oTable As Inventor.CustomTable
Dim tableExists As Boolean = False
For Each tbl As CustomTable In oSheet.CustomTables
If tbl.Title = tableName Then
tableExists = True
oTable = tbl
Exit For
End If
Next
' Falls Tabelle fehlt → neue Tabelle erstellen
If Not tableExists Then
Dim colTitles(2) As String
colTitles(0) = "Nr."
colTitles(1) = "Maß"
colTitles(2) = "Toleranz"
oTable = oSheet.CustomTables.Add("Prüfmaße", ThisApplication.TransientGeometry.CreatePoint2d(1, 1),colTitles.Length,0,colTitles)
oTable.Title = tableName
oTable.ShowTitle=True
End If
' Alte Zeilen (bis auf Kopfzeile) löschen
While oTable.Rows.Count > 0
oTable.Rows.Item(1).Delete
End While
' Sammlung aller Prüfmaße
Dim inspectionDims As New List(Of DrawingDimension)
' Alle Views durchsuchen
For Each oDim As Inventor.DrawingDimension In oSheet.DrawingDimensions
If oDim.IsInspectionDimension Then
inspectionDims.Add(oDim)
End If
Next
' In Tabelle eintragen
Dim index As Integer = 1
For Each dimItem As DrawingDimension In inspectionDims
Dim val As String = dimItem.Text.Text.ToString
Dim tol As String = ""
' Toleranzen auslesen (falls vorhanden)
Try
tol = (dimItem.Tolerance.Upper*10) & " / " & (dimItem.Tolerance.Lower*10)
Catch
tol = "-"
End Try
' Neue Zeile
Dim newRow As Row
newRow = oTable.Rows.Add
' Inhalte
newRow.Item(1).Value = index.ToString()
newRow.Item(2).Value = val
newRow.Item(3).Value = tol
index += 1
Next
MsgBox("Prüfmaße erfolgreich in Tabelle übertragen!", vbInformation)