【心得】NXOpen通过选择控件选择点获取对应实体,以及选择面的法向量

NXOpen通过选择点控件,查询面与体的信息

说明:使用选择控件,通过设置选中的模式为面上的点。
在这里插入图片描述

通过点的tag,获得面上的点的平面

        /// <summary>
        /// 从点找到对应面,返回的是平面
        /// </summary>
        /// <param name="pointTag"></param>
        /// <returns></returns>
        public static Tag AskFaceTagFormPoint(Tag pointTag)
        {

            Tag pointFaceTag = Tag.Null;
            Tag[] parents;
            int nParents;
            theUfSession.So.AskParents(pointTag, UFConstants.UF_SO_ASK_ALL_PARENTS, out nParents, out parents); //查找关联对象

            for (int t = parents.Length - 1; t >= 0; t--)
            {
                int type, subtype;
                theUfSession.Obj.AskTypeAndSubtype(parents[t], out type, out subtype);

                if (type == 70 && subtype == 2) //面的tag类型分类
                {
                    pointFaceTag = parents[t];
                    break;
                }
            }

            return pointFaceTag;
        } 

从面Tag获取体的Tag

        private static Tag GetBodyLayerAndAtt(Tag faceTag)
        {
		Tag bodyTag; //获取到体的Tag
		theUfSession.Modl.AskFaceBody(faceTag, out bodyTag);
		return bodyTag;
		}

从体获取实体的属性与图层

从体获取属性与图层首先需要将Tag对象转换为NXopen的Body对象,需要使用万能转换函数进行转换。


        private static void GetBodyLayerAndAtt(Tag bodyTag)
        {
            Body selectBody = (Body)NXOpen.Utilities.NXObjectManager.Get(bodyTag); //Tag对象转换为Body
            string layerValue = selectBody.Layer.ToString(); //体图层
            var bodyAtt = selectBody.GetUserAttributes();
            List<string> bodyAttList = new List<string>(); //体的所有属性名称集合
            foreach (var att in bodyAtt)
            {
                string title = att.Title;//属性的名称
                string strValue = att.StringValue; //属性的值
                bodyAttList.Add(title);
            }
        }

获取面的法向量

        public static Vector3d AskFaceVector3d(Tag faceTag, Point3d selectPoint)
        {
            UFSession theUfSession = UFSession.GetUFSession();
            int type;
            double[] points = { selectPoint.X, selectPoint.Y, selectPoint.Z };
            double[] dirs = { 0, 0, 0 }; //面的法向量
            double[] box = { 0, 0, 0, 0, 0, 0 };
            double radius;
            double radData;
            int norm;
            theUfSession.Modl.AskFaceData(faceTag, out type, points, dirs, box, out radius, out radData, out norm);
            Vector3d faceVec = new Vector3d(dirs[0], dirs[1], dirs[2]);
            return faceVec;
        }
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值