Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
draftsight / opt / dassault-systemes / DraftSight / APISDK / Create_Context-sensitive_Menu_Items_Example_VBA.htm
Size: Mime:
<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>'--------------------------------------------------------------
'&nbsp;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.
'&nbsp;5.&nbsp;Press&nbsp;F5.
'
'&nbsp;Postconditions:&nbsp;
'&nbsp;1.&nbsp;Connects&nbsp;to&nbsp;DraftSight.
'&nbsp;2.&nbsp;Gets&nbsp;the&nbsp;active&nbsp;document.
'&nbsp;3.&nbsp;Creates&nbsp;three&nbsp;user&nbsp;commands.
'&nbsp;4.&nbsp;Adds&nbsp;a&nbsp;default&nbsp;context-sensitive&nbsp;menu&nbsp;item&nbsp;for&nbsp;the&nbsp;first&nbsp;user&nbsp;command.
'&nbsp;5.&nbsp;Adds&nbsp;a&nbsp;command&nbsp;context-sensitive&nbsp;menu&nbsp;item&nbsp;for&nbsp;the&nbsp;second&nbsp;user&nbsp;command.
'&nbsp;6.&nbsp;Adds&nbsp;an&nbsp;object&nbsp;context-sensitive&nbsp;menu&nbsp;item&nbsp;for&nbsp;the third&nbsp;user&nbsp;command.
'&nbsp;7.&nbsp;Displays&nbsp;a&nbsp;message&nbsp;box&nbsp;informing&nbsp;you&nbsp;to&nbsp;perform&nbsp;steps&nbsp;7a&nbsp;-&nbsp;7f.&nbsp;Click&nbsp;<b>OK</b>
'&nbsp;&nbsp;&nbsp;&nbsp;to&nbsp;close&nbsp;the&nbsp;message&nbsp;box&nbsp;before&nbsp;performing&nbsp;these&nbsp;steps.
'&nbsp;&nbsp;&nbsp;&nbsp;a.&nbsp;Right-click&nbsp;anywhere&nbsp;in&nbsp;the&nbsp;the&nbsp;graphics&nbsp;area&nbsp;and&nbsp;
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;<b>Execute&nbsp;line</b>&nbsp;<b>command</b>&nbsp;in&nbsp;the&nbsp;context-sensitive&nbsp;menu.
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;The&nbsp;crosshair&nbsp;pointer&nbsp;is&nbsp;displayed.
'&nbsp;&nbsp;&nbsp;&nbsp;b.&nbsp;Right-click&nbsp;anywhere&nbsp;in&nbsp;the&nbsp;graphics&nbsp;area&nbsp;and&nbsp;select&nbsp;<b>Open&nbsp;Help</b>&nbsp;
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in&nbsp;the&nbsp;context-sensitive&nbsp;menu.&nbsp;The&nbsp;user-interface&nbsp;DraftSight&nbsp;
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Help&nbsp;system&nbsp;opens and displays the <b>Constructing Lines</b> Help topic.
'&nbsp;&nbsp;&nbsp;&nbsp;c.&nbsp;Read the Help topic and close&nbsp;the&nbsp;Help.
'&nbsp;&nbsp;&nbsp;&nbsp;d.&nbsp;Construct&nbsp;a&nbsp;line&nbsp;and&nbsp;select&nbsp;the&nbsp;line.
'&nbsp;&nbsp;&nbsp;&nbsp;e.&nbsp;Right-click&nbsp;anywhere&nbsp;in&nbsp;the&nbsp;graphics&nbsp;area&nbsp;and
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select&nbsp;<b>Do&nbsp;pattern</b>&nbsp;in&nbsp;the&nbsp;context-sensitive&nbsp;menu.
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A&nbsp;pattern&nbsp;of&nbsp;the selected Line&nbsp;is&nbsp;constructed.
'&nbsp;&nbsp;&nbsp;&nbsp;f.&nbsp;Press&nbsp;the&nbsp;Enter&nbsp;key&nbsp;and exit DraftSight.
'----------------------------------------------------------------
Option Explicit
</pre>
<pre>Sub main()</pre>
<pre>    Dim dsApp As DraftSight.Application</pre>
<pre>    'Connect to DraftSight
    Set dsApp = GetObject(, &quot;DraftSight.Application&quot;)    </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>(&quot;APIUUID&quot;, &quot;TEST_LINE&quot;, &quot;^C^C_LINE&quot; + vbLf, &quot;Line&quot;, &quot;&quot;, &quot;&quot;, dsUIState_e.dsUIState_Document, error)
    Set helpUserCmd = dsApp.<b>CreateUserCommand</b>(&quot;APIUUID&quot;, &quot;TEST_HELP&quot;, &quot;'_HELP&quot; + vbLf, &quot;Help&quot;, &quot;&quot;, &quot;&quot;, dsUIState_e.dsUIState_Document, error)
    Set patternUserCmd = dsApp.<b>CreateUserCommand</b>(&quot;APIUUID&quot;, &quot;TEST_PATTERN&quot;, &quot;_-PATTERN _L 3 3 5 5&quot; + vbLf + vbLf, &quot;Pattern&quot;, &quot;&quot;, &quot;&quot;, 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>(&quot;APIUUID&quot;, menuItemType, &quot;Execute line command&quot;, lineUserCmd.<b>GetID</b>)

    'Add command context-sensitive menu item for second user command  
    Set dsCommandContextMenuItem = dsApp.<b>AddCommandContextMenu</b>(&quot;APIUUID&quot;, menuItemType, &quot;Open Help&quot;, helpUserCmd.<b>GetID</b>, &quot;_LINE&quot;)

    'Add object context-sensitive menu item for third user command  
    Set dsObjectContextMenuItem = dsApp.<b>AddObjectContextMenu</b>(&quot;APIUUID&quot;, menuItemType, &quot;Do pattern&quot;, patternUserCmd.<b>GetID</b>, dsObjectType_e.dsLineType)    </pre>
<pre>    MsgBox &quot;Perform steps 7a - 7f.&quot;
</pre>
<pre>End Sub</pre>
<pre>&nbsp;</pre>
<p>&nbsp;</p>

</body>

</html>