Hello everyone. I am trying to develop a C# application by Solidworks API. I got the following code block from Codestack and modified it for my purpose. It works perfectly for some components but
“swEnt = swComp.GetCorresponding(swEnt);” returns null for some components. If I dont use GetCorresponding() method this time I can’t select the returned “Entity” object in my another method. I couldn’t find a way out to solve it and I would really appriciate your help. Please see the codes below:
private Entity GetNamedEntityFromPart(Component2 swComp, string name, NamedEntityType_e entType)
{
ModelDoc2 model = (ModelDoc2)swComp.GetModelDoc2();
swSelectType_e selType = swSelectType_e.swSelFACES; // Default to Faces
switch (entType)
{
case NamedEntityType_e.Face:
selType = swSelectType_e.swSelFACES;
break;
case NamedEntityType_e.Edge:
selType = swSelectType_e.swSelEDGES;
break;
case NamedEntityType_e.Vertex:
selType = swSelectType_e.swSelVERTICES;
break;
}
Entity swEnt = null;
if (model != null)
{
if (model.GetType() == (int)swDocumentTypes_e.swDocPART)
{
PartDoc swPart = (PartDoc)model;
swEnt = swPart.GetEntityByName(name, (int)selType);
swEnt = swComp.GetCorresponding(swEnt); //This line returns null in some cases
}
}
return swEnt;
}