SolidWorks PDM二次开发—获取库中的文件信息
在休息了一个月之后,博客继续开始更新。
今天我们简单一点,直接上代码。
private void btnGetSelectFileInfo_Click(object sender, EventArgs e)
{
try
{
var vault = new EdmVault5();
//登陆到库中
vault.LoginAuto("PDM2020Default", this.Handle.ToInt32());
//如果用户登录成功,显示下本地库根目录路径
if (!vault.IsLoggedIn) return;
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = vault.RootFolderPath;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() != DialogResult.OK) return;
GetFileInformation(vault, openFileDialog.FileNames[0]);
return;
}
catch (Exception exception)
{
Console.WriteLine(exception);
throw;
}
}
/// <summary>
/// 显示库文件中的一信息
/// </summary>
/// <param name="vault1">库对象</param>
/// <param name="filePath">文件路径</param>
private void GetFileInformation(IEdmVault5 vault1, string filePath)
{
try
{
IEdmVault7 vault2 = null;
vault2 = (IEdmVault7)vault1;
IEdmFile14 aFile = default(IEdmFile16);
IEdmFolder5 ppoRetParentFolder;
aFile = (IEdmFile16)vault2.GetFileFromPath(filePath, out ppoRetParentFolder);
//Get configurations 获取配置
string msg = "Configurations: " + "\r\n";
IEdmFolder5 folder = default(IEdmFolder5);
folder = vault2.RootFolder;
EdmStrLst5 cfgList = default(EdmStrLst5);
cfgList = aFile.GetConfigurations();
IEdmPos5 pos = default(IEdmPos5);
pos = cfgList.GetHeadPosition();
while (!pos.IsNull)
{
var cfgName = cfgList.GetNext(pos);
msg = msg + cfgName + "\r\n";
}
msg = msg + "\r\n";
//Get type of file 文件类型
int typ = 0;
typ = (int)aFile.FileType;
msg = msg + "EdmFileType: " + typ + "\r\n";
msg = msg + "\r\n";
//Get category of file 文件类别
IEdmCategory6 cat = default(IEdmCategory6);
cat = aFile.Category;
if ((cat != null))
{
msg = msg + "Category: " + cat.Name + ", Category ID: " + aFile.CategoryID + "\r\n";
msg = msg + "\r\n";
}
//Get local file timestamp 文件时间戳
filePath = aFile.Name;
object fileDate = null;
fileDate = aFile.GetLocalFileDate(filePath);
if ((fileDate != null))
{
string text = null;
text = fileDate.ToString();
msg = msg + aFile.GetLocalPath(folder.ID) + " was modified " + text + "\r\n";
}
else
{
msg = msg + "There is no local copy of the file" + "\r\n";
}
msg = msg + "\r\n";
//Get local version number 本地版本
int versionNo = 0;
versionNo = aFile.GetLocalVersionNo(aFile.GetLocalPath(folder.ID));
if (versionNo == -1)
{
msg = msg + "The local copy of " + aFile.Name + " does not match any existing versions" +
"\r\n";
}
else
{
string versionStr = null;
versionStr = versionNo.ToString();
msg = msg + "The local copy of " + aFile.Name + " has version " + versionStr + "\r\n";
}
msg = msg + "\r\n";
//Get current version 当前版本
int ver = 0;
ver = aFile.CurrentVersion;
msg = msg + "Current version: " + ver + "\r\n";
msg = msg + "\r\n";
//Get local revision name 本地修订名称
string revName = null;
revName = aFile.GetLocalRevisionName(aFile.GetLocalPath(folder.ID));
if (string.IsNullOrEmpty(revName))
{
msg = msg + "The local copy of " + aFile.Name + " does not match any existing revisions" +
"\r\n";
}
else
{
msg = msg + "The local copy of " + aFile.Name + " has revision name " + revName + "\r\n";
}
msg = msg + "\r\n";
//Get current revision 获取当前修订
revName = aFile.CurrentRevision;
msg = msg + "Current revision: " + revName + "\r\n";
msg = msg + "\r\n";
//Get current workflow state 当前流程状态
IEdmState5 state = default(IEdmState5);
state = aFile.CurrentState;
msg = msg + "Current workflow state: " + state.Name + "\r\n";
msg = msg + "\r\n";
//Get whether the file is checked out 是否检出
bool checkedOut = false;
checkedOut = aFile.IsLocked;
msg = msg + "File is checked out? " + checkedOut + "\r\n";
if (checkedOut)
{
msg = msg + "Lock path: " + aFile.LockPath + "\r\n";
msg = msg + "Locked by: " + aFile.LockedByUser.Name + ", User ID: " + aFile.LockedByUserID +
"\r\n";
msg = msg + "Locked in: " + aFile.LockedInFolder.Name + ", Folder ID: " + aFile.LockedInFolderID +
"\r\n";
msg = msg + "Locked on: " + aFile.LockedOnComputer + ", Vault View ID: " + aFile.LockedOnViewID;
}
MessageBox.Show(msg);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
结果显示:
文件还是老地方:
https://gitee.com/painezeng/solidworks-pdmprofessional-apistudy.git
posted @
2022-03-02 21:39
painezeng 阅读(
0) 评论(
0)
编辑
收藏
举报
来源