×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

GetTessTriangles Macro

GetTessTriangles Macro

GetTessTriangles Macro

(OP)
I would like to retrieve the tesselation associated with SolidWorks rendering. How do I do this, and preferably output the data in a nice readable format such as a textfile or excel.

Thanks in advance. (Below is my first attempt)


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

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

vBodies = swPart.GetBodies2(swSolidBody, False)

'Set swSelData = swSelMgr.CreateSelectData

Set swBody = vBodies(0)

'Set swFace2 = swSelMgr.GetSelectedObject5(1)

Set swFace2 = swBody.GetFirstFace
swModel.ClearSelection2 True

Dim i As Long
i = 1

Do While Not swFace2 Is Nothing
vTessTriangles = swFace2.getTessTriangles(False)

Debug.Print "(" + _
Str(vTessTriangles(9 * i + 0)) + "," + _
Str(vTessTriangles(9 * i + 1)) + "," + _
Str(vTessTriangles(9 * i + 2)) + ")"

Debug.Print "(" + _
Str(vTessTriangles(9 * i + 3)) + "," + _
Str(vTessTriangles(9 * i + 4)) + "," + _
Str(vTessTriangles(9 * i + 5)) + ")"

Debug.Print "(" + _
Str(vTessTriangles(9 * i + 6)) + "," + _
Str(vTessTriangles(9 * i + 7)) + "," + _
Str(vTessTriangles(9 * i + 8)) + ")"

Set swFace2 = swFace2.GetNextFace

i = i + 1

Loop

End Sub

RE: GetTessTriangles Macro

(OP)
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 swSelData = swSelMgr.CreateSelectData

Set swBody = vBodies(0)

'swModel.ClearSelection2 True

Set swFace2 = swBody.GetFirstFace

Dim i As Long
Dim row As Long

row = 2

'i = 1

'Alternatively,
'Set swFace2 = swSelMgr.GetSelectedObject5(1)
'vTessTriangles = swFace2.getTessTriangles(False)
'

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources