使用.NET(C#或VB.NET)开发NX外部程序

00219AD81.如何不用将exe程序拷贝到UGII目录下运行?

答:向上指在调用NX Open命令函数前,将当前目录移动到NX安装目录UGII\,NX安装目录必须和环境变量UGII_BASE_DIR的值一致,否则报错。可以使用如下代码:

Dim instalDir As String = Environment.GetEnvironmentVariable("UGII_BASE_DIR")
System.IO.Directory.SetCurrentDirectory(instalDir)

0021D3652.我的外部程序很小,不想打包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, "UGIImanagedNXOpen.dll"))
Reflection.Assembly.LoadFrom(IO.Path.Combine(ufdir, "UGIImanagedNXOpen.UF.dll"))
Reflection.Assembly.LoadFrom(IO.Path.Combine(ufdir, "UGIImanagedNXOpen.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 FilesSiemensNX 8.0UGIImanagedNXOpen.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="NXOpen.UF"  culture="neutral" publicKeyToken="null"/>
                <codeBase version="8.0.2.2" href="FILE://D:Program FilesSiemensNX 8.0UGIImanagedNXOpen.UF.dll"/>
            </dependentAssembly>
            <dependentAssembly>
                <assemblyIdentity name="NXOpen.Utilities"  culture="neutral" publicKeyToken="null"/>
                <codeBase version="4.0.0.0" href="FILE://D:Program FilesSiemensNX 8.0UGIImanagedNXOpen.Utilities.dll"/>
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>
原文地址:https://www.cnblogs.com/bizca/p/4978109.html