Hi there,
I am trying to extract mate information from an open assembly. I referred to this example from SolidWorks API help: Get Mate and Mate Entities Example (VBA). For each mate under "Mates" feature in Feature Manage Design Tree, by using IMateEntity2.GetEntityParams() method, I get a set of parameters of each mate entity.
But here is a problem that I couldn't overcome. It's about how to get the name of mate entities associated in a mate by their parameters. I've done some searching on internet but with no progress. Does anyone have idea?
//------------------------------Code--------------------------------------------------------------------//
private void ExtractMateInformation_Click(object sender, EventArgs e)
{
SldWorks.SldWorks swApp = new SldWorks.SldWorks();
ModelDoc2 swModel;
Feature swFeat;
Face2 swFace;
Feature swMateFeat=null;
Feature swSubFeat;
PathTitleName Sub = new PathTitleName();
Mate2 swMate;
MateEntity2 swMateEntity_1;
MateEntity2 swMateEntity_2;
string MateFeatName = null;
swModel = (ModelDoc2)swApp.ActiveDoc;
swFeat = (Feature)swModel.FirstFeature();
// Iterate over features in FeatureManager design tree
while (!(swFeat == null))
{
if ("MateGroup" == swFeat.GetTypeName())
{
swMateFeat = (Feature)swFeat;
break;
}
swFeat = (Feature)swFeat.GetNextFeature();
}
MateFeatName = swMateFeat.Name;
// Get first mate, which is a subfeature
swSubFeat = (Feature)swMateFeat.GetFirstSubFeature();
while (!(swSubFeat == null))
{
swMate = (Mate2)swSubFeat.GetSpecificFeature2();
if (!(swMate == null))
{
string MateName = swSubFeat.Name;
string Component1 = swMate.MateEntity(0).ReferenceComponent.Name2;
string Component2 = swMate.MateEntity(1).ReferenceComponent.Name2;
int MateType = swMate.Type;
int MateAlignment = swMate.Alignment;
bool CanBeFlipped = Flipped;
int Entity1Type =swMate.MateEntity(0).ReferenceType;
int Entity2Type =swMate.MateEntity(1).ReferenceType;
//get two mate entities associated in this mate
swMateEntity_1 = (MateEntity2)swMate.MateEntity(0);
swMateEntity_2 = (MateEntity2)swMate.MateEntity(1);
//get a set of entity parameters
double[] EntityParams_1 = swMateEntity_1.EntityParams;
double[] EntityParams_2 = swMateEntity_2.EntityParams;
}
// Get the next mate in MateGroup
swSubFeat = (Feature)swSubFeat.GetNextSubFeature();
}
}
Cheers,
Bomiao