It seems you are interested in a flat slice of your CAD model. While you could use a 3D file and slice it yourself that seems like a bit overkill as the CAD application is perfectly capable of doing the slices for you.
quick and dirty
Ok, so each CAD has a 2D drawing mode, you can save that drawing out as dxf
or pdf
both are easy to parse. If you don't happen to find a good tool for this turn the pdf
into svg
that can be easier to parse. This approach can also be done quick and dirty by leveraging such tools as Inkscape or Illustrator. Lets do an example because its easy to do:
Image 1: Quick and dirty export drawing as pdf
/svg
then isolate and read points from that file I used modified version this tool to dump coordinates from pdf
. You should be able to do that in Perl easily. data available here
Proper Method
It is possible to access both SolidWorks and Inventor trough a COM bridge so you can access the CAD applications data model directly from your Perl code.This has several benefits but mostly not needing to parse intermediate files. You could select the relevant edges and just traverse them directly from the CAD. Now I only have access to SolidWorks at work but similar approach works in inventor as i have done it.
I had some extra time at work to do some quick VBA
code for SolidWorks. The code takes all the lines of a closed sketch, sorts them into polygon (with a naive N^2 algorithm) order and prints them in the VBA
debug console.
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swPart As SldWorks.PartDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swFeat As SldWorks.Feature
Dim swSketch As SldWorks.Sketch
Dim numLines As Long
Dim vLines As Variant
Dim dict As New Collection
Dim i As Variant
Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelMgr = swModel.SelectionManager
Set swFeat = swSelMgr.GetSelectedObject5(1)
Set swSketch = swFeat.GetSpecificFeature2
numLines = swSketch.GetLineCount2(1) 'Exclude crosshatch lines
vLines = swSketch.GetLines2(1) 'Exclude crosshatch lines
Dim startP, endP, line As Variant
For i = 1 To numLines - 1
line = Array(Array(vLines(12 * i + 6) * 1000, _
vLines(12 * i + 7) * 1000), _
Array(vLines(12 * i + 9) * 1000, _
vLines(12 * i + 10) * 1000))
dict.Add (line)
Next i
startP = Array(vLines(6) * 1000, _
vLines(7) * 1000)
endP = Array(vLines(9) * 1000, _
vLines(10) * 1000)
pp startP
pp endP
For i = 1 To dict.Count - 1
endP = NextPoint(dict, endP)
pp endP
Next i
End Sub
Sub pp(point As Variant)
Debug.Print " " & Str(point(0)) & ", " & Str(point(1))
End Sub
Function NextPoint(dict As Collection, point As Variant) As Variant
Dim i As Variant
For i = 1 To dict.Count
Dim data, startRP, endRP As Variant
data = dict.Item(i)
startRP = data(0)
endRP = data(1)
If endRP(0) = point(0) And endRP(1) = point(1) Then
dict.Remove (i)
NextPoint = startRP
Exit Function
End If
If startRP(0) = point(0) And startRP(1) = point(1) Then
dict.Remove (i)
NextPoint = endRP
Exit Function
End If
Next i
End Function
Since vba is calling COM you ca code you can use nearly any language for example perl implements Win32::OLE that can do the job.
Image 2: Example part with simple one loop sketch results in this output
Epilogue
If you really want to export 3D polygon data and do the slicing manually then i would export either OBJ or STL. But this would be way down on my list of approaches mainly because all other approaches are simpler.