Repository URL to install this package:
|
Version:
2016.3.0.4050 ▾
|
draftsight
/
opt
/
dassault-systemes
/
DraftSight
/
APISDK
/
Create_Context-sensitive_Menu_Items_Example_VBA.htm
|
|---|
<html>
<head>
<title>Create Context-sensitive Menu Items Example (VBA)</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="VBA examples">
<meta name=MS-HKWD content="VBA examples,context-sensitive menu items ">
</head>
<body>
<h1>Create Context-sensitive Menu Items Example (VBA)</h1>
<p>This example shows how to create default, command, and object
context-sensitive menu items.</p>
<pre>'--------------------------------------------------------------
' Preconditions:
' 1. Create a VBA macro in a software product in which VBA is
' embedded.
' 2. Copy and paste this example into the Visual Basic IDE.
' 3. Add a reference to the DraftSight type library,
' <i>install_dir</i>\<b>bin\dsAutomation.dll</b>.
' 4. Start DraftSight and open a document.
' 5. Press F5.
'
' Postconditions:
' 1. Connects to DraftSight.
' 2. Gets the active document.
' 3. Creates three user commands.
' 4. Adds a default context-sensitive menu item for the first user command.
' 5. Adds a command context-sensitive menu item for the second user command.
' 6. Adds an object context-sensitive menu item for the third user command.
' 7. Displays a message box informing you to perform steps 7a - 7f. Click <b>OK</b>
' to close the message box before performing these steps.
' a. Right-click anywhere in the the graphics area and
' select <b>Execute line</b> <b>command</b> in the context-sensitive menu.
' The crosshair pointer is displayed.
' b. Right-click anywhere in the graphics area and select <b>Open Help</b>
' in the context-sensitive menu. The user-interface DraftSight
' Help system opens and displays the <b>Constructing Lines</b> Help topic.
' c. Read the Help topic and close the Help.
' d. Construct a line and select the line.
' e. Right-click anywhere in the graphics area and
' select <b>Do pattern</b> in the context-sensitive menu.
' A pattern of the selected Line is constructed.
' f. Press the Enter key and exit DraftSight.
'----------------------------------------------------------------
Option Explicit
</pre>
<pre>Sub main()</pre>
<pre> Dim dsApp As DraftSight.Application</pre>
<pre> 'Connect to DraftSight
Set dsApp = GetObject(, "DraftSight.Application") </pre>
<pre> 'Abort any command currently running in DraftSight
'to avoid nested commands
dsApp.<b>AbortRunningCommand</b>
</pre>
<pre> 'Get active document
Dim dsDoc As DraftSight.Document
Set dsDoc = dsApp.<b>GetActiveDocument</b>()
</pre>
<pre> 'Create three user commands for the context-sensitive menus
Dim error As Long
Dim lineUserCmd As UserCommand
Dim helpUserCmd As UserCommand
Dim patternUserCmd As UserCommand
</pre>
<pre> Set lineUserCmd = dsApp.<b>CreateUserCommand</b>("APIUUID", "TEST_LINE", "^C^C_LINE" + vbLf, "Line", "", "", dsUIState_e.dsUIState_Document, error)
Set helpUserCmd = dsApp.<b>CreateUserCommand</b>("APIUUID", "TEST_HELP", "'_HELP" + vbLf, "Help", "", "", dsUIState_e.dsUIState_Document, error)
Set patternUserCmd = dsApp.<b>CreateUserCommand</b>("APIUUID", "TEST_PATTERN", "_-PATTERN _L 3 3 5 5" + vbLf + vbLf, "Pattern", "", "", dsUIState_e.dsUIState_Document, error)
</pre>
<pre> Dim menuItemType As Long
menuItemType = dsMenuItemType_e.dsMenuItemType_UserCommand
</pre>
<pre> Dim dsDefaultContextMenuItem As ContextMenuItem
Dim dsCommandContextMenuItem As ContextMenuItem
Dim dsObjectContextMenuItem As ContextMenuItem
</pre>
<pre> 'Add default context-sensitive menu item for first user command
Set dsDefaultContextMenuItem = dsApp.<b>AddDefaultContextMenu</b>("APIUUID", menuItemType, "Execute line command", lineUserCmd.<b>GetID</b>)
'Add command context-sensitive menu item for second user command
Set dsCommandContextMenuItem = dsApp.<b>AddCommandContextMenu</b>("APIUUID", menuItemType, "Open Help", helpUserCmd.<b>GetID</b>, "_LINE")
'Add object context-sensitive menu item for third user command
Set dsObjectContextMenuItem = dsApp.<b>AddObjectContextMenu</b>("APIUUID", menuItemType, "Do pattern", patternUserCmd.<b>GetID</b>, dsObjectType_e.dsLineType) </pre>
<pre> MsgBox "Perform steps 7a - 7f."
</pre>
<pre>End Sub</pre>
<pre> </pre>
<p> </p>
</body>
</html>