C#:通用方法总结—第8集
创始人
2024-11-14 19:35:08

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

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

(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校验是否选中为圆柱面:

///

        ///圆柱面校验

        ///

        ///

        ///

        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验证选中面是不是平面:

        ///

        ///验证是不是平面

        ///

        ///

        ///

        ///

        ///

        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;

        }

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

相关内容

热门资讯

裸辞做“一人公司”,我后悔了 去年这个时候,一位以色列程序员正在东南亚旅行。他顺手把一个在脑子里转了很久的想法做成了产品,一个让任...
南京建成国内首个Pre-6G试... 4月21日,2026全球6G技术与产业生态大会在南京开幕。全息互动技术展台前,一名远在北京的工作人员...
超梵求职受邀参加“2025抖音... 超梵求职受邀参加“2025抖音巨量引擎成人教育行业生态大会”,探讨分享优质内容传播,服务万千学员。 ...
摩托罗拉Razr 2026(R... IT之家 4 月 22 日消息,摩托罗拉宣布新一代 Razr 折叠手机将于 4 月 29 日在美国发...
库克卸任,特纳斯领航:苹果新纪... 苹果首席执行官蒂姆·库克将卸任,硬件工程主管约翰·特纳斯将接任,苹果公司今天宣布此事。 库克将在夏季...