C#实现“抑制”NX特征及约束

        static void SuppressedAllConstraintAndFeature(bool bSuppress)
        {
            try
            {
                Session theSession = Session.GetSession();
                UFSession theUfSession = UFSession.GetUFSession();
                UFUi theUFUi = theUfSession.Ui;

                string path = @"D:\test_model\_model1.prt";
                NXOpen.Tag obj = NXOpen.Tag.Null;
                UFPart.LoadStatus LoadStatus;
                theUfSession.Part.Open(path, out obj, out LoadStatus);
                NXOpen.Part part = theSession.Parts.Display;
                
                Feature[] features = part.Features.ToArray();

                if (bSuppress)
                {
                    part.Features.SuppressFeatures(features);
                }
                else
                {
                    part.Features.UnsuppressFeatures(features);
                }

                ComponentAssembly componentAssembly = part.ComponentAssembly;
                ComponentPositioner componentPositioner = componentAssembly.Positioner;
                ConstraintCollection constraintCollection = componentPositioner.Constraints;
                foreach (Constraint c in constraintCollection)
                {
                    c.Suppressed = bSuppress;
                }

                part.Save(BasePart.SaveComponents.True, BasePart.CloseAfterSave.True);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

 

posted @ 2021-03-03 17:13  快雪  阅读(226)  评论(0编辑  收藏  举报