Hello there,
I have an assembly that is export to create a BOM but the order is wrong in so many level.
I saw the answer for with someone saying " If you do mind the order of the tree you will have to traverse on the features tree and look for components. The API help is not explaining that so let me know if you need help."
I need your help please.
Basically I have :
here I load my active doc to get my assembly/part
public override BomNode LoadItemTree()
{
TraceEnterMethod();
var doc = (ModelDoc2)_swApp.ActiveDoc;
if (doc == null) return null;
var selMgr = (ISelectionMgr)doc.SelectionManager;
var obj = selMgr.GetSelectedObject6(1,-1);
object objToProcess=null;
SWDocument swdoc = null;
(some validation)
swdoc = new SWDocument(doc, (IComponent2)objToProcess, configName);
public SWDocument(IModelDoc2 openDocument, IComponent2 selectedObject, string configurationName = null)
{
_errorsLoading = new List
IModelDoc2 model;
if (selectedObject == null)
model = openDocument;
else if ((IModelDoc2)((Component2)selectedObject).GetModelDoc() == null)
model = openDocument;
else
model = (IModelDoc2)((Component2)selectedObject).GetModelDoc();
(some code)
else if (model is AssemblyDoc)
{
var asmRootDoc = (AssemblyDoc)model;
if(CadSettingsController.Instance.GlobalSettings.SolidworksSettings.ResolveLightweightAssemblies)
asmRootDoc.ResolveAllLightWeightComponents(true);
var rootAssembly = (Component2)docConfig.GetRootComponent3(true);
var assembly = new Assembly(0, (AssemblyDoc)model, docConfig, rootAssembly, null);
LoadAssemblyParts(assembly);
LoadSubAssemblies(assembly);
_rootItem = assembly;
}
private static void LoadAssemblyParts(Assembly assembly)
{
var lastLoadedPart = string.Empty;
var childs = (object[])assembly.SwComponent.GetChildren();
var childCount = childs.Length;
for (var i = 0; i < childCount; i++)
{
var aChild = (Component2)childs[i];
if (aChild.IsSuppressed() || aChild.ExcludeFromBOM)
continue;
var itemDoc = (ModelDoc2)aChild.GetModelDoc2();
if (itemDoc == null)
{
_errorsLoading.Add(\\\$"Parent Item = {assembly.Name} - Last element = {lastLoadedPart}");
continue;
}
var docConfig = (Configuration)itemDoc.GetConfigurationByName(aChild.ReferencedConfiguration);
if (!(itemDoc is PartDoc))
continue;
var part = new Part(assembly.Level + 1, (PartDoc)itemDoc, docConfig, aChild, assembly);
if (assembly.AddChild(part))
LoadProfilesAndWeldments(part);
lastLoadedPart = part.Name;
}
}
I saw 2014 SOLIDWORKS API Help - Traverse Features By Reverse Position Example (C#) but don't know how to apply or use it to get the order and the parts.
Thank you for your help.
SolidworksApi macros
Interesting!
This remark from the API help should clear everything for you:
IFeatureManager::GetFeatures(bool TopLevelOnly):
If TopLevelOnly is false, then this method gets all of the feature and child features in this document. It does not get features in components.
The features that are returned by this method can be in any order. You should not rely on the order to indicate anything about children or parents. If hierarchy and order information is needed, then use IPartDoc::FirstFeature or IPartDoc::IFirstFeature or IModelDoc2::FirstFeature or IModelDoc2::FirstFeature, IFeature::GetNextFeature or IFeatureIGetNextFeature, IFeature::GetFirstSubFeature or IFeature::IGetFirstSubFeature, and IFeature::GetNextSubFeature or IFeature::IGetNextSubFeature to retrieve your information.
GetRootComponent ne garantit pas l'ordre des composants. La seul façon de conserver l'ordre de composants est d'utiliser GetFirstFeature pour en avoir la première Feature dans l'arabe (Bien evidemment le feature est un composant) et ensuite il fallait juste d'utiliser GetFirstSubFeature pour savoir si c'est un assemblage et en faire une récursion! Pour parcourir un niveau n-1, utiliser GetNextSubFeature.
Merci!
Petite question: J'adore l'interface graphique (ribbon en bleu)! ou avez vous la trouver?
We are using Infragistics for our UI thats where we got our ribbon bar
Thank you for the information I'll try it out might be the correct answer.
Thanks Julien!