Files
Get mate information for selected component
Code
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Written in SolidWorks 2011
'This macro shows how to quickly get information about the mates associated with a component.
'To get all mates in the assembly more quickly than by searching the feature tree for the Mates _
folder, IComponent2::GetMates might be used in conjunction with IAssemblyDoc::GetComponents
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swComp As SldWorks.Component2
Dim swMate As SldWorks.Mate2
Dim swMateInPlace As SldWorks.MateInPlace
Dim swFeat As SldWorks.Feature
Dim vMates As Variant
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swComp = swSelMgr.GetSelectedObjectsComponent3(1, -1)
vMates = swComp.GetMates
For i = 0 To UBound(vMates)
Set swFeat = vMates(i)
If swFeat.GetTypeName = "MateInPlace" Then
Set swMateInPlace = vMates(i)
Debug.Print "In-place mate belongs to " & swMateInPlace.MateComponentName(0)
Else
Set swMate = vMates(i)
Debug.Print "Non in-place mate type: " & swMate.Type
End If
Next i
End Sub
'NOTES
'IComponent2::GetMates returns in-place and non-in-place mates. Since mates technically are a _
feature, you must test each item in the list to determine the type, because the two objects _
are not interchangeable.