Hi,
I am working on some code for an assembly document where I need to delete small features such as chamfers etc.. My code functions as intended as it lists every feature inside an assembly. But although the select2 method returns true nothing seems to get selected and therefore can't be deleted at the end. Thank you for your help.
here is my code:
public static void DelMinorFeats(ModelDoc2 modeldoc2)
{
AssemblyDoc swAssy = (AssemblyDoc)modeldoc2;
FeatureManager compFeatMan;
ModelDoc2 compModel;
Component2 comp;
Feature feat;
Object[] comps;
Object[] feats;
comps = swAssy.GetComponents(false);
foreach (Object oComp in comps)
{
comp = (Component2)oComp;
compModel = comp.GetModelDoc2();
compFeatMan = compModel.FeatureManager;
Debug.Print(comp.Name);
feats = compFeatMan.GetFeatures(true);
foreach (Object oFeat in feats)
{
feat = (Feature)oFeat;
if (feat.GetTypeName2() == "Chamfer" || feat.GetTypeName2() == "Fillet")
{
Debug.Print(" " + feat.Name);
feat.Select2(true, 0);
}
}
}
modeldoc2.EditDelete();
}
Hello,
You need to call EditPart2: 2013 SOLIDWORKS API Help - EditPart2 Method (IAssemblyDoc)
Then after deleting the feature use EditAssembly to switches back to the assembly: 2015 SOLIDWORKS API Help - EditAssembly Method (IAssemblyDoc)
look at this example to suppress a part feature in an assembly: 2015 SOLIDWORKS API Help - Suppress Component Feature Example (VBA)