Is there a way to have a button on a data card, when pressed, read a variable (drawing number) from that card then search for that PDF in the vault?
Thanks!
SolidworksApi macros
Is there a way to have a button on a data card, when pressed, read a variable (drawing number) from that card then search for that PDF in the vault?
Thanks!
SolidworksApi macros
Yes, but would require a custom program to actually do the search. You can add a button control to a data card and have this button run this program when it is clicked.
Thanks! Has anyone tried this or any pointers on what this program would look like?
The code for an add-in that will open a new Explorer window with the PDF file selected is pretty straightforward. Here's a quickly thrown together C# version. Use for reference only. Code is not production quality.
using System; using EdmLib;using System.Runtime.InteropServices;using System.Windows.Forms;namespace RunTest{ [Guid("7f8c1d0e-3697-4a94-a2e6-49e727fed6cb"), ComVisible(true)] public class RunTest : IEdmAddIn5 { void EdmLib.IEdmAddIn5.GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr) { poInfo.mbsAddInName = "RunTest"; poInfo.mbsCompany = "Your Company Here"; poInfo.mbsDescription = "Run Add-in from button"; poInfo.mlAddInVersion = 1; //Current PDM Version: 2011 SP4 poInfo.mlRequiredVersionMajor = 11; poInfo.mlRequiredVersionMinor = 4; poCmdMgr.AddHook(EdmCmdType.EdmCmd_CardButton, null); } void EdmLib.IEdmAddIn5.OnCmd(ref EdmCmd poCmd, ref System.Array ppoData) { IEdmVault8 edmVault = poCmd.mpoVault as IEdmVault8; try { switch (poCmd.meCmdType) { case EdmCmdType.EdmCmd_CardButton: EdmCmdData[] cmdData = (EdmCmdData[])ppoData; EdmCmdData fileData = cmdData[0]; int fileID = (int)cmdData[0].mlObjectID1; IEdmFile5 file = (IEdmFile5)edmVault.GetObject(EdmObjectType.EdmObject_File, fileID); IEdmEnumeratorVariable5 varEnum = file.GetEnumeratorVariable(""); object value; bool foundValue = varEnum.GetVar("Your Variable", "@", out value); IEdmSearch5 search = edmVault.CreateSearch(); search.FileName = (string)value + ".pdf"; search.FindFiles = true; search.FindFolders = false; search.FindLockedFiles = true; search.FindUnlockedFiles = true; search.Recursive = true; IEdmSearchResult5 result = search.GetFirstResult(); IEdmFile5 pdfFile = (IEdmFile5)edmVault.GetObject(EdmObjectType.EdmObject_File, result.ID); IEdmPos5 pos = pdfFile.GetFirstFolderPosition(); IEdmFolder5 folder = pdfFile.GetNextFolder(pos); edmVault.OpenContainingFolder(pdfFile.ID, folder.ID); break; default: break; } } catch (COMException exp) { string errorName, errorDesc; edmVault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc); edmVault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName); } } }}This is great, thanks so much. Would it be possible to also open the PDF file?
Yes. Just add the line
using System.Diagnostics;
at the top with the other 'using' statements. Next replace the line:
edmVault.OpenContainingFolder(pdfFile.ID, folder.ID);
with the line:
Process.Start(folder.LocalPath + "\\" + pdfFile.Name);
Once again, there's no error checking and such, but this is the basic idea.
Jim S.