iCAx开思工具箱

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1595|回复: 1
打印 上一主题 下一主题

[技术交流] NXOpen C# 创建曲线

[复制链接]
跳转到指定楼层
楼主
发表于 2018-12-20 11:18:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册登录,享用更多网站功能!

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

x
using System;
using System.IO;
using NXOpen;
using NXOpen.UF;
namespace NetExample
{
/// <summary>
/// Summary description for EX_Curve_CreateArc.
/// </summary>
public class EX_Curve_CreateArc
{
        private static FileStream fs;
        private static StreamWriter w;
        private static UFSession theUfSession;
        private static Session theSession;
        public int Execute()
        {
            Tag UFPart;
            string part_name = "EX_Curve_CreateArc";
            int units =2;
            string name;
         
            theUfSession.Part.New(part_name, units, out UFPart);
            theUfSession.Part.AskPartName(UFPart, out name);
            w.WriteLine("Loaded: " + name);
            
            Tag arc, wcs;
            UFCurve.Arc arc_coords = new UFCurve.Arc();     
            
            /* Fill out the data structure */
            arc_coords.start_angle = 0.0;
            arc_coords.end_angle = 3.0;
            arc_coords.arc_center=new double[3];
            arc_coords.arc_center[0] = 0.0;
            arc_coords.arc_center[1] = 0.0;
            arc_coords.arc_center[2] = 1.0;
            arc_coords.radius = 2.0;
            
            theUfSession.Csys.AskWcs(out wcs);
            theUfSession.Csys.AskMatrixOfObject(wcs,out arc_coords.matrix_tag);
            theUfSession.Curve.CreateArc(ref arc_coords,out arc);
            theUfSession.Part.Save();
            return 0;
        }
        public static void Main(string[] args)
        {
            theSession=Session.GetSession();
            theUfSession= UFSession.GetUFSession();
            fs = new FileStream("EX_Curve_CreateArc.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_CreateArc.prt") )
   {
    w.WriteLine("Remove EX_Curve_CreateArc.prt file from <Project Folder>\\bin\\Debug !!");
    w.WriteLine("EX_Curve_CreateArc.prt already exists. !!");
    w.Close();
    return;
   }
            try
            {
                EX_Curve_CreateArc curveTest1 = new EX_Curve_CreateArc();
                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;
  }
}
}

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 支持支持
沙发
 楼主| 发表于 2018-12-20 11:23:27 | 只看该作者

马上注册登录,享用更多网站功能!

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

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

本版积分规则

手板模型制作,在线3D打印服务

QQ|小黑屋|手机版|开思工具箱 CAD工具箱_CAM工具箱  

GMT+8, 2024-4-26 11:23 , Processed in 0.016967 second(s), 18 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

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