Get Mate Reference Properties Example (C#)
This example shows how to get mate reference properties.
//----------------------------------------------------------------------------
// Preconditions:
// 1. Open a part or assembly document that contains a mate reference named
//
Default-<1>.
// 2. Rename the namespace to match the name of your C# project.
//
// Postconditions: Inspect the Immediate window.
//
---------------------------------------------------------------------------
using
SolidWorks.Interop.sldworks;
using
SolidWorks.Interop.swconst;
using
System;
using
System.Diagnostics;
namespace
MateReferences_CSharp.csproj
{
partial
class
SolidWorksMacro
{
public
void Main()
{
MateReference
swMateReference = default(MateReference);
Feature
swFeature = default(Feature);
object
mateRefObj = null;
int
mateRefEntityType = 0;
ModelDoc2
swModel = default(ModelDoc2);
ModelDocExtension
swModelDocExt = default(ModelDocExtension);
SelectionMgr
swSelMgr = default(SelectionMgr);
string
strMateReferencename = null;
int
nCount = 0;
int
refEntType = 0;
int
mateRefAlignment = 0;
bool
boolstatus = false;
swModel = (ModelDoc2)swApp.ActiveDoc;
swModelDocExt = swModel.Extension;
swSelMgr = (SelectionMgr)swModel.SelectionManager;
swModel.ClearSelection2(true);
boolstatus = swModelDocExt.SelectByID2("Default-<1>",
"POSGROUP",
0, 0, 0, false,
0, null,
0);
swFeature = (Feature)swSelMgr.GetSelectedObject6(1,
-1);
swMateReference = (MateReference)swFeature.GetSpecificFeature2();
swModel.ClearSelection2(true);
// Get the name of the mate
reference
strMateReferencename =
swMateReference.Name;
Debug.Print("Name
of mate reference is " +
strMateReferencename);
// Get the number of reference
entities in the mate reference
nCount =
swMateReference.ReferenceEntityCount;
Debug.Print("Number
of mate reference entities is " + nCount);
// Get the mate reference type
for the primary mate
//
entity in the selected mate reference
refEntType =
swMateReference.get_ReferenceType(0);
Debug.Print("Mating
type of primary mate entity is " +
refEntType);
// Get the mate reference
alignment for the
//
mate reference entity in the selected mate reference
mateRefAlignment =
swMateReference.get_ReferenceAlignment(0);
Debug.Print("Alignment
of primary mate entity is " +
mateRefAlignment);
// Get the mate reference
entity in the mate reference
mateRefObj =
swMateReference.get_ReferenceEntity2(0);
// Get the mate reference
entity type
mateRefEntityType =
swMateReference.get_ReferenceEntityType(0);
Debug.Print("Entity
type of primary mate entity is " +
mateRefEntityType);
// QueryInterface the returned
object as a Face, if a face
if
(mateRefEntityType == (int)swSelectType_e.swSelFACES)
{
Face2
mateRefFace = default(Face2);
mateRefFace = (Face2)mateRefObj;
Debug.Print("Primary
mate entity is a face with area = " +
mateRefFace.GetArea());
}
swModel.ClearSelection2(true);
}
public
SldWorks
swApp;
}
}