GetTessTriangles (Macro)

Discussion created by Guest on Jul 12, 2006
Latest reply on Jul 22, 2009 by 1-FEM3FC
Following is my solution. I didn't read the Eng-tips faqs

' Go to "Tools --> References" and look for something like "Microsoft Excel xx.xx Object Library".
' Set All SolidWorks References as well!
Option Explicit

Sub main()

Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swPart As SldWorks.PartDoc
Dim swEnt As SldWorks.Entity
Dim swFace2 As SldWorks.Face2
Dim vTessTriangles As Variant
Dim vBodies As Variant
Dim swBody As SldWorks.Body2

Dim exApp As Excel.Application
Dim sheet As Excel.Worksheet

Set exApp = New Excel.Application
If Not exApp Is Nothing Then
exApp.Visible = True
If Not exApp Is Nothing Then
exApp.Workbooks.Add
Set sheet = exApp.ActiveSheet
If Not sheet Is Nothing Then
sheet.Cells(1, 2).Value = "X1"
sheet.Cells(1, 3).Value = "Y1"
sheet.Cells(1, 4).Value = "Z1"
sheet.Cells(1, 5).Value = "X2"
sheet.Cells(1, 6).Value = "Y2"
sheet.Cells(1, 7).Value = "Z2"
sheet.Cells(1, 8).Value = "X3"
sheet.Cells(1, 9).Value = "Y3"
sheet.Cells(1, 10).Value = "Z3"
End If
End If
End If

Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swPart = swModel
Set swSelMgr = swModel.SelectionManager

vBodies = swPart.GetBodies2(swSolidBody, False)

Set swBody = vBodies(0)

Set swFace2 = swBody.GetFirstFace

Dim i As Long
Dim row As Long

row = 2

'i = 1

Do While Not swFace2 Is Nothing

vTessTriangles = swFace2.getTessTriangles(False)

For i = LBound(vTessTriangles) To UBound(vTessTriangles) / (1 * 9) - 1

sheet.Cells(row, 2).Value = (vTessTriangles(9 * i + 0))
sheet.Cells(row, 3).Value = (vTessTriangles(9 * i + 1))
sheet.Cells(row, 4).Value = (vTessTriangles(9 * i + 2))

sheet.Cells(row, 5).Value = (vTessTriangles(9 * i + 3))
sheet.Cells(row, 6).Value = (vTessTriangles(9 * i + 4))
sheet.Cells(row, 7).Value = (vTessTriangles(9 * i + 5))

sheet.Cells(row, 8).Value = (vTessTriangles(9 * i + 6))
sheet.Cells(row, 9).Value = (vTessTriangles(9 * i + 7))
sheet.Cells(row, 10).Value = (vTessTriangles(9 * i + 8))

row = row + 1

exApp.Columns.AutoFit
Next i

Set swFace2 = swFace2.GetNextFace

Loop

End Sub

Outcomes