Hello all,
I am trying to start a template with the command:
EdmCmdType.EdmCmd_PostState
The template starts with a corresponding template card.
In this card I want to transfer some values from the source file e.g. a SolidWorks-Drawing.
Unfortunately I am not sure how to catch the Template object to use the SetVar Method.
Here my Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using EdmLib;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.VisualBasic;namespace EpdmCsAddIn
{
[Guid("0C6730E7-5E12-409E-AC50-96654A5F6C76"), ComVisible(true)]public class CsAddIn : IEdmAddIn5
{
public void GetAddInInfo(ref EdmAddInInfo poInfo, IEdmVault5 poVault, IEdmCmdMgr5 poCmdMgr)
{
poInfo.mbsAddInName = "AddIn Template";
poInfo.mlRequiredVersionMajor = 14;
poInfo.mlRequiredVersionMinor = 2;
poInfo.mlAddInVersion = 1001;poInfo.mbsCompany = "Mario Boelingen - " + "Hegenscheidt MFD";
poInfo.mbsDescription = "Vorlage zur Erstellung von Add-Ins";poCmdMgr.AddHook(EdmCmdType.EdmCmd_PostState);
}public void OnCmd(ref EdmCmd poCmd, ref Array ppoData)
{
if (poCmd.meCmdType != 0)
{
if (poCmd.meCmdType == EdmCmdType.EdmCmd_PostState)
{
IEdmVault13 vault = poCmd.mpoVault as IEdmVault13;int index = 0;
int last = 0;
index = Information.LBound(ppoData);
last = Information.UBound(ppoData);
int FileID = 0;
int FolderID = 0;
int TransitionID = 0;
string FilePath;
int UserID = 0;
string extension;
string ext;
string fileName;
string DestState;
int DestStateID;
int SourceStateID;FileID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID1; // ID of file
FolderID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID2; // ID of parent folder
TransitionID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID3; // ID of transition to perform
UserID = ((EdmCmdData)ppoData.GetValue(index)).mlObjectID4; // ID of user
FilePath = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData1; // Path to file
DestState = ((EdmCmdData)ppoData.GetValue(index)).mbsStrData2; // Name of destination state
DestStateID = ((EdmCmdData)ppoData.GetValue(index)).mlLongData2; // ID of destination state
SourceStateID = ((EdmCmdData)ppoData.GetValue(index)).mlLongData1; // ID of source stateIEdmFile8 File = default(IEdmFile8);
IEdmFolder5 ppoRetParentFolder;
File = (IEdmFile8)vault.GetFileFromPath(FilePath, out ppoRetParentFolder);fileName = File.Name.ToString();
extension = System.IO.Path.GetExtension(fileName);
ext = extension.TrimStart('.');string RevNumber = File.CurrentRevision;
RevNumber = RevNumber.Replace(".", "");IEdmEnumeratorVariable5 varEnum1 = default(IEdmEnumeratorVariable5);
varEnum1 = File.GetEnumeratorVariable();object ArtNumber = null;
varEnum1.GetVar("SL_NUMMER", "@", out ArtNumber);
string ArtNumberVal = (string)ArtNumber;
object ArtName = null;
varEnum1.GetVar("SL_BENENNUNG", "@" ,out ArtName);
string ArtNameVal = (string)ArtName;if (DestState == "START")
{
try
{
IEdmTemplateMgr5 templateMgr = default(IEdmTemplateMgr5);
templateMgr = (IEdmTemplateMgr5)vault.CreateUtility(EdmUtility.EdmUtil_TemplateMgr);
IEdmPos5 pos = default(IEdmPos5);
pos = templateMgr.GetFirstTemplatePosition();
IEdmTemplate5 template = null;while (index <= last)
{string templateName = "";
while (!pos.IsNull)
{
template = templateMgr.GetNextTemplate(pos);
templateName = template.GetMenuString();
//Try to access the Template-Object PROBLEM
IEdmEnumeratorVariable5 varEnum2 = default(IEdmEnumeratorVariable5);
varEnum2 = template.GetEnumeratorVariable();//Try to access the Template-Object PROBLEM
if (templateName == "Aenderungsdienst")
{
varEnum2.SetVar("SL_NUMMER", "", ArtNumberVal);
varEnum2.SetVar("SL_BENENNUNG", "", ArtNameVal);
varEnum2.SetVar("Revision_ZEICHNUNG", "", RevNumber);
varEnum2.Flush();
EdmRefreshFlag refreshFlag = default(EdmRefreshFlag);
refreshFlag = (EdmRefreshFlag)template.Run(0, FolderID);
}
return;
}index = index + 1;
}}
catch (COMException exp)
{
string errorName, errorDesc;
vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName)}
}
return;
}
return;
}
return;}
}
}
How can I do that?
SolidworksApi macros