UG/NX二开Siemens官方实例解析 4.5 EX_DirPaths(目录和路径)

前言

        本系列文章主要讲解NXOpen UF API(简称ufun函数)的使用,之前看教学视频大都建议用ufun进行开发,这里西门子官方还专门给了一套系列文章来讲,说明官方也是特别推崇ufun。

        本人从事二开也有一段时间了,我的二开启蒙师父就特别喜欢用NXOpen API,用他的话来说“年少不知nxopen好,错把ufun当成宝”,其实就我个人而言,还是喜欢NXOPEN+ufun联合开发。


一、小节概要

本实例主要讲解了ufun函数目录和路径的使用方法,涉及一下几个函数:

1、theUfSession.Dirpath.CreateFromEnv   根据环境变量的值创建路径

2、theUfSession.Dirpath.AskDirs 从路径中提取目录

3、theUfSession.Dirpath.CreateFromDirs 从字符串表示的目录创建路径

4、theUfSession.Dirpath.AppendFromDirs 将字符串表示的目录添加到路径中

5、theUfSession.Dirpath.AskCurrDir 检索路径中当前目录的名称

6、theUfSession.Dirpath.AskNthDir 从路径获取第n个(由index指定)目录

三、程序分析

1、源码所在目录

UGOPEN\SampleNXOpenApplications\.NET\NXOpenExamples\EX_DirPaths

2、主要功能分析 

1、主方法及打印内容

public int Execute()
{
    Tag UFPart;
    string part_name = "EX_DirPath";
    int units =2; 
    string name;

    theUfSession.Part.New(part_name, units, out UFPart);
    theUfSession.Part.AskPartName(UFPart, out name);
    w.WriteLine("Loaded: " + name);
            
    int numdir =0;
    string[] path =null;
            
	Tag  retTag;
			
	theUfSession.Dirpath.CreateFromEnv("UGII_BASE_DIR",out retTag);
    theUfSession.Dirpath.AskDirs( retTag, out numdir, out path);

    for(int ii=0; ii<numdir; ii++)
    {
        w.WriteLine("Dir Path: " + path[ii]);
    }
			
	path = null;
	NXOpen.Tag a_path;
	string[] dirs = {"/dir1", "/dir2" };
	theUfSession.Dirpath.CreateFromDirs( 2, dirs, out a_path );
	theUfSession.Dirpath.AskDirs( a_path, out numdir, out path);

	for(int ii=0; ii<numdir; ii++)
	{
		w.WriteLine("Dir Path: " + path[ii]);
	}

	string[] dirs1 = {"/dir3", "/dir4" };
	theUfSession.Dirpath.AppendFromDirs( a_path, 2, dirs1 );

	theUfSession.Dirpath.AskDirs( a_path, out numdir, out path);

	string curr_dir;
    theUfSession.Dirpath.AskCurrDir(a_path, out curr_dir);
	w.WriteLine("Current Dir : " + curr_dir );

	string nth_dir="";
	w.WriteLine("Index\t" + " Nth Dir");
	for(int index=0;index<numdir;index++)
	{
		theUfSession.Dirpath.AskNthDir(a_path,index,out nth_dir);
		w.WriteLine(index + "\t" + nth_dir );
	}
 
	theUfSession.Part.Save();
    return 0;
}

打印内容如下:

 Log Entry : 
--Log entry goes here--
Loaded: D:\Program Files\Siemens\NX 8.0\EX_DirPath.prt
Dir Path: D:\Program Files\Siemens\NX 8.0
Dir Path: /dir1
Dir Path: /dir2
Current Dir : /dir1
Index     Nth Dir
0    /dir1
1    /dir2
2    /dir3
3    /dir4
Successful
End of Log File

 2、运用场景分析

在实际运用中,我们最常见的获取环境变量路径方法:

1、先创建路径  theUfSession.Dirpath.CreateFromEnv("UGII_BASE_DIR",out retTag);

2、再获取目录  theUfSession.Dirpath.AskDirs( retTag, out numdir, out path);

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

MarcoPro

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

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

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

打赏作者

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

抵扣说明:

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

余额充值