Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Context-sensitive_Menu_Items_Example_VBNET.htm
|
|---|
<html>
<head>
<title>Create Context-sensitive Menu Items 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">
<meta name=MS-HKWD content="VB.NET examples">
<meta name=MS-HKWD content="VB.NET examples,context-sensitive menu items">
</head>
<body>
<h1>Create Context-sensitive Menu Items Example (VB.NET)</h1>
<p>This example shows how to create default, command, and object
context-sensitive menu items.</p>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"><span style="color:green;">'--------------------------------------------------------------</span>
<span style="color:green;">' Preconditions:</span>
<span style="color:green;">' 1. Create a VB.NET Windows console project.</span>
<span style="color:green;">' 2. Copy and paste this code into the VB.NET project.</span>
<span style="color:green;">' 3. Add a reference to</span>
<span style="color:green;">' <i>install_dir</i>\<b>APISDK\tlb\DraftSight.Interop.dsAutomation.dll</b>.</span>
<span style="color:green;">' 4. Add a reference to <b>System.Windows.Forms</b>.</span>
<span style="color:green;">' 5. Start DraftSight.</span>
<span style="color:green;">' 6. Press F5.</span>
<span style="color:green;">'</span>
<span style="color:green;">' Postconditions: </span>
<span style="color:green;">' 1. Connects to DraftSight.</span>
<span style="color:green;">' 2. Gets the active document.</span>
<span style="color:green;">' 3. Creates three user commands.</span>
<span style="color:green;">' 4. Adds a default context-sensitive menu item for the first user command.</span>
<span style="color:green;">' 5. Adds a command context-sensitive menu item for the second user command.</span>
<span style="color:green;">' 6. Adds an object context-sensitive menu item for the third user command.</span>
<span style="color:green;">' 7. Displays a message box informing you to perform steps 7a - 7f. Click <b>OK</b></span>
<span style="color:green;">' to close the message box before performing these steps.</span>
<span style="color:green;">' a. Right-click anywhere in the the graphics area and </span>
<span style="color:green;">' select <b>Execute line command</b> in the context-sensitive menu.</span>
<span style="color:green;">' The crosshair pointer is displayed.</span>
<span style="color:green;">' b. Right-click anywhere in the graphics area and select <b>Open Help</b> </span>
<span style="color:green;">' in the context-sensitive menu. The user-interface DraftSight </span>
<span style="color:green;">' Help system opens and displays the <b>Constructing Lines</b> Help topic.</span>
<span style="color:green;">' c. Read the Help topic and close the Help.</span>
<span style="color:green;">' d. Construct a line and select the line.</span>
<span style="color:green;">' e. Right-click anywhere in the graphics area and</span>
<span style="color:green;">' select <b>Do pattern</b> in the context-sensitive menu.</span>
<span style="color:green;">' A pattern of the selected Line is constructed.</span>
<span style="color:green;">' f. Press the Enter </span><span style="color: #008000">key and exit DraftSight.</span>
<span style="color:green;">'----------------------------------------------------------------</span>
<span style="color:blue;">Imports</span> System
<span style="color:blue;">Imports</span> DraftSight.Interop.dsAutomation
<span style="color:blue;">Imports</span> System.Runtime.InteropServices
<span style="color:blue;">Imports</span> System.Windows.Forms
<span style="color:blue;">Module</span> <span style="color:#2b91af;">Module1</span>
<span style="color:blue;">Sub</span> Main()
<span style="color:blue;">Dim</span> dsApp <span style="color:blue;">As</span> DraftSight.Interop.dsAutomation.<span style="color:#2b91af;">Application</span>
<span style="color:green;">'Connect to DraftSight application</span>
dsApp = GetObject(, <span style="color:#a31515;">"DraftSight.Application"</span>)
<span style="color:blue;">If</span> dsApp <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
<span style="color:blue;">Return</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white"> <span style="COLOR: green">'Abort any command currently running in DraftSight to avoid nested commands</span>
dsApp.<b>AbortRunningCommand</b>()
<span style="color:green;">'Get active document</span>
<span style="color:blue;">Dim</span> dsDoc <span style="color:blue;">As</span> <span style="color:#2b91af;">Document</span> = dsApp.<b>GetActiveDocument</b>()
<span style="color:blue;">If</span> dsDoc <span style="color:blue;">Is</span> <span style="color:blue;">Nothing</span> <span style="color:blue;">Then</span>
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"There are no open documents in DraftSight."</span>)
<span style="color:blue;">Return</span>
<span style="color:blue;">End</span> <span style="color:blue;">If</span>
<span style="color:green;">'Create three user commands for the context-sensitive menus</span>
<span style="color:blue;">Dim</span> [error] <span style="color:blue;">As</span> <span style="color:#2b91af;">dsCreateCommandError_e</span>
<span style="color:blue;">Dim</span> lineUserCmd <span style="color:blue;">As</span> <span style="color:#2b91af;">UserCommand</span> = dsApp.<b>CreateUserCommand</b>(<span style="color:#a31515;">"APIUUID"</span>, <span style="color:#a31515;">"TEST_LINE"</span>, <span style="color:#a31515;">"^C^C_LINE"</span> & vbLf, <span style="color:#a31515;">"Line"</span>, <span style="color:blue;">String</span>.Empty, <span style="color:blue;">String</span>.Empty, _
<span style="color:#2b91af;">dsUIState_e</span>.dsUIState_Document, [error])
<span style="color:blue;">Dim</span> helpUserCmd <span style="color:blue;">As</span> <span style="color:#2b91af;">UserCommand</span> = dsApp.<b>CreateUserCommand</b>(<span style="color:#a31515;">"APIUUID"</span>, <span style="color:#a31515;">"TEST_HELP"</span>, <span style="color:#a31515;">"'_HELP"</span> & vbLf, <span style="color:#a31515;">"Help"</span>, <span style="color:blue;">String</span>.Empty, <span style="color:blue;">String</span>.Empty, _
<span style="color:#2b91af;">dsUIState_e</span>.dsUIState_Document, [error])
<span style="color:blue;">Dim</span> patternUserCmd <span style="color:blue;">As</span> <span style="color:#2b91af;">UserCommand</span> = dsApp.<b>CreateUserCommand</b>(<span style="color:#a31515;">"APIUUID"</span>, <span style="color:#a31515;">"TEST_PATTERN"</span>, <span style="color:#a31515;">"_-PATTERN _L 3 3 5 5"</span> & vbLf & vbLf, <span style="color:#a31515;">"Pattern"</span>, <span style="color:blue;">String</span>.Empty, <span style="color:blue;">String</span>.Empty, _
<span style="color:#2b91af;">dsUIState_e</span>.dsUIState_Document, [error])
<span style="color:blue;">Dim</span> menuItemType <span style="color:blue;">As</span> <span style="color:#2b91af;">dsMenuItemType_e</span> = <span style="color:#2b91af;">dsMenuItemType_e</span>.dsMenuItemType_UserCommand
<span style="color:green;">'Add default context-sensitive menu item for first user command</span>
<span style="color:blue;">Dim</span> dsDefaultContextMenuItem <span style="color:blue;">As</span> <span style="color:#2b91af;">ContextMenuItem</span> = dsApp.<b>AddDefaultContextMenu</b>(<span style="color:#a31515;">"APIUUID"</span>, menuItemType, <span style="color:#a31515;">"Execute line command"</span>, lineUserCmd.<b>GetID</b>())
<span style="color:green;">'Add command context-sensitive menu item for second user command</span>
<span style="color:blue;">Dim</span> dsCommandContextMenuItem <span style="color:blue;">As</span> <span style="color:#2b91af;">ContextMenuItem</span> = dsApp.<b>AddCommandContextMenu</b>(<span style="color:#a31515;">"APIUUID"</span>, menuItemType, <span style="color:#a31515;">"Open Help"</span>, helpUserCmd.<b>GetID</b>(), <span style="color:#a31515;">"_LINE"</span>)
<span style="color:green;">'Add object context-sensitive menu item for third user command</span>
<span style="color:blue;">Dim</span> dsObjectContextMenuItem <span style="color:blue;">As</span> <span style="color:#2b91af;">ContextMenuItem</span> = dsApp.<b>AddObjectContextMenu</b>(<span style="color:#a31515;">"APIUUID"</span>, menuItemType, <span style="color:#a31515;">"Do pattern"</span>, patternUserCmd.<b>GetID</b>(), <span style="color:#2b91af;">dsObjectType_e</span>.dsLineType)
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"Perform steps 7a - 7f."</span>)
<span style="color:blue;">End</span> <span style="color:blue;">Sub</span>
<span style="color:blue;">End</span> <span style="color:blue;">Module</span></pre>
<pre style="font-family: Consolas; font-size: 13; color: black; background: white">
</pre>
</body>
</html>