Hi everyone,
I've been trying to create a macro to mate an inserted component in an assembly so that the selected face gets mated to a plane of an assembly (say, Top Plane). I've used the API Help Example, and have got the following so far. But it will fail to mate with unknown error.. Is there anything I'm missing here? Thanks in advance.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swAssy As SldWorks.AssemblyDoc
Dim boolstat As Boolean, stat As Boolean
Dim strings As Variant
Dim AssemblyName As String
Dim AssemblyTitle As String
Dim SecondSelection As String
Sub Aligned()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swAssy = swModel
' Get title of assembly document
AssemblyTitle = swModel.GetTitle
' Split the title into two strings using the period as the delimiter
strings = Split(AssemblyTitle, ".")
' Use AssemblyName when mating the component with the assembly
AssemblyName = strings(0)
boolstat = True
'planes to use for the mate
SecondSelection = "Top@" + AssemblyName
Set swDocExt = swModel.Extension
'Select the planes to mate
boolstat = swDocExt.SelectByID2(SecondSelection, "PLANE", 0, 0, 0, True, 1, Nothing, swSelectOptionDefault)
swAssy.AddMate5 swMateCOINCIDENT, 0, False, 0, 0, 0, 0, 0, 0, 0, 0, False, False, 0
End Sub
SolidworksApi macros