1.如何不用将exe程序拷贝到UGII目录下运行?
答:在调用NX Open命令函数前,将当前目录移动到NX安装目录\UGII\,NX安装目录必须和环境变量UGII_BASE_DIR的值一致,否则报错。可以使用如下代码:
Dim instalDir As String = Environment.GetEnvironmentVariable("UGII_BASE_DIR") System.IO.Directory.SetCurrentDirectory(instalDir)
2.我的外部程序很小,不想打包NX的.NET库文件一起发布,而是使用用户的库文件,要怎样做呢?
答:第一步,显示项目所有文件,展开Application.myapp文件,再打开Application.Designer.vb文件,为MyApplication添加Startup事件回调函数,在里面添加如下代码:
Dim ufdir As String = Environment.GetEnvironmentVariable("UGII_BASE_DIR") Reflection.Assembly.LoadFrom(IO.Path.Combine(ufdir, "\UGII\managed\NXOpen.dll")) Reflection.Assembly.LoadFrom(IO.Path.Combine(ufdir, "\UGII\managed\NXOpen.UF.dll")) Reflection.Assembly.LoadFrom(IO.Path.Combine(ufdir, "\UGII\managed\NXOpen.Utilities.dll"))
第二步,修改程序运行配置文件:你的exe程序文件名.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="NXOpen" culture="neutral" publicKeyToken="null"/> <codeBase version="8.0.2.2" href="FILE://D:\Program Files\Siemens\NX 8.0\UGII\managed\NXOpen.dll"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="NXOpen.UF" culture="neutral" publicKeyToken="null"/> <codeBase version="8.0.2.2" href="FILE://D:\Program Files\Siemens\NX 8.0\UGII\managed\NXOpen.UF.dll"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="NXOpen.Utilities" culture="neutral" publicKeyToken="null"/> <codeBase version="4.0.0.0" href="FILE://D:\Program Files\Siemens\NX 8.0\UGII\managed\NXOpen.Utilities.dll"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>