Automating Mating Relationships in Assemblies with SOLIDWORKS API
{ width=200 }
You can programmatically mate assembly components using the SOLIDWORKS API method IAssemblyDoc::AddMate3 (or its updated version).
Different markers are used to identify selected objects for different types of mates. Refer to the SOLIDWORKS API Help documentation for the marker values specific to each mating relationship, or use the SOLIDWORKS Macro Recorder to capture the correct markers.