Get Offset Surface Data Example (VBA)
This example shows how to get data for an offset surface.
'------------------------------------------------------------------------
' Preconditions:
' 1. Open a model document that contains a surface offset feature.
' 2. Select a surface offset feature.
'
' Postconditions: Inspect the Immediate window.
'-------------------------------------------------
Option Explicit
Sub main()
Dim swApp
As SldWorks.SldWorks
Dim swModel
As SldWorks.ModelDoc2
Dim swSelMgr
As SldWorks.SelectionMgr
Dim swSelData
As SldWorks.SelectData
Dim swOffset
As SldWorks.SurfaceOffsetFeatureData
Dim swFeat
As SldWorks.Feature
Dim swEnt
As SldWorks.Entity
Dim vFace
As Variant
Dim i
As Long
Dim bRet
As Boolean
Dim comp
As SldWorks.Component2
Dim swCompFace
As SldWorks.Component2
Dim pBodyOfFace
As SldWorks.Body2
Set swApp =
CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swSelData = swSelMgr.CreateSelectData
Set swFeat = swSelMgr.GetSelectedObject6(1, -1)
Set swOffset = swFeat.GetDefinition
Set comp = swSelMgr.GetSelectedObjectsComponent3(1, -1)
Debug.Print "File = " & swModel.GetPathName
Debug.Print "CompFeature = " & comp.Name2
Debug.Print " " & swFeat.Name
Debug.Print " Distance
= " & swOffset.Distance * 1000# & " mm"
Debug.Print " Flip
= " & swOffset.Flip
Debug.Print " FacesCount
= " & swOffset.GetEntitiesCount
bRet = swOffset.AccessSelections(swModel,
comp)
swModel.ClearSelection2 True
vFace = swOffset.Entities
For i = 0 To UBound(vFace)
Set swEnt =
vFace(i)
Set swFeat = swEnt
Set pBodyOfFace =
swFeat.GetBody
Debug.Print "
Number of faces in the Body = " & pBodyOfFace.GetFaceCount
Set swCompFace =
swEnt.GetComponent
Debug.Print "
Component face = " & swCompFace.Name2
Next i
swOffset.ReleaseSelectionAccess
End Sub