Files
pdm/documentation/api_extracted/vbmenuitem.htm

380 lines
18 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<html>
<head>
<title>Creating Menu Commands (VB.NET)</title>
<meta name=MS-HKWD content="VB.NET,add-ins">
<meta name=MS-HKWD content="Add-ins, VB.NET">
<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">
<style>
<!--
div.Section1
{page:Section1;}
.auto-style3 {
color: #2B91AF;
font-size: x-small;
}
.auto-style1 {
font-size: x-small;
}
-->
</style>
</head>
<body>
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
<h1>Creating Menu Commands (VB.NET)</h1>
<div class=Section1>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-US style='font-family:Verdana'>This topic shows how to create a
VB.NET add-in in Microsoft Visual Studio that adds menu commands to
the context-sensitive and Tools menus of vaults in File
Explorer. </span></p>
<p style='margin:0in;margin-bottom:.0001pt'>
&nbsp;</p>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang="en-us"><b><span style="font-family: Verdana">NOTE: </span></b></span>
<span lang=EN-US style='font-family:Verdana;
mso-ansi-language:EN-US'>Because SOLIDWORKS PDM Professional cannot force a reload of
add-ins if they are written in .NET, all client machines must be restarted to ensure that the latest version of the add-in is used.<o:p></o:p></span></p>
<p style='margin:0in;margin-bottom:.0001pt'>&nbsp;</p>
<ol style="font-family: Verdana; font-size: 8pt">
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>Start </span>
<span
style='mso-ansi-language:EN-GB'>Microsoft </span>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>Visual Studio.<br>
&nbsp;</span></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>Click <b>File &gt;</b> <strong>New</strong></span><strong><span
style='mso-ansi-language:EN-GB'> &gt; </span></strong><font face="Verdana">
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><strong>Project</strong>. <br>
&nbsp;</span></font></p>
</li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana">Select <strong>Visual Basic</strong>
in<b> Installed </b>and<span lang="en-us"> select</span> <strong>
<span lang="en-us">Windows Desktop &gt; </span>Class Library</strong></span><strong><span
style='mso-ansi-language:EN-GB'> (.NET Framework)</span></strong><span lang=EN-GB
style='mso-ansi-language:EN-GB'>
as the template.<br>
&nbsp;</span></font></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'><font face="Verdana">
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>Type a name for the project in <b>Name</b> and
click <b>OK</b>.<br>
&nbsp;</span></font></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<font face="Verdana">
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>Click <b>Project &gt; Add Reference &gt; </b></span>
<span
style='mso-ansi-language:EN-GB'><strong>Browse</strong></span><span lang=EN-GB
style='mso-ansi-language:EN-GB'>, click </span>
<span
style='mso-ansi-language:EN-GB'><strong>EPDM.Interop.epdm.dll</strong></span><span lang=EN-GB
style='mso-ansi-language:EN-GB'>, and click </span>
<span
style='mso-ansi-language:EN-GB'><strong>OK</strong></span><span lang=EN-GB
style='mso-ansi-language:EN-GB'>.<br></span></font></p>
</li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang="en-us">Right-click <b>E</b></span><b>pdm.Interop.epdm</b><span lang="en-us"> in the Solution Explorer,
select <b>Properties</b>, and set <b>Embed Interop Types</b> to <b>False</b>
to handle methods that pass arrays of structures.</span><font face="Verdana"><span lang=EN-GB
style='mso-ansi-language:EN-GB'><br>
&nbsp;</span></font></p>
</li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'><span lang="en-gb">
<font face="Verdana">Click <b>Project &gt; Add Reference &gt; </b>
</span> <b>Assembly &gt; Framework</b><span lang="en-gb">,
click
</span> </font>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana"><b>System.Drawing,</b> and
click <span lang="en-us"><strong>OK</strong></span>. <br>
&nbsp;</font></span></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'><span lang="en-gb">
<font face="Verdana">Click <b>Close</b>.</font></span><span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana"><br>
&nbsp;</font></span></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana">Right-click the name of the
project in the Solution Explorer and select <b>Properties</b>.<br>
&nbsp;</font></span></p>
<ol style="font-family: Verdana; font-size: 8pt">
<li>
<p style='margin:0in;margin-bottom:.0001pt'><span lang="en-gb">
<font face="Verdana">On the Application tab, click </font></span>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana"><strong>Assembly Information.</strong>
<br>
&nbsp;</font></span></p></li>
<li>
<p style='margin:0in;margin-bottom:.0001pt'><span lang="en-gb">
<font face="Verdana">De-select </font></span>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'><font face="Verdana"><strong>Make assembly COM-Visible</strong><b>.<br>
&nbsp;</b></font></span></p>
</li>
<li>
<h4 style='margin:0in;margin-bottom:.0001pt' align="left">
<span lang="en-gb"><font face="Verdana"><span style="font-weight: 400">
On the <span lang="en-us">Compile</span> tab, <span lang="en-us">select
<strong>AnyCPU</strong> for the Target CPU, de-select <strong>Prefer
32-bit</strong>, and </span>select </span>Register for COM interop<span style="font-weight: 400">.<br>
&nbsp;</span></font></span></h4>
</li>
</ol>
</li>
<li>
<p style='margin-top:0in;margin-right:0in;margin-bottom:12.0pt;
margin-left:0in'><span lang=EN-GB style='mso-ansi-language:EN-GB'>Save the project</span><span lang=SV
style='mso-ansi-language:SV'><o:p>.</o:p></span></p></li>
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<font face="Verdana">Double-click
<b>Class1.vb</b> in the Solution Explorer
to open the code window.<br>
&nbsp;</font></p>
<ol style="font-family: Verdana; font-size: 8pt">
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<font face="Verdana">Before <b>Public Class
Class1</b> type:<br>
<br>
</font>
<b>
<font face="Courier New" size="2">Imports EPDM.Interop.epdm</font><font face="Verdana"><br>
</font>
</b><b><font face="Courier New" size="2">Imports&nbsp;System.Runtime.InteropServices</font></b><font face="Verdana"><b><br>
</b></font><font face="Courier New" size="2">&lt;<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">&quot;&quot;</span>)&gt;&nbsp;_<br>
&lt;<span style="color:#2b91af;">ComVisible</span>(<span style="color:blue;">True</span>)&gt;&nbsp;_<br>
&nbsp;</font></p></li>
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
To populate the GUID
attribute above, click <b>Tools &gt; Create GUID</b> in the IDE, select GUID
Format
6, click <b>Copy</b>, and click <b>Exit</b>. Replace
<font face="Courier New" size="2">&lt;<span style="color:#2b91af;">Guid</span>(<span style="color:#a31515;">&quot;&quot;</span>)&gt;</font>
with the copied string.<br>
&nbsp;</p></li>
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<font face="Verdana">Type <b>Implements IEdmAddIn5</b> after <b>Public Class
Class1 </b>and
make sure that the GetAddInInfo and OnCmd methods are generated after
you press <b>Enter</b>.<br>
&nbsp;</font></p></li>
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>Replace your add-in's
implementation of the
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~GetAddInInfo.html">IEdmAddIn5::GetAddInInfo</a> method with the following code<span lang=SV style='font-family:Verdana;mso-ansi-language:
SV'>:</span><span
lang=SV style='mso-ansi-language:SV'><o:p></o:p></span></p></li>
</ol>
<blockquote>
<p class=MsoNormal><span style='font-size:10.0pt;font-family:"Courier New"'>Public
Sub GetAddInInfo(ByRef poInfo As EdmAddInInfo, ByVal poVault As
EIEdmVault5, ByVal poCmdMgr As IEdmCmdMgr5) Implements
IEdmAddIn5.GetAddInInfo<br><br><span style='color:#669966'>&nbsp;</span><span style='color:#009900'>
'Specify the add-in information&nbsp;</span><br>&nbsp; poInfo.mbsAddInName = &quot;Menu command sample&quot;<br>&nbsp; poInfo.mbsCompany = &quot;SOLIDWORKS Corporation&quot;<br>&nbsp; poInfo.mbsDescription = &quot;Adds menu
command items&quot;<br>&nbsp; poInfo.mlAddInVersion = 1<br>&nbsp; poInfo.mlRequiredVersionMajor = 5<br>&nbsp; poInfo.mlRequiredVersionMinor = 2<br><br><span style='color:#009900'>&nbsp; 'Add
menu command items (the command-ID numbers 1000 and 1001 are<br>&nbsp; 'arbitrary; PDM does not use them;
instead, PDM only passes them to the<br>&nbsp; 'implementation of OnCmd
to know which command was selected)</span><br>&nbsp; poCmdMgr.AddCmd(1000, &quot;First command&quot;,
EdmMenuFlags.EdmMenu_Nothing, &quot;This is the first command&quot;,
&quot;First command&quot;, 0, 99)<br>&nbsp; poCmdMgr.AddCmd(1001, &quot;Second command&quot;,
EdmMenuFlags.EdmMenu_MustHaveSelection, &quot;This is the second
command&quot;, &quot;Second command&quot;, 1, 99)<br><br>End Sub</span><span lang=EN-GB
style='font-family:Verdana;mso-ansi-language:EN-GB'><br><br>The flag</span><font face="Verdana"><span lang=EN-GB style='mso-ansi-language:EN-GB'>
</span></font>
<span
lang=EN-GB style='font-family:Verdana;mso-ansi-language:EN-GB'>
<a style="text-decoration: underline" href="EPDM.Interop.epdm~EPDM.Interop.epdm.EdmMenuFlags.html">EdmMenuFlags.EdmMenu_MustHaveSelection</a></span><font face="Verdana"><span
lang=SV style='mso-ansi-language:EN-GB'> </span></font>
<span lang=EN-GB
style='font-family:Verdana;mso-ansi-language:EN-GB'>means that
the second command is only available if the user has selected one or more
files or folders.</span></p>
</blockquote>
<ol>
<li class=kadov-p value="5">
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='font-family:Verdana;mso-ansi-language:EN-GB'>Replace your add-in's
implementation of the
<a href="EPDM.Interop.epdm~EPDM.Interop.epdm.IEdmAddIn5~OnCmd.html">
IEdmAddIn5::OnCmd</a> method with the
following code (IEdmAddIn5::OnCmd is called when a menu command is selected by the
user):</span> </li>
</ol>
<blockquote>
<span
style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>Public Sub OnCmd(ByRef poCmd As EdmCmd,
</span>
<span style='font-family:"Courier New"'>
<span style="color:blue;" class="auto-style1">ByRef</span></span><span style='font-size:10.0pt;
font-family:"Courier New"'><span style='font-family:"Courier New"' class="auto-style1">&nbsp;ppoData&nbsp;<span style="color:blue;">As</span></span><font size="1">&nbsp;<span class="auto-style3">EdmCmdData</span><span class="auto-style1">[]</span></font>) Implements IEdmAddIn5.OnCmd</span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New";color:#009900'>&nbsp; 'Check the command ID to
see which command was selected<br>
&nbsp; '(This only affects the
caption of the message box below)<br>
&nbsp; </span><span style='font-size:10.0pt;
font-family:"Courier New"'>Dim CommandName As String</span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; If poCmd.mlCmdID = 1000 Then<br>&nbsp; &nbsp; CommandName = &quot;The first command.&quot;
</span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; Else<br>&nbsp; &nbsp; CommandName = &quot;The second command.&quot;</span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; End If </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New";color:#009900'>&nbsp; 'Retrieve the bounds of the
array containing the selected files and folders <br>
&nbsp; </span><span style='font-size:10.0pt;
font-family:"Courier New"'>Dim index As Long </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; Dim last As Long </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; index = LBound(ppoData) </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; last = UBound(ppoData) </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; Dim StrID As String </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New";color:#009900'>&nbsp; <br>
&nbsp; 'Create a message showing the
names and IDs of all selected files and folders</span><span
style='font-size:10.0pt;font-family:"Courier New"'> </span>
<span style='font-size:10.0pt;
font-family:"Courier New"'><br>&nbsp; Dim message As String
<o:p></o:p></span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'><span style='mso-spacerun:yes'> </span><span
style='mso-spacerun:yes'> </span>message = &quot;You have selected the
following files and folders: &quot; + vbLf </span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'>&nbsp; While index &lt;= last<br>&nbsp; &nbsp; If ppoData(index).mlObjectID1 = 0 Then<br>&nbsp; &nbsp; &nbsp; message = message + &quot;Folder: (ID=&quot;<o:p></o:p></span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'><span style='mso-spacerun:yes'>      </span>StrID
= ppoData(index).mlObjectID2<o:p></o:p></span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'><span style='mso-spacerun:yes'>      </span>message
= message + StrID + &quot;) &quot;<br>&nbsp; &nbsp; Else<br>&nbsp; &nbsp; &nbsp; &nbsp; message = message + &quot;File: (ID=&quot;<o:p></o:p></span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'><span style='mso-spacerun:yes'>        </span>StrID
= ppoData(index).mlObjectID1<o:p></o:p></span></p>
<p class=MsoNormal style='line-height:11.3pt'>
<span style='font-size:10.0pt;
font-family:"Courier New"'><span style='mso-spacerun:yes'>        </span>message
= message + StrID + &quot;) &quot;<br>&nbsp; &nbsp; End If<br><br>&nbsp; &nbsp; message = message + ppoData(index).mbsStrData1 + vbLf<br>&nbsp; &nbsp; index = index + 1<br>&nbsp; End While<br>
<br><span style='color:#009900'>&nbsp; 'Display the message<br></span>&nbsp; Dim v As EdmVault5<br>&nbsp; v = poCmd.mpoVault<br>&nbsp; v.MsgBox(poCmd.mlParentWnd, message, EdmMBoxType.EdmMbt_OKOnly,
CommandName)<br><br>End Sub</span></p>
</blockquote>
</li>
<li>
<p class=MsoNormal style='line-height:11.3pt'>
<span lang=EN-US style='mso-ansi-language:EN-US'>Click <b>Build &gt; Build
Solution</b> to build the add-in.</span></p></li>
<li><span lang="en-us">I</span><span lang=EN-US style='mso-ansi-language:EN-US'>nstall
the add-in through the SOLIDWORKS PDM Professional
Administration tool: <br>&nbsp;</span><ol style="font-family: Verdana; font-size: 8pt">
<li><span lang="en-us">Open</span><span lang=EN-US style='mso-ansi-language:EN-US'> the SOLIDWORKS
PDM Professional Administration tool.<br>&nbsp;</span></li>
<li><span lang=EN-US style='mso-ansi-language:EN-US'>Expand the vault where
you want to install this add-in and log in as Admin.<br>&nbsp;</span></li>
<li><span lang="en-us">Right-click <b>Add-ins</b> and click <b>New
Add-in</b>.<b><br>
&nbsp;</b></span></li>
<li>B<span lang="en-us">rowse to </span>
<span lang=EN-US style='mso-ansi-language:EN-US'>
<i style='mso-bidi-font-style:
normal'>project_path</i><span style='mso-bidi-font-style:
normal; '><i>\</i></span></span><span style='mso-bidi-font-style:
normal; mso-ansi-language:EN-US' lang="EN-US"><i>project_name\project_name</i><b>\bin\Debug</b>,
click <i>project_name</i><b>.dll</b> and <b>EPDM.Interop.epdm.dll</b>.<br>&nbsp;</span></li>
<li><span lang="en-us">Click <b>Open</b>.<br>
&nbsp;</span></li>
<li>Click <b>OK</b>.<br>
&nbsp;</li>
<li>Click <b>OK</b>.</li>
</ol>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB style='font-family:Verdana;mso-ansi-language:EN-GB'><br>
</span><span lang=EN-GB
style='mso-ansi-language:EN-GB'>&nbsp;</span><span style='font-size:10.0pt;
font-family:Arial'><o:p></o:p></span></p></li>
<li>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<span lang="en-gb"><font face="Verdana">The first</font></span><font face="Verdana"><span lang=EN-GB
style='mso-ansi-language:EN-GB'> menu command appears in the context-sensitive
and Tools menus of vault files in </span>
<span
style='mso-ansi-language:EN-GB'> File</span><span lang=EN-GB
style='mso-ansi-language:EN-GB'>
Explorer. The second menu command
appears in the context-sensitive menus only when one or more files or folders are selected.</span></font>
<span style="font-family: Verdana" lang="en-gb">Right-click a file in
the</span><span lang=EN-GB
style='font-family:Verdana;mso-ansi-language:EN-GB'> vault and select <b>Second
command</b>. A dialog similar to the following is displayed:</span></p>
</li>
</ol>
<blockquote>
<p class=section1 style='margin:0in;margin-bottom:.0001pt'>
<span lang=EN-GB
style='mso-ansi-language:EN-GB'>&nbsp;</span><span lang=SV
style='mso-ansi-language:SV'><img border=0 width=266 height=185
id="_x0000_i1029" src=advancedmenu.gif></span></p>
</blockquote>
</div>
</body>
</html>