Export Coordinates from Inventor

Export Coordinates from Inventor

mes063
Contributor Contributor
228 Views
1 Reply
Message 1 of 2

Export Coordinates from Inventor

mes063
Contributor
Contributor

Hello, I am trying to export the coordinates of the vertices of my line elements in the attached Inventor model. I have seen a few other Forum posts regarding exporting Inventor coordinates in Excel and have followed what was done there, but have had issues. https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/unable-to-export-3d-point-co-ordinat... and https://modthemachine.typepad.com/my_weblog/2011/06/writing-work-points-to-an-excel-file.html One of the codes kept giving me an error even after trying to fix it and the other produced a blank Excel sheet. Please let me know if you have any advice.

I am either trying to export my model as only lines, not solids, or trying to export the coordinates of the vertices of my model, as mentioned. Thank you so much for your help!

0 Likes
229 Views
1 Reply
Reply (1)
Message 2 of 2

JelteDeJong
Mentor
Mentor

Does this work for you? It creates a csv file with the same file name as the part.

Sub Main()

	Dim doc As PartDocument = ThisDoc.Document
	Dim uom As UnitsOfMeasure = doc.UnitsOfMeasure

	Dim csvFileInfo As New IO.FileInfo(ThisDoc.PathAndFileName(False) & ".csv") 'Get file Names
	If csvFileInfo.Exists Then
		csvFileInfo.Delete()
	End If

	Using csvWriter As IO.StreamWriter = csvFileInfo.CreateText()
		csvWriter.WriteLine("sep=|")

		For Each body As SurfaceBody In doc.ComponentDefinition.SurfaceBodies
			For Each vertex As Vertex In body.Vertices
				Dim x As Double = Convert(uom, Vertex.Point.X)
				Dim y As Double = Convert(uom, Vertex.Point.Y)
				Dim z As Double = Convert(uom, Vertex.Point.Z)
				csvWriter.WriteLine(String.Format("{0}|{1}|{2}", x, y, z))
			Next
		Next
	End Using
End Sub


Private Function Convert(uom As UnitsOfMeasure, value As Double) As Double
	value = uom.ConvertUnits(value, UnitsTypeEnum.kDatabaseLengthUnits, UnitsTypeEnum.kDefaultDisplayLengthUnits)
	Return Math.Round(value, 10)
End Function

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes