找回密码 注册 QQ登录
开思网工业级高精度在线3D打印服务

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 16860|回复: 1
打印 上一主题 下一主题

关于NXOpenExamples中的一个例子

[复制链接]
跳转到指定楼层
1
发表于 2005-8-6 22:40:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
UGNX帮助中通过点绘制Spline的例子如下:
  
using System;
using System.IO;
using NXOpen;
using NXOpen.UF;
  
namespace NetExample
{
  /// <summary>
  /// Summary description for EX_Curve_CreateArc.
  /// </summary>
  public class EX_Curve_CreateSplineThruPts
  {
        private static FileStream fs;  
        private static StreamWriter w;
        private static UFSession theUfSession;
        private static Session theSession;
  
  
        //Constants
        public const int NUMBER_POINTS = 5;
  
        public const int UF_CURVE_SLOPE_NONE = -1;  /* UF_CURVE_ASK_SPLINE_THRU_PTS */
        public const int UF_CURVE_SLOPE_AUTO =  0;   /* UF_CURVE_ASK_SPLINE_THRU_PTS */
        public const int UF_CURVE_SLOPE_DIR  =  1;   /* UF_CURVE_ASK_SPLN_BY_DEF_DATA */  
        public const int UF_CURVE_SLOPE_VEC  =  2;   /* UF_CURVE_ASK_SPLN_BY_DEF_DATA */
  
        public const int UF_CURVE_CRVATR_NONE = -1;  /* UF_CURVE_CREATE_SPLINE_THRU_PTS */
        public const int UF_CURVE_CRVATR_AUTO_DIR = 1;   /* UF_CURVE_CREATE_SPLINE_THRU_PTS */
        public const int UF_CURVE_CRVATR_VEC = 2;   /* UF_CURVE_CREATE_SPLINE_THRU_PTS */
    
        public int Execute()
        {
            Tag UFPart;
            string part_name = "EX_Curve_CreateSplineThruPts";
            int units =2;  
            string name;
  
            theUfSession.Part.New(part_name, units, out UFPart);
            theUfSession.Part.AskPartName(UFPart, out name);
            w.WriteLine("Loaded: " + name);
            
            /* B-spline parameters  */
            int degree = 3;
            int periodicity = 0;
            int num_points = NUMBER_POINTS;
  
            /* Point/slope UFCurve attribute array */
            UFCurve.PtSlopeCrvatr[] point_data = new UFCurve.PtSlopeCrvatr[NUMBER_POINTS];
            
            /* Arrays of user's defining point data */
            double[] parameters={0.00,  0.17,  0.32,  0.45, 1.23};
            double[] points = {1.1000,  0.5320,  2.0000,
                                  1.5240,  0.6789,  2.3000,
                                  2.0000,  0.9000,  3.5956,
                                  2.3456,  1.3456,  3.7890,
                                  3.1000,  2.4567,  3.3214};
            int[] slopeTypes = { UF_CURVE_SLOPE_DIR,
                                   UF_CURVE_SLOPE_AUTO,
                                   UF_CURVE_SLOPE_NONE,
                                   UF_CURVE_SLOPE_DIR,
                                   UF_CURVE_SLOPE_VEC};
            double[] slopeVecs = {1.2300,  5.0506,  4.0360,
                                     0.0000,  0.0000,  0.0000,
                                     0.0000,  0.0000,  0.0000,
                                     0.5000,  1.0000,  0.5000,
                                     1.0000, -2.0000,  1.0000};
            int[] crvatrTypes = {UF_CURVE_CRVATR_NONE,
                                    UF_CURVE_CRVATR_AUTO_DIR,
                                    UF_CURVE_CRVATR_NONE,
                                    UF_CURVE_CRVATR_VEC,
                                    UF_CURVE_CRVATR_VEC};
            double[] crvatrVecs = {0.0000,  0.0000,  0.0000,
                                      1.0000,  2.5780,  5.6700,
                                      0.0000,  0.0000,  0.0000,
                                      1.0000,  -1.0000,  1.0000,
                                      -1.0000,  -1.0000,  -1.0000};
            int i, save_def_data = 1;
  
            Tag spline_tag;
            for (i= 0;   i<NUMBER_POINTS; i++)
            {
                point_data.point= new double[3];  
                point_data.point[0] = points[3*i];
                point_data.point[1] = points[3*i+1];
                point_data.point[2] = points[3*i+2];
                point_data.slope_type = slopeTypes;
                point_data.slope= new double[3];  
                point_data.slope[0] = slopeVecs[3*i];
                point_data.slope[1] = slopeVecs[3*i+1];
                point_data.slope[2] = slopeVecs[3*i+2];
                point_data.crvatr_type = crvatrTypes;
                point_data.crvatr= new double[3];  
                point_data.crvatr[0] = crvatrVecs[3*i];
                point_data.crvatr[1] = crvatrVecs[3*i+1];
                point_data.crvatr[2] = crvatrVecs[3*i+2];
            }
            /* Create B-spline UFCurve */
            theUfSession.Curve.CreateSplineThruPts(degree,
                periodicity,
                num_points,
                point_data,
                parameters,
                save_def_data,
                out spline_tag);
            theUfSession.Part.Save();
            return 0;
        }
        public static void Main(string[] args)
        {
            theSession=Session.GetSession();
            theUfSession= UFSession.GetUFSession();
  
            fs = new FileStream("EX_Curve_CreateSplineThruPts.log", FileMode.Create, FileAccess.Write);
            w = new StreamWriter(fs); // create a stream writer  
            w.Write("Log Entry : \r\n");
            w.WriteLine("--Log entry goes here--");  
            w.Flush(); // update underlying file
  
      if ( File.Exists("EX_Curve_CreateSplineThruPts.prt") )  
      {
        w.WriteLine("Remove EX_Curve_CreateSplineThruPts.prt file from &ltroject Folder>\\bin\\Debug !!");
        w.WriteLine("EX_Curve_CreateSplineThruPts.prt already exists. !!");
        w.Close();
        return;
      }
  
            try
            {
                EX_Curve_CreateSplineThruPts curveTest1 = new EX_Curve_CreateSplineThruPts();
                if (curveTest1.Execute()==0)
                {
                    w.WriteLine("Successful");
                }
                else
                {
                    w.WriteLine("Failed");
                }
            }
            catch(NXException e)
            {   
                w.WriteLine("Exception is: {0}", e.Message);
            }
            w.WriteLine("End of Log File");
            w.Close();
        }
    public static int GetUnloadOption(string dummy)  
    {
      return UFConstants.UF_UNLOAD_IMMEDIATELY;
    }
  }
}
  
请问这里的
double[] slopeVecs = {1.2300,  5.0506,  4.0360,
                                     0.0000,  0.0000,  0.0000,
                                     0.0000,  0.0000,  0.0000,
                                     0.5000,  1.0000,  0.5000,
                                     1.0000, -2.0000,  1.0000};和
            double[] crvatrVecs = {0.0000,  0.0000,  0.0000,
                                      1.0000,  2.5780,  5.6700,
                                      0.0000,  0.0000,  0.0000,
                                      1.0000,  -1.0000,  1.0000,
                                      -1.0000,  -1.0000,  -1.0000};
数组中的具体值应该怎样确定。
请各位大虾帮忙,谢谢了!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
发表于 2005-8-8 16:03:04 | 只看该作者

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-11-24 07:16 , Processed in 0.028823 second(s), 10 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表