C# how to convert or cast the AssemblyDoc to Component2?
IConfiguration::GetRootComponent3 will return the active assembly as IComponent2.
SolidWorks API Tutorials
Can I be named Artem?
AssemblyDoc rootAssy = (AssemblyDoc)swModel;
Object allComponents = (Object)rootAssy.GetComponents(true);
for (int i = 0; i < allComponents.Length; i++)
ModelDoc2 currentPart = ((Component2)allComponents[i]).GetModelDoc2();//Here could be your assembly obtained somewhere before.
if (currentPart.GetType() == (int)swDocumentTypes_e.swDocASSEMBLY)
AssemblyDoc innerAssy = (AssemblyDoc)currentPart;
ModelDoc2 innerModDoc = (ModelDoc2)innerAssy;
String compName = Path.GetFileNameWithoutExtension(innerModDoc.GetPathName());
Component2 requComp = rootAssy.FeatureByName(compName);
foreach (Component2 currentComp in allComponents)
Boolean found = true;
Thank to you both guys appreciated it , both ways worked for me thanks again!
Please mark someone's answer as correct if your problem is resolved.
Please mark as answer Keith message. Perhaps for him it is very important, since he pays attention to it. I had enough of your usual "thank you"
Retrieving data ...