Edit Mate Reference Example (VBA)
This example shows how to edit a mate reference.
'---------------------------------------------------------------------------------
'
' Preconditions:
' (1)
A part or assembly document is open.
' (2)
The part or assembly document contains a mate
' reference
named Parallel_MateReference-<1>.
'
' Postconditions: The mate reference named Parallel_MateReference-<1>
' is
edited and replaced by a mate reference named asdfg.
'
'----------------------------------------------------------------------------------
Option Explicit
Sub main()
Dim
swApp As SldWorks.SldWorks
Dim
swMateReference As SldWorks.MateReference
Dim
swFeature As SldWorks.feature
Dim
swModel As SldWorks.ModelDoc2
Dim
swNewFace As SldWorks.face2
Dim
swSelMgr As SldWorks.SelectionMgr
Dim
swModelDocExt As SldWorks.ModelDocExtension
Dim
boolstatus As Boolean
Dim
retVal As Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
If
swModel Is Nothing Then
MsgBox
"No active document."
Exit
Sub
End
If
Set
swSelMgr = swModel.SelectionManager
Set
swModelDocExt = swModel.Extension
boolstatus
= swModelDocExt.SelectByID2("",
"FACE", -0.07408228341137, 0.02764877337773, 0.01130601269097,
False, 0, Nothing, swSelectOptionDefault)
Set
swNewFace = swSelMgr.GetSelectedObject5(1)
swModel.ClearSelection2 True
boolstatus
= swModelDocExt.SelectByID2("Parallel_MateReference-<1>",
"POSGROUP", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)
Set
swFeature = swSelMgr.GetSelectedObject5(1)
Set
swMateReference = swFeature.GetSpecificFeature2
swModel.ClearSelection2 True
retVal
= swMateReference.Edit("asdfg",
swNewFace, swMateReferenceType_Concentric, swMateReferenceAlignment_AntiAligned,
Nothing, swMateReferenceType_default, swMateReferenceAlignment_Any, Nothing,
swMateReferenceType_default, swMateReferenceAlignment_Any)
Debug.Print
retVal
End Sub