ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
BLBomiao Li18/09/2012

Hi there,

I am new to solidwork api programming. Now I need to set name for mate entities associated in a mate in assembly. But I am stucked in getting corresponding entity from assembly level to part level.

First, I traverse all mates to get mate entities for each mate (refer to 2012 SolidWorks API help). For each mate, there are two mate entities (can be obtained by MateEntity2 swMateEntity_1 = (MateEntity2)swMate.MateEntity(0) and MateEntity2 swMateEntity_2 = (MateEntity2)swMate.MateEntity(1)). Take swMateEntity_1 as an example, the entity I get from mate reference in assembly context is Entity swEntity_1 = (Entity)swMateEntity_1.Reference.

Then, I  get the entity in part level. According to Artem (a nice guy who gave me some advices on this topic) 's point, after I get the entity from mate reference in assembly context, I need to convert it to part space by using IModelDocExtension::GetCorresponding() method to get the pointer to the entity in component level. I suppose I can get the entity in part level by using Entity swPartEntity_1=(Entity)swModelDocExtension.GetCorrespondingEntity(swEntity_1). swPartEntity_1 returns not null, but when I was trying to get the component it belongs to by Component2 Comp_1 = (Component2)Entity_1.GetComponent(); it returns nothing.

Finally,  I need to set name to this entity by using SetEntityName() method.

Anyone has insights on this?

Cheers,

Bomiao