246 lines
27 KiB
HTML
246 lines
27 KiB
HTML
<html>
|
|
|
|
<head>
|
|
<title>Find Revisions Using Component 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,revision numbers">
|
|
<meta name=MS-HKWD content="C# examples,revisions">
|
|
<meta name=MS-HKWD content="C# examples,revision number components">
|
|
|
|
<body>
|
|
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Find Revisions Using Component Example (C#)</h1>
|
|
<p><a name="Top"></a>This example shows how to find the revision numbers using
|
|
the revision number component named <b>Alpha Revision Component</b>.</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="FindRevisions.gif" width="344" height="214"></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;">// 2. Click <b>File > New > Project > C# > Windows Forms Application</b>.</span>
|
|
<span style="color:green;">// 3. Type <b>FindRevisionsCSharp</b> in Name.</span>
|
|
<span style="color:green;">// 4. Click the <b>Browse</b> button and browse to the folder where to create the project.</span>
|
|
<span style="color:green;">// 5. Click <b>OK</b>. </span>
|
|
<span style="color:green;">// 6. Create a form similar to the form shown above and change: </span>
|
|
<span style="color:green;">// a. Label to <b>VaultsLabel</b>.</span>
|
|
<span style="color:green;">// b. Combo box to <b>VaultsComboBox</b>. </span>
|
|
<span style="color:green;">// c. Button to <b>FindRevisionsButton</b>. </span>
|
|
<span style="color:green;">// 7. Replace the code in <b>Form1.cs</b> with <a href="#Form1">this code</a>.</span>
|
|
<span style="color:green;">// 8. Replace the code in F<b>orm1.Designer.cs</b> with <a href="#Designer">this code</a>.</span>
|
|
<span style="color:green;">// 9. Add E<b>PDM.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>Framework</b> in the left-side panel, browse to the top folder of your </span>
|
|
<span style="color:green;">// 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;">// 10. 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;">// 11. Open the Immediate window.</span>
|
|
<span style="color:green;">// 12. Switch back to the <b>Form1.cs</b> code window.</span>
|
|
<span style="color:green;">// 13. 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 a dialog.</span>
|
|
<span style="color:green;">// 2. Select a vault.</span>
|
|
<span style="color:green;">// 3. Click the <b>Find revisions that use Alpha Revision Component</b> button.</span>
|
|
<span style="color:green;">// 4. Prints the names of the revision numbers using the revision number
|
|
// </span><span style="color: green">component </span><span style="color:green;"><b>Alpha Revision Component </b></span><span style="color: green">to the </span><span style="color:green;">Immediate window. </span>
|
|
<span style="color:green;">// 5. Examine the Immediate window.</span>
|
|
<span style="color:green;">// 6. Close the dialog.</span>
|
|
<span style="color:green;">//---------------------------------------------------------------------------- </span>
|
|
</pre>
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:green;"><a name="Form1"></a>//Form1.cs</span>
|
|
|
|
<span style="color:blue;">using</span> EPDM.Interop.epdm;
|
|
<span style="color:blue;">using</span> System;
|
|
<span style="color:blue;">using</span> System.Diagnostics;
|
|
<span style="color:blue;">using</span> System.Windows.Forms;
|
|
<span style="color:blue;">using</span> System.Runtime.InteropServices;
|
|
|
|
<span style="color:blue;">namespace</span> FindRevisionsCSharp
|
|
{
|
|
<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:blue;">void</span> FindRevisionsCSharp_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:green;">//Declare and create an instance of IEdmVault5</span>
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault1 = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
|
|
|
<span style="color:green;">//Cast IEdmVault5 to IEdmVault8</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> FindRevisionsButton_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:green;">//Declare and create an instance of IEdmVault5 object
|
|
//and cast to IEdmVault7</span>
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
|
<span style="color:#2b91af;">IEdmVault7</span> vault1 = (<span style="color:#2b91af;">IEdmVault7</span>)vault;
|
|
|
|
<span style="color:green;">//Log into selected vault as the current user</span>
|
|
vault.<b>LoginAuto</b>(VaultsComboBox.Text, <span style="color:blue;">this</span>.Handle.ToInt32());
|
|
|
|
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">"Revision numbers that use revision number component \"Alpha Revision Component\":"</span>);
|
|
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">""</span>);
|
|
|
|
<span style="color:#2b91af;">IEdmRevisionMgr2</span> RevMgr = <span style="color:blue;">default</span>(<span style="color:#2b91af;">IEdmRevisionMgr2</span>);
|
|
RevMgr = (<span style="color:#2b91af;">IEdmRevisionMgr2</span>)vault1.<b>CreateUtility</b>(<span style="color:#2b91af;">EdmUtility</span>.EdmUtil_RevisionMgr);
|
|
|
|
<span style="color:#2b91af;">EdmRevNo</span>[] RevNumbers = <span style="color:blue;">null</span>;
|
|
RevMgr.<b>GetRevisionNumbers</b>(<span style="color:blue;">null</span>, <span style="color:blue;">out</span> RevNumbers);
|
|
<span style="color:blue;">foreach</span> ( <span style="color:#2b91af;">EdmRevNo</span> RevNo <span style="color:blue;">in</span> RevNumbers) {
|
|
<span style="color:#2b91af;">EdmRevComponent2</span>[] RevComponents = <span style="color:blue;">null</span>;
|
|
RevMgr.<b>GetRevisionNumberComponents2</b>(-RevNo.mlRevNoID, <span style="color:blue;">out</span> RevComponents);
|
|
<span style="color:blue;">foreach</span> ( <span style="color:#2b91af;">EdmRevComponent2</span> RevComponent <span style="color:blue;">in</span> RevComponents) {
|
|
<span style="color:blue;">if</span> (RevComponent.<b>mbsComponentName</b> == <span style="color:#a31515;">"Alpha Revision Component"</span>) {
|
|
<span style="color:#2b91af;">Debug</span>.Print(<span style="color:#a31515;">" "</span> + RevNo.<b>mbsRevNoName</b>);
|
|
}
|
|
}
|
|
}
|
|
|
|
} <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: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a></pre>
|
|
</div>
|
|
<pre style="font-family: Courier New; font-size: 13; color: #008000; background: white"><a name="Designer"></a>//Form1.Designer.cs</pre>
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:blue;">namespace</span> FindRevisionsCSharp
|
|
{
|
|
<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>.VaultsLabel = <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>.FindRevisionsButton = <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;">// VaultsLabel</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.VaultsLabel.AutoSize = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.VaultsLabel.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(112, 37);
|
|
<span style="color:blue;">this</span>.VaultsLabel.Name = <span style="color:#a31515;">"VaultsLabel"</span>;
|
|
<span style="color:blue;">this</span>.VaultsLabel.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(91, 13);
|
|
<span style="color:blue;">this</span>.VaultsLabel.TabIndex = 0;
|
|
<span style="color:blue;">this</span>.VaultsLabel.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>(94, 77);
|
|
<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>(121, 21);
|
|
<span style="color:blue;">this</span>.VaultsComboBox.TabIndex = 1;
|
|
<span style="color:green;">// </span>
|
|
<span style="color:green;">// FindRevisionsButton</span>
|
|
<span style="color:green;">// </span>
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.Location = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Point</span>(94, 136);
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.Name = <span style="color:#a31515;">"FindRevisionsButton"</span>;
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.Size = <span style="color:blue;">new</span> System.Drawing.<span style="color:#2b91af;">Size</span>(121, 50);
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.TabIndex = 2;
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.Text = <span style="color:#a31515;">"Find revisions that use Alpha Revision Component"</span>;
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.UseVisualStyleBackColor = <span style="color:blue;">true</span>;
|
|
<span style="color:blue;">this</span>.FindRevisionsButton.Click += <span style="color:blue;">new</span> System.<span style="color:#2b91af;">EventHandler</span>(<span style="color:blue;">this</span>.FindRevisionsButton_Click);
|
|
<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>(304, 209);
|
|
<span style="color:blue;">this</span>.Controls.Add(<span style="color:blue;">this</span>.FindRevisionsButton);
|
|
<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>.VaultsLabel);
|
|
<span style="color:blue;">this</span>.Name = <span style="color:#a31515;">"Form1"</span>;
|
|
<span style="color:blue;">this</span>.Text = <span style="color:#a31515;">"Find revisions using component"</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>.FindRevisionsCSharp_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;"> #endregion</span>
|
|
|
|
<span style="color:blue;">private</span> System.Windows.Forms.<span style="color:#2b91af;">Label</span> VaultsLabel;
|
|
<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> FindRevisionsButton;
|
|
}
|
|
}</pre>
|
|
<div align="center">
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><a href="#Top">Back to top</a></pre>
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|