This website uses cookies to ensure you get the best experience on our website. By using our website you agree on the following Cookie Policy, Privacy Policy, and Terms Of Use
The following code example allows to output all assignable interfaces for the selected feature's definition and specific feature. The result is output to the Output window of VSTA editor.
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;
using System.Diagnostics;
namespace CodeStack.csproj
{
publicpartialclass SolidWorksMacro
{
publicvoid Main()
{
IFeature feat = swApp.IActiveDoc2.ISelectionManager.GetSelectedObject6(1, -1) as IFeature;
PrintFeatureTypes(feat);
}
privatevoid PrintFeatureTypes(IFeature feat)
{
object featDef = feat.GetDefinition();
if (featDef != null)
{
foreach (Type defType in FindSpecificInterfacesFromDispatch(featDef))
{
Debug.Print("Feature Definition: " + defType.FullName);
}
}
else
{
Debug.Print("Feature Definition: None");
}
object featSpec = feat.GetSpecificFeature2();
if (featSpec != null)
{
foreach (Type specType in FindSpecificInterfacesFromDispatch(featSpec))
{
Debug.Print("Specific Feature: " + specType.FullName);
}
}
else
{
Debug.Print("Specific Feature: None");
}
}
private IEnumerable<Type> FindSpecificInterfacesFromDispatch(object disp)
{
if (disp == null)
{
thrownew ArgumentNullException("disp");
}
Type[] types = typeof(ISldWorks).Assembly.GetTypes();
foreach (Type type in types)
{
if (type.IsInstanceOfType(disp))
{
yieldreturn type;
}
}
}
public SldWorks swApp;
}
}