Message 1 of 13
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i want to create a list of coordinates of the centers of all holes in my .ipt and save the list as an Excel file. i am familiar with Excel VBA. But, not very expert in inventor iLogic. i tried to search online and created a code like below.
This code doesn't give any error even the Excel file is also created. But, it is always blank. I am not able to find what exactly is causing the problem. i don't want to go with the hole table command because it only gives .CSV file.
Also, extend this code if possible to run a global macro in that Excel file.
If this task can be done with the "Holefeature" object instead of Edges, that is also fine.
Any help would be much appreciated.
Dim partDoc As PartDocument
partDoc = ThisApplication.ActiveDocument
' Get the component definition of the part
Dim partDef As PartComponentDefinition
partDef = partDoc.ComponentDefinition
' Get all circular edges in the part
Dim edges As Edges
edges = partDef.SurfaceBodies.Item(1).Edges
Dim holeList As New List(Of String)
For Each edge As Edge In edges
If Edge.GeometryType = kCircularEdgeGeometry Then
Dim cen As Point = Edge.Geometry.center
Dim holeInfo As String = cen.X & "," & cen.Y & "," & cen.Z
holeList.Add(holeInfo)
End If
Next
Dim excelApp As Object = CreateObject("Excel.Application")
Dim excelWorkbook As Object = excelApp.Workbooks.Add()
Dim excelSheet As Object = excelWorkbook.Sheets(1)
excelSheet.Cells(1, 1).Value = "X"
excelSheet.Cells(1, 2).Value = "Y"
excelSheet.Cells(1, 3).Value = "Z"
For i As Integer = 0 To holeList.Count - 1
Dim holeInfoArray As String() = holeList(i).Split(",")
excelSheet.Cells(i + 2, 1).Value = holeInfoArray(0)
excelSheet.Cells(i + 2, 2).Value = holeInfoArray(1)
excelSheet.Cells(i + 2, 3).Value = holeInfoArray(2)
Next
excelWorkbook.SaveAs("C:\HoleInfo.xlsx")
excelWorkbook.Close()
excelApp.Quit()
Solved! Go to Solution.