/// <summary> /// 对所有子件操作 /// </summary> /// <param name="comp"></param> /// <param name="action"></param> public static void UsingChildren(this IComponent2 comp, Action <Component2> action) { var child = comp.GetChildren() as Component2[]; if (child != null) { foreach (var item in child) { action(item); } } }
/// <summary> /// Gets the children. /// </summary> /// <param name="component">The component.</param> /// <returns></returns> private static List <IComponent2> GetChildren(IComponent2 component) { Array childComponentsArray = component.GetChildren(); var childComponents = new List <IComponent2>(); if (childComponentsArray == null) { return(childComponents); } foreach (IComponent2 comp in childComponentsArray) { childComponents.Add(comp); // Add the child childComponents.AddRange(GetChildren(comp)); // Recursively add children of the child } return(childComponents); }
public bool MoveNext() { if (m_CurChildIndex == -1) { m_Children = (m_Parent.GetChildren() as object[])?.Cast <IComponent2>().ToArray(); if (m_Children == null) { m_Children = new IComponent2[0]; } } m_CurChildIndex++; if (m_CurChildIndex < m_Children.Length) { m_CurComp = m_Children[m_CurChildIndex]; return(true); } else { return(false); } }
/// <summary> /// 获取组件的子组件 /// </summary> /// <param name="comp"></param> /// <returns></returns> public static IEnumerable <IComponent2> GetChildrenEx(this IComponent2 comp) { return(comp.GetChildren().CastObj <object[]>().Cast <IComponent2>()); }
public void GetParts(IComponent2 Comp) { try { if (Settings.Run) { bool Include = true; Object Children; //TreferencedDoc ActDoc = new TreferencedDoc(); if (!Comp.IsSuppressed())//Wenn Zeichnung nicht unterdrückt { Part part = new Part(); modeldoc = (ModelDoc2)Comp.GetModelDoc2(); if (modeldoc != null) { string FileName = Path.GetFileNameWithoutExtension(modeldoc.GetPathName()); part.Name = FileName.Substring(FileName.LastIndexOf("/") + 1); foreach (Part partfromList in Parts) { if (SWX.Settings.NotInBil && Comp.ExcludeFromBOM) { Include = false; break; } if (Settings.OnlyAssembly && modeldoc.GetType() != (int)swDocumentTypes_e.swDocASSEMBLY) { Include = false; break; } if (partfromList.Name == part.Name) { partfromList.Cnt++; Include = false; break; } } if (Include) { part.PathName = modeldoc.GetPathName(); part.RefConfig = Comp.ReferencedConfiguration; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Beschreibung = modeldoc.GetCustomInfoValue("", "Description"); part.IsFastener = modeldoc.GetCustomInfoValue("", "isfastener"); if (modeldoc.GetCustomInfoValue("", "Medienberührend").ToUpper() == "JA") { part.Zertifikat = true; } part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); modelDocExtension = modeldoc.Extension; //int ret = modelDocExtension.ToolboxPartType; //if (ret != 0) //{ // part.IsToolBoxPart = true; //} } } else { part.PathName = modeldoc.GetPathName(); string TempName = Path.GetFileNameWithoutExtension(Comp.GetPathName()); part.Name = TempName.Substring(TempName.LastIndexOf("/") + 1); //KKS.KKS_Message.Show(ActDoc.Name); part.RefConfig = ""; part.Released = modeldoc.GetCustomInfoValue("", "Status"); part.Revision = modeldoc.GetCustomInfoValue(part.RefConfig, "Revision"); } if (Include) { Parts.Add(part); } } Children = Comp.GetChildren(); foreach (Object com in (Object[])Children) { Child = (IComponent2)com; GetParts(Child); } } } catch (Exception ex) { if (KKS.KKS_Message.Show("Folgender Fehler ist aufgetreten. Um den Vorgang weiter zu führen Klicke auf OK. /n" + ex.Message, "Fehler", true, "OK", "Abbrechen") == System.Windows.Forms.DialogResult.Cancel) { Settings.Run = false; } } }
//public Stopwatch t = new Stopwatch(); public int GetParts(IComponent2 Comp) { try { bool Include = true; Object Children; if (!Comp.IsSuppressed())//Wenn Zeichnung nicht unterdrückt { Part part = new Part(); modeldoc = (ModelDoc2)Comp.GetModelDoc2(); if (modeldoc != null) { //string FileName = Path.GetFileNameWithoutExtension(modeldoc.GetPathName()); part.Name = modeldoc.GetCustomInfoValue("", "DokID"); //t.Stop(); //Settings.LogAdd(t.Elapsed.Milliseconds.ToString(), Cnt.ToString(), part.Name); //t.Reset(); //t.Start(); foreach (Part partfromList in Parts) { if (SWX.Settings.NotInBil && Comp.ExcludeFromBOM) { Include = false; break; } if (partfromList.Name == part.Name) { partfromList.Cnt++; Include = false; break; } } if (Include) { if (modeldoc.GetCustomInfoValue("", "Medienberührend").ToUpper() == "JA") { part.Zertifikat = true; } part.ArtNr = modeldoc.GetCustomInfoValue("", "Artikelnummer"); part.Beschreibung = modeldoc.GetCustomInfoValue("", "Description"); Parts.Add(part); } } if (Include) { } } Children = Comp.GetChildren(); Cnt++; foreach (Object com in (Object[])Children) { Child = (IComponent2)com; GetParts(Child); } } catch (Exception ex) { if (KKS.KKS_Message.Show("Folgender Fehler ist aufgetreten. Um den Vorgang weiter zu führen Klicke auf OK. /n" + ex.Message, "Fehler", true, "OK", "Abbrechen") == System.Windows.Forms.DialogResult.Cancel) { } } return(Cnt); }