// Expands every node in the Feature Manager tree, given a Solidworks ModelDoc2 private void ExpandAllSolidworksFeaturesInTree(ModelDoc2 model) { Console.WriteLine("Expanding all features in Solidworks part..."); if (model == null) { ShowNonFatalError("Failed to open model. (ActiveDoc is null)"); return; } FeatureManager featureMgr = default(FeatureManager); TreeControlItem rootNode = default(TreeControlItem); // Get the root node of the Feature Manager tree featureMgr = model.FeatureManager; rootNode = featureMgr.GetFeatureTreeRootItem2((int)swFeatMgrPane_e.swFeatMgrPaneBottom); if ((rootNode == null)) { ShowNonFatalError("Failed to get root node of Feature Tree from part. (rootNode is null)"); return; } //TreeControlItem childNode = default(TreeControlItem); int nodeObjectType = rootNode.ObjectType; object nodeObject = rootNode.Object; // Ignore Annotations and History features if (rootNode.Text != "Annotations" && rootNode.Text != "History") { // Expand the node rootNode.Expanded = true; traverseLevel = traverseLevel + 1; //childNode = rootNode.GetFirstChild(); } traverseLevel = traverseLevel - 1; Console.WriteLine("Expanded all features in part successfully."); }
//public ArrayList ListeDesFonctionsDeArbre(String NomARechercher = "", String TypeDeLaFonction = "", Boolean AvecLesSousFonctions = false) //{ // Log.Print(cNOMCLASSE); // List<eFonction> pListeFonctions = ListeDesFonctionsDeArbre(NomARechercher, TypeDeLaFonction, AvecLesSousFonctions); // ArrayList pArrayFonctions = new ArrayList(); // if (pListeFonctions.Count > 0) // pArrayFonctions = new ArrayList(pListeFonctions); // return pArrayFonctions; //} /// <summary> /// Scanner le FeatureManager pour rechercher la vue /// </summary> /// <param name="Noeud"></param> /// <param name="NoeudVue"></param> private void ScannerVueFeatureManager(TreeControlItem Noeud, ref TreeControlItem NoeudVue) { Log.Methode(cNOMCLASSE); TreeControlItem pNoeud = Noeud.GetFirstChild(); while (pNoeud != null) { if (pNoeud.Text == _SwVue.GetName2()) { NoeudVue = pNoeud; return; } if (pNoeud.ObjectType != (int)swTreeControlItemType_e.swFeatureManagerItem_Component) ScannerVueFeatureManager(pNoeud, ref NoeudVue); if (NoeudVue != null) return; pNoeud = pNoeud.GetNext(); } }
/// <summary> /// Scanner les fonctions de la vue à partir du FeatureManager /// </summary> /// <param name="Noeud"></param> /// <param name="ListeFonctions"></param> /// <param name="NomARechercher"></param> /// <param name="TypeDeLaFonction"></param> /// <param name="AvecLesSousFonctions"></param> private void ScannerFonctionsFeatureManager(TreeControlItem Noeud, ArrayList ListeFonctions, String NomARechercher, String TypeDeLaFonction, Boolean AvecLesSousFonctions) { Log.Methode(cNOMCLASSE); TreeControlItem pNoeud = Noeud.GetFirstChild(); while (pNoeud != null) { eFonction pFonction = new eFonction(); if (pNoeud.ObjectType == (int)swTreeControlItemType_e.swFeatureManagerItem_Feature) { if (pFonction.Init(pNoeud.Object, ModeleDeReference) && Regex.IsMatch(pFonction.Nom, NomARechercher) && Regex.IsMatch(pFonction.TypeDeLaFonction, TypeDeLaFonction)) { ListeFonctions.Add(pFonction); } } // On scanne dans tous les cas le dossier Tôlerie et le dossier Etat déplié if (AvecLesSousFonctions || (pFonction.EstInitialise && (pFonction.TypeDeLaFonction == "TemplateSheetMetal")) || (pFonction.EstInitialise && (pFonction.TypeDeLaFonction == "TemplateFlatPattern"))) ScannerFonctionsFeatureManager(pNoeud, ListeFonctions, NomARechercher, TypeDeLaFonction, AvecLesSousFonctions); pNoeud = pNoeud.GetNext(); } }