Solidworks PDM二次开发—文件夹相关操作
前言
好久没有更新Solidworks PDM的操作了,今天我们来学习一下文件夹的几个常用操作。
新建文件夹
可以参考api中的帮助 Add Folder Example (C#) —这里面有相关的卡设置
//new 一个库对象
var vault = new EdmVault5();
//登陆到库中
vault.LoginAuto("PDM2020Default", this.Handle.ToInt32());
var vault2 = (IEdmVault7)vault;
//本地根目录
var rootPath = vault2.RootFolderPath;
var rootFolder = vault2.RootFolder;
//新建子文件夹
//这里路径可以多个子层级 如A\B\C
var newFolder = rootFolder.CreateFolderPath($@"\newTempFolder", this.Handle.ToInt32());
IEdmFolder5 parentFolder = default(IEdmFolder5);
parentFolder = vault2.GetFolderFromPath(ListBox.Items[0].ToString());
dynamic folderName = "Temp";
IEdmUserMgr5 usrMgr = default(IEdmUserMgr5);
usrMgr = (IEdmUserMgr5)parentFolder.Vault;
EdmFolderData data = default(EdmFolderData);
data = new EdmFolderData();
data.SetUserRights(usrMgr.GetUser("Engineer1").ID, (int)EdmRightFlags.EdmRight_Read | (int)EdmRightFlags.EdmRight_Lock);
data.SetGroupRights(usrMgr.GetUserGroup("Administrators").ID, (int)EdmRightFlags.EdmRight_All);
IEdmCard5 card = default(IEdmCard5);
card = parentFolder.Vault.RootFolder.GetCard("doc");
data.SetCardSource(card.ID, "doc");
IEdmFolder5 folder = default(IEdmFolder5);
folder = parentFolder.AddFolder(this.Handle.ToInt32(), folderName, data);
Interaction.MsgBox("Created " + folderName + " successfully with ID, " + Conversion.Str(folder.ID) + ", in " + parentFolder.Name);
获取文件夹对象
//读取文件夹
//var tempFolderObj = vault2.GetFolderFromPath($@"文件夹路径");
IEdmEnumeratorVariable6 EnumVarFolder = (IEdmEnumeratorVariable6)folderObj;
object ResValueObjFolder = null;
//object ResValueObjFolderDB = null;
//从数据库中读
//EnumVarFolder.GetVarFromDb("项目编号", "", out ResValueObjFolderDB);
EnumVarFolder.GetVar("项目编号", "", out ResValueObjFolder);
if (ResValueObjFolder != null)
{
MessageBox.Show($"项目编号:" + ResValueObjFolder);
}
删除文件夹
//删除文件夹 DeleteFolder Method (IEdmFolder5)
rootFolder.DeleteFolder(this.Handle.ToInt32(), folderObj.ID, true);
刷新文件夹
//刷新本地文件夹
rootFolder.Refresh();
结果正常:
结束,收工。
var code = "a7325120-55a0-49ed-9394-1bfdcde9edb6"
posted @
2023-04-25 15:47
painezeng 阅读(
0) 评论(
0)
编辑
收藏
举报
来源