Get Vertex Chamfer Distances Example (VBA)
This example shows how to get the distances associated with the selected
vertex chamfer.
'-----------------------------------------------
'
' Preconditions:
' (1)
Part document is open.
' (2)
Vertex chamfer is selected.
'
' Postconditions: None
'
' ChamferFeatureData2::Type
' 1
= Angle-Distance
' 2
= Distance-Distance
' 3
= Vertex
'
'-----------------------------------------------
Option Explicit
Sub main()
Const
DegPerRad As
Double = 57.3
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swFeat As
SldWorks.feature
Dim
swChamfer As
SldWorks.ChamferFeatureData2
Dim
swVertex As
SldWorks.Vertex
Dim
vEdgeArr As
Variant
Dim
vEdge As
Variant
Dim
swEdge As
SldWorks.Edge
Dim
vFaceArr As
Variant
Dim
vFace As
Variant
Dim
swFace As
SldWorks.face2
Dim
vLoopArr As
Variant
Dim
vLoop As
Variant
Dim
swLoop As
SldWorks.Loop2
Dim
vLoopEdge As
Variant
Dim
vLoopEdgeArr As
Variant
Dim
swLoopEdge As
SldWorks.Edge
Dim
swEnt As
SldWorks.entity
Dim
swSelData As
SldWorks.SelectData
Dim
i As
Long
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swSelData = SwSelMgr.CreateSelectData
Set
swFeat = swSelMgr.GetSelectedObject5(1)
Set
swChamfer = swFeat.GetDefinition
'
Get chamfer information
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" "
& swFeat.Name
Debug.Print
" EdgeChamferAngle
=
" & swChamfer.EdgeChamferAngle
* DegPerRad & " degrees"
Debug.Print
" EqualDistance
=
" & swChamfer.EqualDistance
Debug.Print
" EdgeChamferDistance(0)
=
" & swChamfer.GetEdgeChamferDistance(0)
* 1000# & " mm"
Debug.Print
" EdgeChamferDistance(1)
=
" & swChamfer.GetEdgeChamferDistance(1)
* 1000# & " mm"
Debug.Print
" VertexChamferDistance(0)
= " & swChamfer.GetVertexChamferDistance(0)
* 1000# & " mm"
Debug.Print
" VertexChamferDistance(1)
= " & swChamfer.GetVertexChamferDistance(1)
* 1000# & " mm"
Debug.Print
" VertexChamferDistance(2)
= " & swChamfer.GetVertexChamferDistance(2)
* 1000# & " mm"
Debug.Print
" KeepFeatures
=
" & swChamfer.KeepFeatures
Debug.Print
" Type
=
" & swChamfer.Type
'
Roll back to get access to geometric entities
bRet
= swChamfer.AccessSelections(swModel,
Nothing): Debug.Assert bRet
Set
swVertex = swChamfer.Vertex
vEdgeArr
= swChamfer.edges
vFaceArr
= swChamfer.faces
vLoopArr
= swChamfer.Loops
If
Not swVertex Is Nothing Then
swModel.ClearSelection2 True
Set
swEnt = swVertex
bRet
= swEnt.Select4(True, swSelData):
Debug.Assert bRet
'
Remove comment to see selected vertex
'Stop
End
If
If
Not IsEmpty(vEdgeArr) Then
swModel.ClearSelection2 True
i
= 0
bRet
= False
For
Each vEdge In vEdgeArr
Set
swEdge = vEdge
Set
swEnt = swEdge
bRet
= swEnt.Select4(True, swSelData):
Debug.Assert bRet
Debug.Print
" EdgeFlip("
& i & ") =
" & swChamfer.GetIsFlipped(swEdge)
i
= i + 1
Next
'
Remove comment to see selected edges
'If
bRet Then Stop
End
If
If
Not IsEmpty(vFaceArr) Then
swModel.ClearSelection2 True
i
= 0
bRet
= False
For
Each vFace In vFaceArr
Set
swFace = vFace
Set
swEnt = swFace
bRet
= swEnt.Select4(True, swSelData):
Debug.Assert bRet
Debug.Print
" FaceFlip("
& i & ") =
" & swChamfer.GetIsFlipped(swFace)
i
= i + 1
Next
'
Remove comment to see selected faces
'If
bRet Then Stop
End
If
If
Not IsEmpty(vLoopArr) Then
swModel.ClearSelection2 True
i
= 0
bRet
= False
For
Each vLoop In vLoopArr
Set
swLoop = vLoop
'
Cannot select loop-through-entity interface because loop
'
is topology; instead, get edges (geometry) and select through
'
entity from edge
vLoopEdgeArr
= swLoop.GetEdges
For
Each vLoopEdge In vLoopEdgeArr
Set
swLoopEdge = vLoopEdge
Set
swEnt = swLoopEdge
bRet
= swEnt.Select4(True, swSelData):
Debug.Assert bRet
Next
Debug.Print
" LoopFlip("
& i & ") =
" & swChamfer.GetIsFlipped(swLoop)
i
= i + 1
Next
'
Remove comment to see selected loops
'If
bRet Then Stop
End
If
'Cancel
changes
swChamfer.ReleaseSelectionAccess
End Sub
'-------------------------------------------------