/// <summary>
        /// 对所有子件文档操作
        /// </summary>
        /// <param name="comp"></param>
        /// <param name="action"></param>
        public static void UsingCompModelDoc2(this IComponent2 comp, Action <ModelDoc2> action)
        {
            ModelDoc2 swModel = comp.GetModelDoc2() as ModelDoc2;

            if (swModel != null)
            {
                action(swModel);
            }
        }
 /// <summary>
 /// 直接返回转换类型的ModelDoc对象
 /// </summary>
 /// <param name="comp"></param>
 /// <returns></returns>
 public static ModelDoc2 GetModelDoc2Ex(this IComponent2 comp)
 {
     try
     {
         return(comp.GetModelDoc2() as ModelDoc2);
     }
     catch (NullReferenceException)
     {
         throw;
     }
 }
        // Suppresses limit mates to make it easier to find the free degree of freedom in a joint
        public List<Mate2> suppressLimitMates(IComponent2 component)
        {
            ModelDoc2 modelDoc = component.GetModelDoc2();
            List<Mate2> limitMates = new List<Mate2>();

            object[] objs = component.GetMates();

            //limit mates aren't always present
            if (objs != null)
            {
                foreach (object obj in objs)
                {
                    if (obj is Mate2)
                    {
                        Mate2 swMate = (Mate2)obj;
                        if (swMate.MinimumVariation != swMate.MaximumVariation)
                        {
                            limitMates.Add(swMate);
                        }
                    }
                }
            }
            
            foreach (Mate2 swMate in limitMates)
            {
                ModelDoc2 doc = component.GetModelDoc2();
                Feature feat = (Feature)swMate;
                feat.Select(false);
                feat.SetSuppression2((int)swFeatureSuppressionAction_e.swSuppressFeature, (int)swInConfigurationOpts_e.swThisConfiguration, null);
            }

            return limitMates;
        }
        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);
        }