258 lines
34 KiB
HTML
258 lines
34 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>Execute Template Example (VB.NET)</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="VB.NET examples,templates">
|
|
<meta name=MS-HKWD content="VB.NET examples,folders">
|
|
|
|
<body>
|
|
<h1><font size="1"><span style="font-weight: 400">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Execute Template Example (VB.NET)</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 Basic > Windows Forms Application</b>.</span>
|
|
<span style="color: green">' b. Type <b>TemplateVBNET</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.vb </b>in the Solution Explorer.</span>
|
|
<span style="color: green">' f. Replace the code in <b>Form1.vb</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.vb</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
|
|
' 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>
|
|
<span style="color: green"><a name="Form1"></a>'Form1.vb</span>
|
|
|
|
<span style="color: blue">Imports</span> System.IO
|
|
<span style="color: blue">Imports</span> System.Xml.Serialization
|
|
<span style="color: blue">Imports</span> System.Collections
|
|
<span style="color: blue">Imports</span> System.Collections.Generic
|
|
<span style="color: blue">Imports</span> System.Data
|
|
<span style="color: blue">Imports</span> System.Diagnostics
|
|
<span style="color: blue">Imports</span> System.Windows.Forms
|
|
<span style="color: blue">Imports</span> System.ComponentModel
|
|
<span style="color: blue">Imports</span> EPDM.Interop.epdm
|
|
|
|
<span style="color: blue">Public</span> <span style="color: blue">Class</span> <span style="color: #2b91af">Form1</span>
|
|
<span style="color: blue">Dim</span> vault1 <span style="color: blue">As</span> <span style="color: #2b91af">IEdmVault5</span> = <span style="color: blue">New</span> <span style="color: #2b91af">EdmVault5</span>()
|
|
<span style="color: blue">Dim</span> vault <span style="color: blue">As</span> <span style="color: #2b91af">IEdmVault8</span> = <span style="color: blue">DirectCast</span>(vault1, <span style="color: #2b91af">IEdmVault8</span>)
|
|
<span style="color: blue">Dim</span> Views <span style="color: blue">As</span> <span style="color: #2b91af">EdmViewInfo</span>() = <span style="color: blue">Nothing</span>
|
|
<span style="color: blue">Public</span> <span style="color: blue">Sub</span> Form1_Load(<span style="color: blue">ByVal</span> sender <span style="color: blue">As</span> System.<span style="color: #2b91af">Object</span>, <span style="color: blue">ByVal</span> e <span style="color: blue">As</span> System.<span style="color: #2b91af">EventArgs</span>) <span style="color: blue">Handles</span> <span style="color: blue">MyBase</span>.Load
|
|
|
|
<span style="color: blue">Try</span>
|
|
vault.<b>GetVaultViews</b>(Views, <span style="color: blue">False</span>)
|
|
VaultsComboBox.Items.Clear()
|
|
<span style="color: blue">For</span> <span style="color: blue">Each</span> View <span style="color: blue">As</span> <span style="color: #2b91af">EdmViewInfo</span> <span style="color: blue">In</span> Views
|
|
VaultsComboBox.Items.Add(View.<b>mbsVaultName</b>)
|
|
<span style="color: blue">Next</span>
|
|
<span style="color: blue">If</span> VaultsComboBox.Items.Count > 0 <span style="color: blue">Then</span>
|
|
VaultsComboBox.Text = <span style="color: blue">DirectCast</span>(VaultsComboBox.Items(0), <span style="color: blue">String</span>)
|
|
<span style="color: blue">End</span> <span style="color: blue">If</span>
|
|
<span style="color: blue">Catch</span> ex <span style="color: blue">As</span> System.Runtime.InteropServices.<span style="color: #2b91af">COMException</span>
|
|
<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> ex <span style="color: blue">As</span> <span style="color: #2b91af">Exception</span>
|
|
<span style="color: #2b91af">MessageBox</span>.Show(ex.Message)
|
|
<span style="color: blue">End</span> <span style="color: blue">Try</span>
|
|
|
|
<span style="color: blue">End</span> <span style="color: blue">Sub</span>
|
|
|
|
<span style="color: blue">Private</span> <span style="color: blue">Sub</span> ExecuteTemplateButton_Click(<span style="color: blue">ByVal</span> sender <span style="color: blue">As</span> System.<span style="color: #2b91af">Object</span>, <span style="color: blue">ByVal</span> e <span style="color: blue">As</span> System.<span style="color: #2b91af">EventArgs</span>) <span style="color: blue">Handles</span> ExecuteTemplateButton.Click
|
|
|
|
<span style="color: blue">Try</span>
|
|
<span style="color: blue">Dim</span> vault2 <span style="color: blue">As</span> <span style="color: #2b91af">IEdmVault7</span> = <span style="color: blue">Nothing</span>
|
|
<span style="color: blue">If</span> vault1 <span style="color: blue">Is</span> <span style="color: blue">Nothing</span> <span style="color: blue">Then</span>
|
|
vault1 = <span style="color: blue">New</span> <span style="color: #2b91af">EdmVault5</span>()
|
|
<span style="color: blue">End</span> <span style="color: blue">If</span>
|
|
vault2 = <span style="color: blue">DirectCast</span>(vault1, <span style="color: #2b91af">IEdmVault7</span>)
|
|
|
|
<span style="color: blue">If</span> <span style="color: blue">Not</span> vault1.<b>IsLoggedIn</b> <span style="color: blue">Then</span>
|
|
vault1.<b>LoginAuto</b>(VaultsComboBox.Text, <span style="color: blue">Me</span>.Handle.ToInt32())
|
|
<span style="color: blue">End</span> <span style="color: blue">If</span>
|
|
|
|
<span style="color: green">'Access template in the selected vault</span>
|
|
<span style="color: blue">Dim</span> templateMgr <span style="color: blue">As</span> <span style="color: #2b91af">IEdmTemplateMgr5</span>
|
|
templateMgr = vault1.<b>CreateUtility</b>(<span style="color: #2b91af">EdmUtility</span>.EdmUtil_TemplateMgr)
|
|
<span style="color: blue">Dim</span> pos <span style="color: blue">As</span> <span style="color: #2b91af">IEdmPos5</span>
|
|
pos = templateMgr.<b>GetFirstTemplatePosition</b>
|
|
<span style="color: blue">Dim</span> template <span style="color: blue">As</span> <span style="color: #2b91af">IEdmTemplate5</span> = <span style="color: blue">Nothing</span>
|
|
|
|
<span style="color: blue">Dim</span> message <span style="color: blue">As</span> <span style="color: blue">String</span> = <span style="color: #a31515">""</span>
|
|
message = <span style="color: #a31515">"Installed template in vault, "</span> + vault.<b>Name</b> + <span style="color: #a31515">", to use:"</span> + vbLf + vbLf
|
|
|
|
<span style="color: blue">While</span> <span style="color: blue">Not</span> pos.IsNull
|
|
|
|
template = templateMgr.<b>GetNextTemplate</b>(pos)
|
|
|
|
message = message + template.<b>GetMenuString</b> + vbLf
|
|
<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 </span><span style="color: green">in the selected vault</span><span style="color: green"> </span>
|
|
<span style="color: green">'using this template</span>
|
|
<span style="color: blue">Dim</span> refreshFlag <span style="color: blue">As</span> <span style="color: #2b91af">EdmRefreshFlag</span>
|
|
<span style="color: blue">Dim</span> retData() <span style="color: blue">As</span> <span style="color: blue">Object</span> = <span style="color: blue">Nothing</span>
|
|
refreshFlag = template.<b>Run</b>(<span style="color: blue">Me</span>.Handle.ToInt32(), vault1.RootFolderID)</pre>
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"> <span style="color:green;">'Make sure folder structure is created
|
|
'Exit application if it is not</span>
|
|
<span style="color:blue;">If</span> refreshFlag = <span style="color:#2b91af;">EdmRefreshFlag</span>.EdmRefresh_Nothing <span style="color:blue;">Then</span>
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Folder structure not created."</span>)
|
|
<span style="color:blue;">Exit Sub</span>
|
|
<span style="color:blue;">Else
|
|
</span><font color="#008000"> 'Folder structure created</font>
|
|
<span style="color:blue;">If</span> refreshFlag <span style="color: #0000FF">=</span> <span style="color:#2b91af;">EdmRefreshFlag</span>.EdmRefresh_FileList <span style="color:blue;">Then</span>
|
|
vault1.RefreshFolder(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;">End</span> <span style="color:blue;">If</span>
|
|
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
|
|
|
|
<span style="color: blue">End</span> <span style="color: blue">While</span>
|
|
|
|
|
|
<span style="color: blue">Catch</span> ex <span style="color: blue">As</span> System.Runtime.InteropServices.<span style="color: #2b91af">COMException</span>
|
|
<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> ex <span style="color: blue">As</span> <span style="color: #2b91af">Exception</span>
|
|
<span style="color: #2b91af">MessageBox</span>.Show(ex.Message)
|
|
<span style="color: blue">End</span> <span style="color: blue">Try</span>
|
|
|
|
<span style="color: blue">End</span> <span style="color: blue">Sub</span>
|
|
|
|
<span style="color: blue">End</span> <span style="color: blue">Class</span></pre>
|
|
<div align="center">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><font face="Calibri"><a href="#Top">Back to top</a></font></pre>
|
|
</div>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: #008000; background-image: none; background-repeat: repeat; background-attachment: scroll"><a name="Designer"></a>'Form1.Designer.vb</pre>
|
|
</div>
|
|
<div align="left">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><<span style="color:blue;">Global</span>.Microsoft.VisualBasic.CompilerServices.<span style="color:#2b91af;">DesignerGenerated</span>()> _
|
|
<span style="color:blue;">Partial</span> <span style="color:blue;">Class</span> <span style="color:#2b91af;">Form1</span>
|
|
<span style="color:blue;">Inherits</span> System.Windows.Forms.<span style="color:#2b91af;">Form</span>
|
|
|
|
<span style="color:green;">'Form overrides dispose to clean up the component list.</span>
|
|
<System.Diagnostics.<span style="color:#2b91af;">DebuggerNonUserCode</span>()> _
|
|
<span style="color:blue;">Protected</span> <span style="color:blue;">Overrides</span> <span style="color:blue;">Sub</span> Dispose(<span style="color:blue;">ByVal</span> disposing <span style="color:blue;">As</span> <span style="color:blue;">Boolean</span>)
|
|
<span style="color:blue;">Try</span>
|
|
<span style="color:blue;">If</span> disposing <span style="color:blue;">AndAlso</span> components <span style="color:blue;">IsNot</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
|
|
components.Dispose()
|
|
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
|
|
<span style="color:blue;">Finally</span>
|
|
<span style="color:blue;">MyBase</span>.Dispose(disposing)
|
|
<span style="color:blue;">End</span> <span style="color:blue;">Try</span>
|
|
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
|
|
|
|
<span style="color:green;">'Required by the Windows Form Designer</span>
|
|
<span style="color:blue;">Private</span> components <span style="color:blue;">As</span> System.ComponentModel.<span style="color:#2b91af;">IContainer</span>
|
|
|
|
<span style="color:green;">'NOTE: The following procedure is required by the Windows Form Designer</span>
|
|
<span style="color:green;">'It can be modified using the Windows Form Designer. </span>
|
|
<span style="color:green;">'Do not modify it using the code editor.</span>
|
|
<System.Diagnostics.<span style="color:#2b91af;">DebuggerStepThrough</span>()> _
|
|
<span style="color:blue;">Private</span> <span style="color:blue;">Sub</span> InitializeComponent()
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton = <span style="color:blue;">New</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span>()
|
|
<span style="color:blue;">Me</span>.VaultsComboBox = <span style="color:blue;">New</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span>()
|
|
<span style="color:blue;">Me</span>.Label1 = <span style="color:blue;">New</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span>()
|
|
<span style="color:blue;">Me</span>.SuspendLayout()
|
|
<span style="color:green;">'</span>
|
|
<span style="color:green;">'ExecuteTemplateButton</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.Location = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Point</span>(30, 75)
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.Name = <span style="color:#a31515;">"ExecuteTemplateButton"</span>
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.Size = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Size</span>(102, 23)
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.TabIndex = 0
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.Text = <span style="color:#a31515;">"Execute Template"</span>
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.TextAlign = System.Drawing.<span style="color:#2b91af;">ContentAlignment</span>.MiddleLeft
|
|
<span style="color:blue;">Me</span>.ExecuteTemplateButton.UseVisualStyleBackColor = <span style="color:blue;">True</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:green;">'VaultsComboBox</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:blue;">Me</span>.VaultsComboBox.FormattingEnabled = <span style="color:blue;">True</span>
|
|
<span style="color:blue;">Me</span>.VaultsComboBox.Location = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Point</span>(30, 39)
|
|
<span style="color:blue;">Me</span>.VaultsComboBox.Name = <span style="color:#a31515;">"VaultsComboBox"</span>
|
|
<span style="color:blue;">Me</span>.VaultsComboBox.Size = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Size</span>(169, 21)
|
|
<span style="color:blue;">Me</span>.VaultsComboBox.TabIndex = 1
|
|
<span style="color:green;">'</span>
|
|
<span style="color:green;">'Label1</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:blue;">Me</span>.Label1.AutoSize = <span style="color:blue;">True</span>
|
|
<span style="color:blue;">Me</span>.Label1.Location = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Point</span>(27, 23)
|
|
<span style="color:blue;">Me</span>.Label1.Name = <span style="color:#a31515;">"Label1"</span>
|
|
<span style="color:blue;">Me</span>.Label1.Size = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Size</span>(91, 13)
|
|
<span style="color:blue;">Me</span>.Label1.TabIndex = 2
|
|
<span style="color:blue;">Me</span>.Label1.Text = <span style="color:#a31515;">"Select vault view:"</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:green;">'Form1</span>
|
|
<span style="color:green;">'</span>
|
|
<span style="color:blue;">Me</span>.AutoScaleDimensions = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">SizeF</span>(6.0!, 13.0!)
|
|
<span style="color:blue;">Me</span>.AutoScaleMode = System.Windows.Forms.<span style="color:#2b91af;">AutoScaleMode</span>.Font
|
|
<span style="color:blue;">Me</span>.ClientSize = <span style="color:blue;">New</span> System.Drawing.<span style="color:#2b91af;">Size</span>(246, 123)
|
|
<span style="color:blue;">Me</span>.Controls.Add(<span style="color:blue;">Me</span>.Label1)
|
|
<span style="color:blue;">Me</span>.Controls.Add(<span style="color:blue;">Me</span>.VaultsComboBox)
|
|
<span style="color:blue;">Me</span>.Controls.Add(<span style="color:blue;">Me</span>.ExecuteTemplateButton)
|
|
<span style="color:blue;">Me</span>.Name = <span style="color:#a31515;">"Form1"</span>
|
|
<span style="color:blue;">Me</span>.Text = <span style="color:#a31515;">"Execute Template"</span>
|
|
<span style="color:blue;">Me</span>.ResumeLayout(<span style="color:blue;">False</span>)
|
|
<span style="color:blue;">Me</span>.PerformLayout()
|
|
|
|
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
|
|
<span style="color:blue;">Friend</span> <span style="color:blue;">WithEvents</span> ExecuteTemplateButton <span style="color:blue;">As</span> System.Windows.Forms.<span style="color:#2b91af;">Button</span>
|
|
<span style="color:blue;">Friend</span> <span style="color:blue;">WithEvents</span> VaultsComboBox <span style="color:blue;">As</span> System.Windows.Forms.<span style="color:#2b91af;">ComboBox</span>
|
|
<span style="color:blue;">Friend</span> <span style="color:blue;">WithEvents</span> Label1 <span style="color:blue;">As</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span>
|
|
|
|
<span style="color:blue;">End</span> <span style="color:blue;">Class</span></pre>
|
|
</div>
|
|
<div align="center">
|
|
<pre style="font-family: Courier New; font-size: 13; color: #008000; background-image: none; background-repeat: repeat; background-attachment: scroll"><font face="Calibri"><a href="#Top">Back to top</a></font></pre>
|
|
</div>
|
|
|
|
<p> </p>
|
|
|
|
</body>
|
|
|
|
</html>
|