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

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

下面是今天要介绍的通用方法:

(1)这个通用方法为SW查找草图数量

        /// <summary>

        /// 查找草图数量

        /// </summary>

        /// <param name="doc2"></param>

        /// <returns></returns>

        public static int FindSketchesNumber(ModelDoc2 doc2)

        {

            FeatureManager featureManager = doc2.FeatureManager;

            object[] features = (object[])featureManager.GetFeatures(true);

            int sketchCount = 0;

            // 遍历特征,统计3D草图的数量

            foreach (object feature in features)

            {

                Feature swFeature = (Feature)feature;

                if (swFeature.Name.Contains("3D草图"))

                {

                    sketchCount++;

                }

            }

            return sketchCount;

        }

(2)这个通用方法为SW获取选择对象的Entity:

        /// <summary>

        /// 获取选择实体对象

        /// </summary>

        /// <param name="swModel">传入的ModelDoc2类型参数</param>

        /// <returns></returns>

        public static Entity EntityPlateSurface(ModelDoc2 swModel)

        {

            var swSelMgr = (SelectionMgr)swModel.SelectionManager;

            var swEnt1 = (Entity)swSelMgr.GetSelectedObject6(1, -1);

            return swEnt1;

        }

(3)这个通用方法为SW获取选择对象的Component2

        /// <summary>

        /// 获取选择对象的Component2

        /// </summary>

        /// <param name="swcomp1">传入的Component2类型参数</param>

        /// <param name="swModel">传入的ModelDoc2类型参数</param>

        /// <returns></returns>

        public static Component2 GetEntityComponent(Component2 swcomp1, ModelDoc2 swModel)

        {

            bottomentity = null;

            var swSelMgr = (SelectionMgr)swModel.SelectionManager;

            swcomp1=(Component2)swSelMgr.GetSelectedObjectsComponent4(1,-1);

            SelectData = swSelMgr.CreateSelectData();

            bottonmodeldoc = (ModelDoc2)swcomp1.GetModelDoc2();

            bottomentity = (Entity)swSelMgr.GetSelectedObject6(1, -1);

            bottomid = swModel.Extension.GetPersistReference3(bottomentity);

            return swcomp1;

        }

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

  • 11
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

喵桑さん

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值