NXOPEN/UG二次开发C#---投影(等弧长投影为例)

11 篇文章 11 订阅
   /// <summary>
        /// 等弧长投影函数底层
        /// </summary>
        /// <param name="lines"></param>
        /// <param name="faces"></param>
        /// <param name="layer"></param>
        /// <param name="deleteGroup"></param>
        /// <returns></returns>
        private static TaggedObject[] _DengHuChangTouYing(TaggedObject[] lines, TaggedObject[] faces, int layer = -1, bool deleteGroup = true)
        {
            if (lines.Length == 0 || faces.Length == 0 || layer > 256 || layer < -1)
            {
                return new TaggedObject[0];
            }
            //获取颜色
            Curve curve = (Curve)lines[0];
            int color = curve.Color;

            //第一个参数:投影曲线的数量
            int n_curve_refs = lines.Length;

            //第二个参数:投影曲线,点的tag
            Tag[] curve_refs = WZCommonly.TaggedObjectToTag(lines);

            //第三个参数:投影到面的数量
            int n_face_refs = 1;

            //第四个参数:投影到面的tag
            Tag[] face_refs = WZCommonly.TaggedObjectToTag(faces);


            //第五个参数:投影的模式:
            //              1.复制
            //              2.移动
            //              3.关联
            int copy_flag = 2;

            //第六个参数:投影的相关数据
            Proj1 proj_data = new Proj1();
            //六-1:投影的数据
            proj_data.proj_data = new Proj();

            //六-1-1:投影的方式
            //          1 - 沿面法线,
            //          2 - 朝向点,
            //          3 - 沿矢量,
            //          4 - 与矢量成角度
            //          5 - 朝向一条线
            //          6 - 等弧长
            proj_data.proj_data.proj_type = 6;

            //六-1-2:"2-朝向点"或"6-等弧长"的点eid,"5-朝向一条线"的线或基准轴eid
            Tag pointEid;
            double[] pointXYZ = new double[] { 0.0, 0.0, 50.0 };
            UFSession.GetUFSession().Curve.CreatePoint(pointXYZ, out pointEid);
            proj_data.proj_data.proj_pnt = pointEid;

            //六-1-3:"3 - 沿矢量"、"4 - 与矢量成角度"、"6 - 等弧长"的向量
            double[] proj_vec = new[] { 0.0, 0.0, 1.0 };
            proj_data.proj_data.proj_vec = proj_vec;

            //六-1-4:"6 - 等弧长"的X轴矢量
            double[] x_vector = new double[] { 1.0, 0.0, 0.0 };
            proj_data.proj_data.x_vector = x_vector;

            //六-1-5:"3 - 沿矢量"的模式:
            //                  1.单向
            //                  2.双向
            int multiplicity = 1;
            proj_data.proj_data.multiplicity = multiplicity;

            //六-1-6:"6 - 等弧长"的模式:
            //                  0.同时X和Y
            //                  1.首先X,然后Y
            //                  2.首先Y,然后X
            //                  3.只有X
            //                  4.只有Y
            int arcl_option = 0;
            proj_data.proj_data.arcl_option = arcl_option;

            //六-1-7:"4 - 与矢量成角度"的角度
            double angle = 0.0;
            proj_data.proj_data.angle = angle;

            //六-1-8:"4 - 与矢量成角度"的参考点
            double[] ref_pnt = new[] { 0.0, 0.0, 0.0 };
            proj_data.proj_data.ref_pnt = ref_pnt;


            //六-2:"3 - 沿矢量"、"4 - 与矢量成角度"、"6 - 等弧长"的矢量标记,如果proj_向量不是NULL_标记,项目向量数组将不被使用
            Tag proj_vector = Tag.Null;
            proj_data.proj_vector = proj_vector;

            //六-3:"6 - 等弧长"的X轴矢量标记如果x_向量_标记不是NULL_标记,不使用x_矢量数组
            Tag x_vector_tag = Tag.Null;
            proj_data.x_vector_tag = x_vector_tag;

            //六-4:投影曲线的连接选项
            //      UF_CURVE_NO_JOIN= 0
            //          不要把曲线连接起来
            //      UF_CURVE_CUBIC_JOIN
            //          创建三次多项式连接曲线
            //      UF_CURVE_GENERAL_JOIN
            //          创建常规样条曲线连接曲线
            //      UF_CURVE_QUINTIC_JOIN
            //          创建五次多项式连接曲线
            JoinTypes join_type = 0;
            proj_data.join_type = join_type;

            //六-5:曲线拟合选项
            UFModl.CurveFitData curve_fit_data = new UFModl.CurveFitData(); ;
            proj_data.curve_fit_data = curve_fit_data;


            //七:投影曲线的tag
            Tag proj_curve_feature = Tag.Null;
            UFSession.GetUFSession().Curve.CreateProjCurves1(n_curve_refs, curve_refs, n_face_refs, face_refs, copy_flag, ref proj_data, out proj_curve_feature);

            //八.删除辅助点
            UFSession.GetUFSession().Obj.DeleteObject(pointEid);

            //从投影生成的组中提取所有曲线的tag,为了更改颜色和图层
            Tag[] touYingLines = new Tag[lines.Length];
            int touYingLinesCount;
            UFSession.GetUFSession().Group.AskGroupData(proj_curve_feature, out touYingLines, out touYingLinesCount);


            //设置颜色和图层
            if (layer > 0)//指定图层
            {
                for (int i = 0; i < touYingLinesCount; i++)
                {
                    UFSession.GetUFSession().Obj.SetColor(touYingLines[i], color);
                    UFSession.GetUFSession().Obj.SetLayer(touYingLines[i], layer);
                }
            }
            else if (layer == -1)//工作图层
            {
                for (int i = 0; i < touYingLinesCount; i++)
                {
                    UFSession.GetUFSession().Obj.SetColor(touYingLines[i], color);
                }
            }
            else//线的原始图层!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!有问题
            {
                TaggedObject taggedObject;
                NXOpen.Curve line;
                for (int i = 0; i < touYingLinesCount; i++)
                {
                    taggedObject = NXObjectManager.Get(touYingLines[i]);
                    line = (NXOpen.Curve)taggedObject;
                    UFSession.GetUFSession().Obj.SetColor(touYingLines[i], color);
                    UFSession.GetUFSession().Obj.SetLayer(touYingLines[i], line.Layer);
                }
            }


            //取消分组
            if (deleteGroup)
            {
                UFSession.GetUFSession().Group.UngroupAll(proj_curve_feature);
            }

            return WZCommonly.TagToTaggedObject(touYingLines);
        }

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值