Hi,
I'm using SW 2011 SP3 and SW 2013 SP4.
I'm trying to get all components from big assembly and in the end I get different result of number children.
For SW 2011 the result is 7373 components for SW 2013 the result is 1374 components.
Can you explain why I have different results? API for getting components was changed for SW 2011 and SW 2013?
SolidworksApi macrosTake a look at the code below, please:
Object swDocSpecificationObj = swApp.GetOpenDocSpec(fileName);
var swDocSpecification = (IDocumentSpecification)swDocSpecificationObj;
swDocSpecification.Silent = true;
swDocSpecification.ReadOnly = true;
swDocSpecification.UseLightWeightDefault = false;
swDocSpecification.LightWeight = false;
IModelDoc2 swDoc = swApp.OpenDoc7(swDocSpecificationObj); // I see here different time of loading for SW 2011 and 2013, maybe this method was modified?
var swModel = (ModelDoc2)swApp.ActiveDoc;
var swConfMgr = (ConfigurationManager)swModel.ConfigurationManager;var activeConfig = (Configuration)swConfMgr.ActiveConfiguration;
var rootComponent = (Component2)activeConfig.GetRootComponent();
var numComponents = calcComponents(rootComponent, 1);
int calcComponents(IComponent2 comp, long nLevel)
{
int numComponents = 1;string sPadStr = " ";
long i = 0;
for(i = 0; i <= nLevel - 1; i++)
{sPadStr = sPadStr + " ";
}
var children = (object[])comp.GetChildren();
for(i = 0; i < children.Length; i++)
{Component2 swChildComp = (SW.Component2)children[i];
Debug.Print(sPadStr + "+" + swChildComp.Name2 + " <" + swChildComp.ReferencedConfiguration + ">");
numComponents += calcComponents(swChildComp, nLevel + 1);
}
Thanks in advance
return numComponents;
}