Insert Mate Reference Example (VB.NET)
This example shows how to insert a mate reference.
'----------------------------------------------------------------------------
' Preconditions: Open:
' <SOLIDWORKS_install_dir>\samples\HandsOn\mate references\crank-arm.sldprt
'
' Postconditions:
' A
mate reference, MateReference1, is inserted in the MateReferences folder
' in the FeatureManager design tree.
' NOTE:
Because this part is used in a SOLIDWORKS online tutorial,
' do not save
any changes when you close it.
'----------------------------------------------------------------------------
Imports SolidWorks.Interop.sldworks
Imports SolidWorks.Interop.swconst
Imports System
Partial Class SolidWorksMacro
Sub
main()
Dim
swModel As ModelDoc2
Dim
swModelDocExt As ModelDocExtension
Dim
swSelMgr As SelectionMgr
Dim
swFeatMgr As FeatureManager
Dim
swFeature As Feature
Dim
mateRef1 As Object, mateRef2 As Object, mateRef3 As Object
Dim
boolstatus As Boolean
Dim
strMateRefName As String
swModel
= swApp.ActiveDoc
swModelDocExt
= swModel.Extension
swSelMgr
= swModel.SelectionManager
swFeatMgr
= swModel.FeatureManager
swModel.ClearSelection2(True)
'
Select three faces
boolstatus
= swModel.Extension.SelectByID2("", "FACE", 0.007841429441271,
0.004702510345794, 0.007840974544081, False, 0, Nothing, 0)
mateRef1
= swSelMgr.GetSelectedObject6(1, -1)
boolstatus
= swModel.Extension.SelectByID2("", "FACE", 0.06256195446167,
0.003271675226301, 0.004687091733047, False, 0, Nothing, 0)
mateRef2
= swSelMgr.GetSelectedObject6(1, -1)
boolstatus
= swModel.Extension.SelectByID2("", "FACE", 0.04319534991731,
0.006350000000054, 0.009894144482189, False, 0, Nothing, 0)
mateRef3
= swSelMgr.GetSelectedObject6(1, -1)
swModel.ClearSelection2(True)
strMateRefName
= "MateReference1"
'
Insert mate reference
swFeature
= swFeatMgr.InsertMateReference2(strMateRefName,
mateRef1, swMateReferenceType_e.swMateReferenceType_Concentric, swMateReferenceAlignment_e.swMateReferenceAlignment_Aligned,
False, mateRef2, swMateReferenceType_e.swMateReferenceType_Concentric,
swMateReferenceAlignment_e.swMateReferenceAlignment_AntiAligned, False,
mateRef3, swMateReferenceType_e.swMateReferenceType_Concentric, swMateReferenceAlignment_e.swMateReferenceAlignment_Closest)
If
swFeature Is Nothing Then
MsgBox("Failed
to insert mate reference.")
End
If
swModel.ClearSelection2(True)
End
Sub
Public
swApp As SldWorks
End Class