Starting a template by IEdmTemplate5 with EdmCmdType.EdmCmd_PostState

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:

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

How can I do that?

SolidworksApi macros