C#:通用方法总结—第8集

avatar
作者
筋斗云
阅读量:0

大家好,今天继续讲解我们的通用方法系列。

下面是今天分享的通用方法:

(1)这个通用方法为Ug删除参数构建器方法:

publicstaticint RemoveParameters(int id)//删除参数构建器

    {

        UFSession.GetUFSession().Undo.SetMark(0, null, out id);

        BodyCollection Bodies = theSession.Parts.Work.Bodies;

        Body[] body = Bodies.ToArray();

        NXOpen.Features.RemoveParametersBuilder removeParametersBuilder1;

        removeParametersBuilder1 = theSession.Parts.Work.Features.CreateRemoveParametersBuilder();

        theSession.UpdateManager.SetDefaultUpdateFailureAction(NXOpen.Update.FailureOption.AcceptAll);

        for (int t = 0; t < body.Length; t++)

        {

            removeParametersBuilder1.Objects.Add(body[t]);

        }

        try

        {

            NXOpen.NXObject nXObject1;

            nXObject1 = removeParametersBuilder1.Commit();

            removeParametersBuilder1.Destroy();

        }

        catch (Exception e)

        {

            theUI.NXMessageBox.Show("提示", NXOpen.NXMessageBox.DialogType.Information, e.Message.ToString());

            return 0;

        }

        return id;

    }

(2)这个通用方法为SW校验是否选中为圆柱面:

///<summary>

        ///圆柱面校验

        ///</summary>

        ///<param name="swModel"></param>

        ///<returns></returns>

        publicint MesoporeVerify(ModelDoc2 swModel, SelectionMgr swSelMgr,ref Face2 face)

        {

            int result = 0;

            try

            {            

                Face2 swEnt1 = (Face2)swSelMgr.GetSelectedObject6(1, -1);

                face = swEnt1;

                if (swEnt1 != null)

                {

                    Surface surface = swEnt1.GetSurface();

                    if (!surface.IsCylinder())

                    {

                        result = -1;

                    }

                }

                else

                {

                    result = -1;

                }              

            }

            catch

            {

                result = -1;

            }

            return result;

        }

(3)这个通用方法为SW验证选中面是不是平面:

        ///<summary>

        ///验证是不是平面

        ///</summary>

        ///<param name="swModel"></param>

        ///<param name="swSelMgr"></param>

        ///<param name="face2"></param>

        ///<returns></returns>

        publicint VerifyPlan(ModelDoc2 swModel, SelectionMgr swSelMgr,ref Face2 face2)

        {

            int result = 0;

            try

            {

                Face2 swEnt1 = (Face2)swSelMgr.GetSelectedObject6(1, -1);

                face2 = swEnt1;

                if (swEnt1 != null)

                {

                    Surface surface = swEnt1.GetSurface();

                    if (!surface.IsPlane())

                    {

                        result = -1;

                    }

                }

                else

                {

                    result = -1;

                }

            }

            catch

            {

                result = -1;

            }

            return result;

        }

今天要介绍的就是这么多,我们下篇文章再见。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!