Dimensions to Excel with Label

Dimensions to Excel with Label

max.baumann07
Enthusiast Enthusiast
226 Views
2 Replies
Message 1 of 3

Dimensions to Excel with Label

max.baumann07
Enthusiast
Enthusiast

Hello,

I need help with the Excel export of the dimensions. Everything works as it should, but I would also like to have all labels exported. Unfortunately I can't do this without errors. Can someone help me out here?

maxbaumann07_0-1714157403996.png

CODE:

 

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

'Dim oXLFile As String = "C:\TEMP\DrawingDimensions.xlsx"
Dim oSheet As String = "Tabelle1"

Dim oExcel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim oWB As Microsoft.Office.Interop.Excel.Workbook = oExcel.Workbooks.add'.Open(oXLFile)
Dim oWS As Microsoft.Office.Interop.Excel.Worksheet = oWB.Worksheets.Item(oSheet)

Dim oCells As Microsoft.Office.Interop.Excel.Range = oWS.Cells

'oCells.item(2,1).value= b.Text.Text.ToString

Dim a As Inventor.DrawingDocument = ThisDrawing.Document
Dim s As Inventor.Sheet = a.ActiveSheet


Dim i As Integer = 1
		oCells.Item(1,1).value  = "Dimension"
		oCells.Item(1,2).value = "Tolerance Upper"
		oCells.Item(1,3).value = "Tolerance Lower"
For Each b As Inventor.DrawingDimension In s.DrawingDimensions
	i = i + 1
'MsgBox (b.Text.Text & " " & b.Tolerance.ToleranceType)
	
	If b.Tolerance.ToleranceType = 31236 Then
		oCells.Item(i,1).value = b.Text.Text
		oCells.Item(i,2).value = b.Tolerance.Upper*10
		oCells.Item(i,3).value  = b.Tolerance.Lower*10
	

		End If
If b.Tolerance.ToleranceType = 31233 Then
		oCells.Item(i,1).value = b.Text.Text
		oCells.Item(i,2).value = b.Tolerance.Upper*10
		oCells.Item(i,3).value  = b.Tolerance.Lower*10

		End If
If b.Tolerance.ToleranceType = 31235 Then
	Dim du As Double = "+" & (b.Tolerance.Upper * 10)
	Dim dl As Double = "-" & (b.Tolerance.Upper * 10)
	'MsgBox("+"&(b.Tolerance.Upper*10).ToString)
		oCells.Item(i,1).value = b.Text.Text
		oCells.Item(i,2).value = du '"="+"" &(b.Tolerance.Upper*10)'"p"'"+" & b.Tolerance.Upper*10
		oCells.Item(i,3).value  = dl'"-" &(b.Tolerance.Lower*10)'"q"'"-" &b.Tolerance.Lower*10

		End If
If b.Tolerance.ToleranceType = 31246 Then
		oCells.Item(i,1).value = (Replace((Replace(b.Text.Text.ToString,"(","")),")",""))'Replace(b.Text.Text.ToString,"-","")
		oCells.Item(i,2).value = b.Tolerance.Upper*10
		oCells.Item(i,3).value  = b.Tolerance.Lower*10

		End If

	Next
	oWB.SaveAs("C:\TEMP\"& a.DisplayName & ".xlsx")
oWB.Close

 

0 Likes
227 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor

Hi @max.baumann07.  It looks like you are looking for the information in the following places:

DrawingDimension.IsInspectionDimension 

DrawingDimension.GetInspectionDimensionData 

DrawingDimension.SetInspectionDimensionData 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 3

max.baumann07
Enthusiast
Enthusiast

Thank you!

Got it. 

 

If anyone needs the code:

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

'Dim oXLFile As String = "C:\TEMP\DrawingDimensions.xlsx"
Dim oSheet As String = "Tabelle1"

Dim oExcel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim oWB As Microsoft.Office.Interop.Excel.Workbook = oExcel.Workbooks.add'.Open(oXLFile)
Dim oWS As Microsoft.Office.Interop.Excel.Worksheet = oWB.Worksheets.Item(oSheet)

Dim oCells As Microsoft.Office.Interop.Excel.Range = oWS.Cells

'oCells.item(2,1).value= b.Text.Text.ToString

Dim a As Inventor.DrawingDocument = ThisDrawing.Document
Dim s As Inventor.Sheet = a.ActiveSheet

Dim i As Integer = 1
oCells.Item(1,1).value = "Dimension"
oCells.Item(1,2).value = "Tolerance Upper"
oCells.Item(1,3).value = "Tolerance Lower"
For Each b As Inventor.DrawingDimension In s.DrawingDimensions
    i = i + 1
    'MsgBox (b.Text.Text & " " & b.Tolerance.ToleranceType)
    
    If b.Tolerance.ToleranceType = 31236 Then
        oCells.Item(i,1).value = b.Text.Text
        oCells.Item(i,2).value = b.Tolerance.Upper*10
        oCells.Item(i,3).value  = b.Tolerance.Lower*10
        
        ' Set Inspection Dimension Data
        DrawingDimension.SetInspectionDimensionData(InspectionDimensionShapeEnum, "Label", "Rate")
    End If
    If b.Tolerance.ToleranceType = 31233 Then
        oCells.Item(i,1).value = b.Text.Text
        oCells.Item(i,2).value = b.Tolerance.Upper*10
        oCells.Item(i,3).value  = b.Tolerance.Lower*10
        
        ' Set Inspection Dimension Data
        DrawingDimension.SetInspectionDimensionData(InspectionDimensionShapeEnum, "Label", "Rate")
    End If
    If b.Tolerance.ToleranceType = 31235 Then
        Dim du As Double = "+" & (b.Tolerance.Upper * 10)
        Dim dl As Double = "-" & (b.Tolerance.Upper * 10)
        'MsgBox("+"&(b.Tolerance.Upper*10).ToString)
        oCells.Item(i,1).value = b.Text.Text
        oCells.Item(i,2).value = du '"="+"" &(b.Tolerance.Upper*10)'"p"'"+" & b.Tolerance.Upper*10
        oCells.Item(i,3).value  = dl'"-" &(b.Tolerance.Lower*10)'"q"'"-" &b.Tolerance.Lower*10
        
        ' Set Inspection Dimension Data
        DrawingDimension.SetInspectionDimensionData(InspectionDimensionShapeEnum, "Label", "Rate")
    End If
    If b.Tolerance.ToleranceType = 31246 Then
        oCells.Item(i,1).value = (Replace((Replace(b.Text.Text.ToString,"(","")),")",""))'Replace(b.Text.Text.ToString,"-","")
        oCells.Item(i,2).value = b.Tolerance.Upper*10
        oCells.Item(i,3).value  = b.Tolerance.Lower*10
        
        ' Set Inspection Dimension Data
        DrawingDimension.SetInspectionDimensionData(InspectionDimensionShapeEnum, "Label", "Rate")
    End If
    
Next

' Speichern und Schließen der Arbeitsmappe
oWB.SaveAs("C:\TEMP\"& a.DisplayName & ".xlsx")
oWB.Close()

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports exe = Microsoft.Office.Interop.Excel

Dim oSheet As String = "Tabelle1"
Dim oExcel As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim oWB As Microsoft.Office.Interop.Excel.Workbook = oExcel.Workbooks.Add
Dim oWS As Microsoft.Office.Interop.Excel.Worksheet = oWB.Worksheets.Item(oSheet)
Dim oCells As Microsoft.Office.Interop.Excel.Range = oWS.Cells

Dim a As Inventor.DrawingDocument = ThisDrawing.Document
Dim s As Inventor.Sheet = a.ActiveSheet

Dim i As Integer = 1
oCells.Item(1, 1).Value = "Dimension"
oCells.Item(1, 2).Value = "Tolerance Upper"
oCells.Item(1, 3).Value = "Tolerance Lower"
oCells.Item(1, 4).Value = "Inspection Label"

For Each b As Inventor.DrawingDimension In s.DrawingDimensions
    i = i + 1
    
    If b.Tolerance.ToleranceType = 31236 Then
        oCells.Item(i, 1).Value = b.Text.Text
        oCells.Item(i, 2).Value = b.Tolerance.Upper * 10
        oCells.Item(i, 3).Value = b.Tolerance.Lower * 10
    End If
    
    If b.Tolerance.ToleranceType = 31233 Then
        oCells.Item(i, 1).Value = b.Text.Text
        oCells.Item(i, 2).Value = b.Tolerance.Upper * 10
        oCells.Item(i, 3).Value = b.Tolerance.Lower * 10
    End If
    
    If b.Tolerance.ToleranceType = 31235 Then
        Dim du As Double = "+" & (b.Tolerance.Upper * 10)
        Dim dl As Double = "-" & (b.Tolerance.Upper * 10)
        oCells.Item(i, 1).Value = b.Text.Text
        oCells.Item(i, 2).Value = du
        oCells.Item(i, 3).Value = dl
    End If
    
    If b.Tolerance.ToleranceType = 31246 Then
        oCells.Item(i, 1).Value = Replace(Replace(b.Text.Text.ToString, "(", ""), ")", "")
        oCells.Item(i, 2).Value = b.Tolerance.Upper * 10
        oCells.Item(i, 3).Value = b.Tolerance.Lower * 10
    End If

    ' Get Inspection Label
    Dim inspectionLabel As String = ""
    If b.IsInspectionDimension() Then
        Dim shape As Inventor.InspectionDimensionShapeEnum
        Dim label As String = ""
        Dim rate As String = ""
        b.GetInspectionDimensionData(shape, label, rate)
        inspectionLabel = label
    End If
    
    oCells.Item(i, 4).Value = inspectionLabel
Next

' Save and close the workbook
oWB.SaveAs("C:\TEMP\" & a.DisplayName & ".xlsx")
oWB.Close()

 

0 Likes