Hide Table of Contents

Insert Mate Reference Example (C#)

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.

//---------------------------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

namespace InsertMateReference2_CSharp.csproj

{

    partial class SolidWorksMacro

    {

        public void Main()

        {

            ModelDoc2 swModel = default(ModelDoc2);

            ModelDocExtension swModelDocExt = default(ModelDocExtension);

            SelectionMgr swSelMgr = default(SelectionMgr);

            FeatureManager swFeatMgr = default(FeatureManager);

            Feature swFeature = default(Feature);

            Entity mateRef1 = null;

            Entity mateRef2 = null;

            Entity mateRef3 = null;

            bool boolstatus = false;

            string strMateRefName = null;

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swModelDocExt = swModel.Extension;

            swSelMgr = (SelectionMgr)swModel.SelectionManager;

            swFeatMgr = swModel.FeatureManager;

            swModel.ClearSelection2(true);

            // Select three faces

            boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.007841429441271, 0.004702510345794, 0.007840974544081, false, 0, null, 0);

            mateRef1 = (Entity)swSelMgr.GetSelectedObject6(1, -1);

            boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.06256195446167, 0.003271675226301, 0.004687091733047, false, 0, null, 0);

            mateRef2 = (Entity)swSelMgr.GetSelectedObject6(1, -1);

            boolstatus = swModel.Extension.SelectByID2("", "FACE", 0.04319534991731, 0.006350000000054, 0.009894144482189, false, 0, null, 0);

            mateRef3 = (Entity)swSelMgr.GetSelectedObject6(1, -1);

            swModel.ClearSelection2(true);

            strMateRefName = "MateReference1";

            // Insert mate reference

            swFeature = swFeatMgr.InsertMateReference2(strMateRefName, (Entity)mateRef1, (int)swMateReferenceType_e.swMateReferenceType_Concentric, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_Aligned, false, mateRef2, (int)swMateReferenceType_e.swMateReferenceType_Concentric, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_AntiAligned, false, mateRef3,

            (int)swMateReferenceType_e.swMateReferenceType_Concentric, (int)swMateReferenceAlignment_e.swMateReferenceAlignment_Closest);

            if (swFeature == null)

            {

                System.Windows.Forms.MessageBox.Show("Failed to insert mate reference.");

            }

            swModel.ClearSelection2(true);

        }

        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

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Insert Mate Reference Example (C#)
*Comment:  
*   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:

x

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
x

Web Help Content Version: API Help (English only) 2015 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.