Initial Commit of the PDM project (ready for DWS migration)
This commit is contained in:
278
documentation/api_extracted/Execute_Template_Example_CSharp.htm
Normal file
278
documentation/api_extracted/Execute_Template_Example_CSharp.htm
Normal file
@@ -0,0 +1,278 @@
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Execute Template Example (C#)</title>
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
||||
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
||||
</head>
|
||||
<meta name=MS-HKWD content="C# examples,templates">
|
||||
<meta name=MS-HKWD content="C# examples,folders">
|
||||
|
||||
<body>
|
||||
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
||||
<h1>Execute Template Example (C#)</h1>
|
||||
<p><a name="Top"></a>This example shows how to execute a template to create a
|
||||
folder structure in a vault.</p>
|
||||
<p><b>NOTE</b>: If using the primary interop assembly
|
||||
provided with SOLIDWORKS PDM Professional, see
|
||||
<a href="Using_NET_Framework_in_Applications.htm">Using .NET Framework 4.0 in
|
||||
Stand-alone Applications</a>.</p>
|
||||
<p><img border="0" src="ExecuteTemplate.gif" width="262" height="161"></p>
|
||||
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:green;">//----------------------------------------------------------------------------</span>
|
||||
<span style="color:green;">// Preconditions:</span>
|
||||
<span style="color:green;">// 1. Start Microsoft Visual Studio.</span>
|
||||
<span style="color:green;">// a. Click <b>File > New > Project > Visual C# > Windows Forms Application</b>.</span>
|
||||
<span style="color:green;">// b. Type <b>TemplateCSharp</b> in <b>Name</b>.</span>
|
||||
<span style="color:green;">// c. Click <b>Browse</b> and navigate to the folder where to create the project.</span>
|
||||
<span style="color:green;">// d. Click <b>OK</b>. </span>
|
||||
<span style="color:green;">// e. Click <b>Show All Files</b> in the Solution Explorer toolbar and expand </span>
|
||||
<span style="color:green;">// <b>Form1.cs </b>in the Solution Explorer.</span>
|
||||
<span style="color:green;">// f. Replace the code in <b>Form1.cs</b> with <a href="#Form1">this code</a>.</span>
|
||||
<span style="color:green;">// g. To create the form, replace the code in <b>Form1.Designer.cs</b> with </span>
|
||||
<span style="color:green;">// <a href="#Designer">this code</a>.</span>
|
||||
<span style="color:green;">// 2. Add <b>EPDM.Interop.epdm.dll </b>as a reference (right-click the project</span>
|
||||
<span style="color:green;">// name in the Solution Explorer, click <b>Add Reference</b>, click </span>
|
||||
<span style="color:green;">// <b>Assemblies > Framework</b> in the left-side panel, browse to the top folder of </span>
|
||||
<span style="color:green;">// your SOLIDWORKS PDM Professional installation, locate and click </span>
|
||||
<span style="color:green;">// <b>EPDM.Interop.epdm.dll</b>, click <b>Open</b>, click <b>Add</b>, and click <b>Close</b>).</span>
|
||||
<span style="color:green;">// 3. Right-click <b>EPDM.Interop.epdm</b> in References, click <b>Properties</b>, and set </span>
|
||||
<span style="color:green;">// <b>Embed Interop Types</b> to <b>False</b> to handle methods that pass arrays of </span>
|
||||
<span style="color:green;">// structures.</span>
|
||||
<span style="color:green;">// 4. Ensure that a template exists in the vault that you plan to </span>
|
||||
<span style="color:green;">// select and that a template card is assigned to that template.</span>
|
||||
<span style="color:green;">// <b>NOTE</b>: This example assumes that the template in your selected vault</span>
|
||||
<span style="color:green;">// creates a folder structure and that folder structure does not already</span>
|
||||
<span style="color:green;">// exist in the selected vault.</span>
|
||||
<span style="color:green;">// 5. Click <b>Debug > Start Debugging</b> or press F5.</span>
|
||||
<span style="color:green;">//</span>
|
||||
<span style="color:green;">// Postconditions: </span>
|
||||
<span style="color:green;">// 1. Displays the Execute Template dialog box.</span>
|
||||
<span style="color:green;">// a. Select a vault.</span>
|
||||
<span style="color:green;">// b. Click <b>Execute Template</b>.</span>
|
||||
<span style="color:green;">// c. Displays a message box showing the name of the template to execute.</span>
|
||||
<span style="color:green;">// d. Click <b>OK</b> to close the message box.</span>
|
||||
<span style="color:green;">// e. Creates the folder structure defined for the template at the selected</span>
|
||||
<span style="color:green;">// vault's root folder and prompts for variable values, if any </span>
|
||||
<span style="color:green;">// exist for the template card and template. </span>
|
||||
<span style="color:green;">// 2. Displays a message box informing you that a new folder structure</span>
|
||||
<span style="color:green;">// was created in the selected vault.</span>
|
||||
<span style="color:green;">// - or -</span>
|
||||
<span style="color:green;">// Displays a message box informing you that a folder structure</span>
|
||||
<span style="color:green;">// was not created.</span>
|
||||
<span style="color:green;">// 3. Click <b>OK</b> to close the message box.</span>
|
||||
<span style="color:green;">// 4. Close the Execute Template dialog box.</span>
|
||||
<span style="color:green;">// 5. Examine the selected vault to verify that a new folder</span>
|
||||
<span style="color:green;">// structure based on the template was, or was not, created.</span>
|
||||
<span style="color:green;">//----------------------------------------------------------------------------</span></pre>
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color: #008000"><a name="Form1"></a>//Form1.cs</span>
|
||||
<span style="color:blue;">using</span> System;
|
||||
<span style="color:blue;">using</span> System.Collections.Generic;
|
||||
<span style="color:blue;">using</span> System.ComponentModel;
|
||||
<span style="color:blue;">using</span> System.Data;
|
||||
<span style="color:blue;">using</span> System.Drawing;
|
||||
<span style="color:blue;">using</span> System.Linq;
|
||||
<span style="color:blue;">using</span> System.Text;
|
||||
<span style="color:blue;">using</span> System.Windows.Forms;
|
||||
<span style="color:blue;">using</span> EPDM.Interop.epdm;
|
||||
|
||||
<span style="color:blue;">namespace</span> TemplateCSharp
|
||||
{
|
||||
<span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Form1</span> : <span style="color:#2b91af;">Form</span>
|
||||
{
|
||||
<span style="color:blue;">public</span> Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
<span style="color:#2b91af;">IEdmVault5</span> vault1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
||||
|
||||
<span style="color:blue;">public</span> <span style="color:blue;">void</span> Form1_Load(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
||||
{
|
||||
<span style="color:blue;">try</span> {
|
||||
|
||||
<span style="color:#2b91af;">IEdmVault8</span> vault = (<span style="color:#2b91af;">IEdmVault8</span>)vault1;
|
||||
<span style="color:#2b91af;">EdmViewInfo</span>[] Views = <span style="color:blue;">null</span>;
|
||||
|
||||
vault.<b>GetVaultViews</b>(<span style="color:blue;">out</span> Views, <span style="color:blue;">false</span>);
|
||||
VaultsComboBox.Items.Clear();
|
||||
<span style="color:blue;">foreach</span> (<span style="color:#2b91af;">EdmViewInfo</span> View <span style="color:blue;">in</span> Views) {
|
||||
VaultsComboBox.Items.Add(View.<b>mbsVaultName</b>);
|
||||
}
|
||||
<span style="color:blue;">if</span> (VaultsComboBox.Items.Count > 0) {
|
||||
VaultsComboBox.Text = (<span style="color:blue;">string</span>)VaultsComboBox.Items[0];
|
||||
}
|
||||
} <span style="color:blue;">catch</span> (System.Runtime.InteropServices.<span style="color:#2b91af;">COMException</span> ex) {
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color:#a31515;">"X"</span>) + <span style="color:#a31515;">" "</span> + ex.Message);
|
||||
} <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex) {
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<span style="color:blue;">private</span> <span style="color:blue;">void</span> ExecuteTemplateButton_Click(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
||||
{
|
||||
<span style="color:blue;">try</span> {
|
||||
<span style="color:#2b91af;">IEdmVault7</span> vault2 = <span style="color:blue;">null</span>;
|
||||
<span style="color:blue;">if</span> (vault1 == <span style="color:blue;">null</span>) {
|
||||
vault1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
||||
}
|
||||
vault2 = (<span style="color:#2b91af;">IEdmVault7</span>)vault1;
|
||||
|
||||
<span style="color:blue;">if</span> (!vault1.<b>IsLoggedIn</b>) {
|
||||
vault1.<b>LoginAuto</b>(VaultsComboBox.Text, <span style="color:blue;">this</span>.Handle.ToInt32());
|
||||
}
|
||||
|
||||
<span style="color:green;">//Access template in the selected vault</span>
|
||||
<span style="color:#2b91af;">IEdmTemplateMgr5</span> templateMgr = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmTemplateMgr5</span>);
|
||||
templateMgr = (<span style="color:#2b91af;">IEdmTemplateMgr5</span>)vault2.<b>CreateUtility</b>(<span style="color:#2b91af;">EdmUtility</span>.EdmUtil_TemplateMgr);
|
||||
<span style="color:#2b91af;">IEdmPos5</span> pos = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmPos5</span>);
|
||||
pos = templateMgr.<b>GetFirstTemplatePosition</b>();
|
||||
<span style="color:#2b91af;">IEdmTemplate5</span> template = <span style="color:blue;">null</span>;
|
||||
|
||||
<span style="color:blue;">string</span> message = <span style="color:#a31515;">""</span>;
|
||||
message = <span style="color:#a31515;">"Installed template in vault, "</span> + vault1.<b>Name</b> + <span style="color:#a31515;">", to use:"</span> + <span style="color:#a31515;">"\n\n"</span>;
|
||||
|
||||
|
||||
<span style="color:blue;">while</span> (!pos.IsNull) {
|
||||
template = templateMgr.<b>GetNextTemplate</b>(pos);
|
||||
|
||||
<span style="color:blue;">string</span> menuString = <span style="color:#a31515;">""</span>;
|
||||
menuString = template.<b>GetMenuString</b>();
|
||||
message = message + menuString + <span style="color:#a31515;">"\n"</span>;
|
||||
<span style="color:green;">//Display message box with name of template</span>
|
||||
<span style="color:green;">//to use in the selected vault</span>
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(message);
|
||||
|
||||
<span style="color:green;">//Create template folders in the selected vault </span>
|
||||
<span style="color:green;">//using this template</span>
|
||||
<span style="color:#2b91af;">EdmRefreshFlag</span> refreshFlag = <span style="color:blue;">default</span>(<span style="color:#2b91af;">EdmRefreshFlag</span>);
|
||||
refreshFlag = (<span style="color:#2b91af;">EdmRefreshFlag</span>)template.<b>Run</b>(<span style="color:blue;">this</span>.Handle.ToInt32(), vault1.RootFolderID);
|
||||
|
||||
<span style="color:green;">//Make sure folder structure created</span>
|
||||
<span style="color:green;">//Exit application if it is not created</span>
|
||||
<span style="color:blue;">if</span> (refreshFlag == <span style="color:#2b91af;">EdmRefreshFlag</span>.EdmRefresh_Nothing) {
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Folder structure not created."</span>);
|
||||
<span style="color:blue;">return</span>;
|
||||
} <span style="color:blue;">else</span> {
|
||||
<span style="color:green;">//Folder structure created</span>
|
||||
<span style="color:blue;">if</span> (refreshFlag == <span style="color:#2b91af;">EdmRefreshFlag</span>.EdmRefresh_FileList) {
|
||||
vault1.<b>RefreshFolder</b>(vault1.<b>RootFolderPath</b>);
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"The new folder structure based on the template was created in the selected vault."</span>);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} <span style="color:blue;">catch</span> (System.Runtime.InteropServices.<span style="color:#2b91af;">COMException</span> ex) {
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color:#a31515;">"X"</span>) + <span style="color:#a31515;">" "</span> + ex.Message);
|
||||
} <span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex) {
|
||||
<span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}</pre>
|
||||
<div align="center">
|
||||
<pre style="font-family: Calibri; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a></pre>
|
||||
</div>
|
||||
<div align="left">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: #008000; background: white"><a name="Designer"></a>//Form1.Designer.cs</pre>
|
||||
</div>
|
||||
<div align="left">
|
||||
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:blue;">namespace</span> TemplateCSharp
|
||||
{
|
||||
<span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Form1</span>
|
||||
{
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> Required designer variable.</span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
||||
<span style="color:blue;">private</span> System.ComponentModel.<span style="color:#2b91af;">IContainer</span> components = <span style="color:blue;">null</span>;
|
||||
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> Clean up any resources being used.</span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><param name="disposing"></span><span style="color:green;">true if managed resources should be disposed; otherwise, false.</span><span style="color:gray;"></param></span>
|
||||
<span style="color:blue;">protected</span> <span style="color:blue;">override</span> <span style="color:blue;">void</span> Dispose(<span style="color:blue;">bool</span> disposing)
|
||||
{
|
||||
<span style="color:blue;">if</span> (disposing && (components != <span style="color:blue;">null</span>))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
<span style="color:blue;">base</span>.Dispose(disposing);
|
||||
}
|
||||
|
||||
<span style="color:blue;"> #region</span> Windows Form Designer generated code
|
||||
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"><summary></span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> Required method for Designer support - do not modify</span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> the contents of this method with the code editor.</span>
|
||||
<span style="color:gray;">///</span><span style="color:green;"> </span><span style="color:gray;"></summary></span>
|
||||
<span style="color:blue;">private</span> <span style="color:blue;">void</span> InitializeComponent()
|
||||
{
|
||||
<span style="color:blue;">this</span>.label1 = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span>();
|
||||
<span style="color:blue;">this</span>.VaultsComboBox = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span>();
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton = <span style="color:blue;">new</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span>();
|
||||
<span style="color:blue;">this</span>.SuspendLayout();
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:green;">// label1</span>
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:blue;">this</span>.label1.AutoSize = <span style="color:blue;">true</span>;
|
||||
<span style="color:blue;">this</span>.label1.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(24, 24);
|
||||
<span style="color:blue;">this</span>.label1.Name = <span style="color:#a31515;">"label1"</span>;
|
||||
<span style="color:blue;">this</span>.label1.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(91, 13);
|
||||
<span style="color:blue;">this</span>.label1.TabIndex = 0;
|
||||
<span style="color:blue;">this</span>.label1.Text = <span style="color:#a31515;">"Select vault view:"</span>;
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:green;">// VaultsComboBox</span>
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:blue;">this</span>.VaultsComboBox.FormattingEnabled = <span style="color:blue;">true</span>;
|
||||
<span style="color:blue;">this</span>.VaultsComboBox.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(27, 41);
|
||||
<span style="color:blue;">this</span>.VaultsComboBox.Name = <span style="color:#a31515;">"VaultsComboBox"</span>;
|
||||
<span style="color:blue;">this</span>.VaultsComboBox.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(242, 21);
|
||||
<span style="color:blue;">this</span>.VaultsComboBox.TabIndex = 1;
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:green;">// ExecuteTemplateButton</span>
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(27, 81);
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.Name = <span style="color:#a31515;">"ExecuteTemplateButton"</span>;
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(113, 23);
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.TabIndex = 2;
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.Text = <span style="color:#a31515;">"Execute Template"</span>;
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.Click += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(ExecuteTemplateButton_Click);
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.TextAlign = System.Drawing.<span style="color:#2b91af;">ContentAlignment</span>.MiddleLeft;
|
||||
<span style="color:blue;">this</span>.ExecuteTemplateButton.UseVisualStyleBackColor = <span style="color:blue;">true</span>;
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:green;">// Form1</span>
|
||||
<span style="color:green;">// </span>
|
||||
<span style="color:blue;">this</span>.AutoScaleDimensions = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">SizeF</span>(6F, 13F);
|
||||
<span style="color:blue;">this</span>.AutoScaleMode = System.Windows.Forms.<span style="color:#2b91af;">AutoScaleMode</span>.Font;
|
||||
<span style="color:blue;">this</span>.ClientSize = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(290, 125);
|
||||
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.ExecuteTemplateButton);
|
||||
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.VaultsComboBox);
|
||||
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.label1);
|
||||
<span style="color:blue;">this</span>.Name = <span style="color:#a31515;">"Form1"</span>;
|
||||
<span style="color:blue;">this</span>.Text = <span style="color:#a31515;">"Execute Template"</span>;
|
||||
<span style="color:blue;">this</span>.Load += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(<span style="color:blue;">this</span>.Form1_Load);
|
||||
<span style="color:blue;">this</span>.ResumeLayout(<span style="color:blue;">false</span>);
|
||||
<span style="color:blue;">this</span>.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span> label1;
|
||||
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span> VaultsComboBox;
|
||||
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span> ExecuteTemplateButton;
|
||||
|
||||
<span style="color:blue;"> #endregion</span>
|
||||
}
|
||||
}</pre>
|
||||
</div>
|
||||
<div align="center">
|
||||
<pre style="font-family: Calibri; font-size: 13; color: #008000; background: white"><a href="#Top">Back to top</a></pre>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user