Hide Table of Contents


Create a Cam-Follower Mate Example (C#)

This example shows how to create a cam-follower mate.

// Preconditions:

// 1. Open public_documents\samples\tutorial\api\MechanicalMates\Cam-Follower.sldasm.
// 2. Delete CamMateCoincident1 from the Mates folder in the FeatureManager
//    design tree.

// Postconditions:
// Inspect the Mates folder in the FeatureManager design tree.
// NOTE: Because the model is used elsewhere, do not save changes.

// -----------------------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
namespace CamFollowerMate_CSharp
    partial class SolidWorksMacro
        private ModelDoc2 Part;
        private AssemblyDoc assy;
        private bool boolstatus;
        public void Main()
            Part = (ModelDoc2)swApp.ActiveDoc;
            assy = (AssemblyDoc)Part;
            boolstatus = Part.Extension.SelectByRay(-0.00229201081452857, 0.0761655216381314, 0.00981125242168446, -0.577381545199981, -0.577287712085548, -0.577381545199979, 0.00288013169157359, 2, true, 1, 0);
            boolstatus = Part.Extension.SelectByRay(0, 0.0762, 0, -0.577381545199981, -0.577287712085548, -0.577381545199979, 0.00288013169157359, 3, true, 8, 0);
            // Create CamFollowerMateFeatureData
            CamFollowerMateFeatureData MateData = (CamFollowerMateFeatureData)assy.CreateMateData(9);
            // Set the Entities To Mate
            object FirstEntityToMate = null;
            object SecondEntityToMate = null;
            FirstEntityToMate = ((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(1, -1);
            MateData.EntitiesToMate[0] = FirstEntityToMate;
            SecondEntityToMate = ((SelectionMgr)(Part.SelectionManager)).GetSelectedObject6(2, -1);
            MateData.EntitiesToMate[1] = SecondEntityToMate;
            // Set the Mate Alignment
            MateData.MateAlignment = 2;
            // Create the mate
            Feature MateFeature = (Feature)assy.CreateMate(MateData);
        /// <summary>
        /// The SldWorks swApp variable is pre-assigned for you.
        /// </summary>
        public SldWorks swApp;


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Create a Cam-Follower Mate Example (C#)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2019 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.