本文主要是介绍SOLIDWORKS PDM 独立程序 C#,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本主题介绍如何创建登录到 一个 SOLIDWORKS PDM Professional 文件库,并列出根文件夹中的文件。
- 启动Visual Studio.
- 文件 > 新建 > 项目 > Visual C# > WPF(也可以使用WF)
- 输入程序名称
- 选择存储路径
- 确定
- 在解决方案资源管理器中右键项目名称,添加引用,将SOLIDWORKS PDM Professional primary assembly interop 添加到你的项目中
- 导航到PDM的安装根目录
- 选择 EPDM.Interop.epdm.dll,这里复制到项目下。
- 打开
- 添加
- 关闭
- 导航到PDM的安装根目录
- 更改 .NET Framework 和目标的版本
- 项目 > 属性 > 生成 ,并将“平台目标”设置为“任何 CPU”。
- 选择应用程序,将目标框架设置为.NET Framework 4
- 确定
- 项目 > 属性 > 生成 ,并将“平台目标”设置为“任何 CPU”。
-
添加 按钮从到窗体上。
- 双击按钮,将代码窗口中的所有代码替换为以下内容
using System; using System.Windows; using EPDM.Interop.epdm;//新增namespace SW_PDM__Standalone_APP_DEMO {/// <summary>/// MainWindow.xaml 的交互逻辑/// </summary>public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void Button_Click(object sender, RoutedEventArgs e){try{//Create a file vault interface and log into a vault//创建文件库登录IEdmVault5 vault = new EdmVault5();vault.LoginAuto("JXEM",0 /*this.Handle.ToInt32()*/); //JXEM:MyVaultName//Get the vault's root folder interface//获取库根目录string message = "";IEdmFile5 file = null;IEdmFolder5 folder = null;folder = vault.RootFolder;//Get position of first file in the root folder//获取根文件夹中第一个文件的位置IEdmPos5 pos = null;pos = folder.GetFirstFilePosition();if (pos.IsNull){message = "The root folder of your vault does not contain any files.";MessageBox.Show(message);return;}message = "The root folder of your vault contains these files: " + "\n";while (!pos.IsNull){file = folder.GetNextFile(pos);message = message + file.Name + "\n";}//Show the names of all files in the root folder//显示根文件夹中所有文件的名称MessageBox.Show(message);}catch (System.Runtime.InteropServices.COMException ex){MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + "\n" + ex.Message);}catch (Exception ex){MessageBox.Show(ex.Message);}}} }
- 把代码中的 MyVaultName 替换为 你计算机中的库名,这里是JXEM。
- F5调试
- 单击按钮,将显示一个消息框,其中包含 指定库的根文件夹中的文件,或通知您 指定库的根文件夹不包含任何文件。
-
关闭窗体。
-
注意:这里要先在windows 资源管理器手动登录下,再使用这个程序。
程序打包 https://download.csdn.net/download/hd51cc/87871608
提醒:
1.测试机需要安装SW PDM
2.运行前需要登录库
Stand-alone Applications (VB.NET)
Stand-alone Applications (C++)
这篇关于SOLIDWORKS PDM 独立程序 C#的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!