问题描述
首先我不习惯这样编程,但我正在尝试。我很沮丧,我找不到问题的解决方案,我希望有人能给我一个很好的资源来使用,因为我认为 SolidWorks 帮助和文档在很多方面都缺乏。我刚刚开始学习这个,我唯一的问题是如何访问 IEdmFile5 对象。
我想做的是创建一个插件来做一件事,就是将 URL 链接作为变量添加到文件中。我当然会添加代码,每当文件移动或名称更改时更新此 URL。现在,我创建了一个只有右键单击菜单的插件,因此我可以一次更改一个或多个文件的 URL。 (当务之急是为现有文件创建/更新 URL。)
除了一件事之外,我已经编写了所有执行此操作的代码。即,将 URL 保存到变量中。菜单命令没有文件路径,只有 ID。令我困惑的是我正在右键单击该文件。它应该包含我需要的关于文件的信息,或者获取它的方法。也许确实如此,但我似乎无法找到它。
这是代码。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using EdmLib;
namespace ClassFileURL
{
[Guid("A0A3EA71-06F1-4369-AAEA-256DBDC28652")]
[ComVisible(true)]
public class Class1 : IEdmAddIn5
{
private readonly String vaultName = "kern_vault test";
private IEdmVault5 vault = null;
public void GetAddInInfo(ref EdmAddInInfo poInfo,IEdmVault5 poVault,IEdmCmdMgr5 poCmdMgr)
{
try
{
//Specify @R_808_4045@ion to display in the add-in's Properties dialog Box
poInfo.mbsAddInName = "File URL Generator Add-in";
poInfo.mbsCompany = "Kern Laser Systems";
poInfo.mbsDescription = "Creates a URL of the file.";
poInfo.mlAddInVersion = 1;
//Specify the minimum required version of SolidWorks PDM Professional
poInfo.mlrequiredVersionMajor = 6;
poInfo.mlrequiredVersionMinor = 4;
// Register a menu command
poCmdMgr.AddCmd(1,"Generate File URL",(int)EdmMenuFlags.EdmMenu_nothing);
// Set the vault object.
vault = poVault;
// All all the needed command hooks.
poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostAdd);
poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostMove);
poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostMoveFolder);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void IEdmAddIn5.OnCmd(ref EdmCmd poCmd,ref Array ppoData)
{
try
{
// Declare variables.
int index = ppoData.GetLowerBound(0); // Get the lower bound of the array.
int last = ppoData.GetUpperBound(0); // Get the upper bound of the array.
EdmCmdData[] tmpArr = (EdmCmdData[])ppoData; // Create a temporary array will full access.
// Make sure we are logged into the vault.
if (!vault.IsLoggedIn)
{
//Log into selected vault as the current user
vault.LoginAuto(vaultName,poCmd.mlParentWnd);
}
// Handle the command.
switch (poCmd.meCmdType)
{
case EdmCmdType.EdmCmd_Menu:
// Declare variables.
String message = "Do you want to update or create the file URL for the selected files? (Aplies only to .SLDPRT and .SLDASM files.)";
String title = "Update/Create file URL";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
if (poCmd.mlCmdID == 1)
{
// Show the message Box.
result = MessageBox.Show(message,title,buttons);
// Determine what is done to the files.
if (result == DialogResult.Yes)
{
ProcessFileList(index,last,tmpArr);
// Show done Box when finished.
MessageBox.Show("Done",title);
}
}
break;
case EdmCmdType.EdmCmd_PostAdd:
break;
case EdmCmdType.EdmCmd_PostMove:
break;
case EdmCmdType.EdmCmd_PostMoveFolder:
break;
default:
break;
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//
private void ProcessFileList(int lowerBound,int upperBound,EdmCmdData[] files)
{
// Declare variables.
IEdmEnumeratorVariable5 linkVariable = default(IEdmEnumeratorVariable5);
IEdmFolder5 retFolder = default(IEdmFolder5);
IEdmFile5 aFile = default(IEdmFile5);
String extension1 = ".sldprt";
String extension2 = ".sldasm";
String url = null;
//Append the paths of all files to a message string
while (lowerBound <= upperBound)
{
// Get the data.
int fileID = files[lowerBound].mlObjectID1;
int folderID = files[lowerBound].mlObjectID2;
int parentFolderID = files[lowerBound].mlObjectID3;
String fileName = files[lowerBound].mbsstrData1.ToLower();
// Process only the desired files.
if ((fileName.EndsWith(extension1)) || (fileName.EndsWith(extension2)))
{
// Check the file ID for 0.
if (fileID == 0)
{
url = CreateURL(folderID,fileID);
// work on this. for files in folder
}
// Check the folder ID for 0.
if (folderID == 0)
{
url = CreateURL(parentFolderID,fileID);
}
// Get the file object.
//this is where I get hung up,I have no path to the file.
aFile = vault.GetFileFromPath(**path to file**,out retFolder);
linkVariable = aFile.GetEnumeratorVariable(**path to file **);
// Set the File Link of the selected file.
linkVariable.Setvar("File Link","",url,true);
linkVariable.Flush();
}
lowerBound++;
}
}
//
private String CreateURL(int folderID,int fileID)
{
// Declare variables.
String action = "open"; // Could be one of these: open,view,explore,get,lock,properties,or history.
int EdmObject_File = 1;
String url = String.Format("conisio://{0}/{1}?projectid={2}&documentid={3}&objecttype={4}",vaultName,action,folderID,fileID,EdmObject_File);
// Show the url.
MessageBox.Show(url,"The file URL");
return url;
}
}
}
格式不正确。这是一个 COM 对象,需要 EDMLib dll 进行编译。任何帮助,将不胜感激。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)