Hide Table of Contents
InsertMenuItem Method (IMenuItem)

Inserts a menu item.

.NET Syntax

Visual Basic (Declaration) 
Function InsertMenuItem( _
   const dsString& ApiUuid As System.String, _
   dsMenuItemType_e ItemType As dsMenuItemType_e, _
   long Position As System.Integer, _
   const dsString& ItemName As System.String, _
   const dsString& UserCmdID As System.String _
) As MenuItem
C# 
MenuItem InsertMenuItem( 
   System.string ApiUuid,
   dsMenuItemType_e ItemType,
   System.int Position,
   System.string ItemName,
   System.string UserCmdID
)
JavaScript 
InsertMenuItem( 
   ApiUuid : String,
   ItemType : String,
   Position : Number,
   ItemName : String,
   UserCmdID : String
) : dsMenuItem
COM native C++ 
HRESULT InsertMenuItem( 
   BSTR ApiUuid,
   dsMenuItemType_e ItemType,
   LONG Position,
   BSTR ItemName,
   BSTR UserCmdID,
   IMenuItem** MenuItem
) 
C++ 
DSRESULT InsertMenuItem( 
   const dsString& ApiUuid,
   dsMenuItemType_e ItemType,
   long Position,
   const dsString& ItemName,
   const dsString& UserCmdID,
   dsMenuItem** MenuItem
) 

Parameters

ApiUuid

UUID of the add-in or non add-in application

ItemType
Type of menu item to insert as defined in dsMenuItemType_e
Position
1-based index indicating where to insert the menu item
ItemName
Name of menu item
UserCmdID
User-defined command ID when ItemType is dsMenuItemType_e.dsMenuItemType_UserCommand
MenuItem[out] or Return Value
Menu item

Example

The following code snippets show how to add a menu item to a menu:

 

COM native C++

DsAddinConnection.cpp

sAddinUserCommand pNotepad(m_sApiUuid, L"Notepad", L"^C^CNotepad", L"Opens Notepad", L"path_and_file_name.bmp", L"path_and_file_name.png");

IMenuItemPtr pMenu = m_DsApp->AddMenu( m_sApiUuid, dsUIState_Document, MENU_POSITION, L"DsAddin" );

pMenu->InsertMenuItem(m_sApiUuid, dsMenuItemType_UserCommand, 1, L"Open Notepad", pNotepad.GetUserCommandID());

 

DsAddinUserCommand.cpp

bstr_t DsAddinUserCommand::GetUserCommandID()
{
    return m_DsUserCommand->GetID();
}

 

C++

dsUserCommand_ptr pUserCmd;

dsApp->CreateUserCommand( myApplication::appID, UserCommandName, UserCmdString, Description, L"path_and_file_name.bmp", L"path_and_file_name.png", dsUIState_Document, &Error, &pUserCmd );

dsMenuItem_ptr pMenu;

dsApp->AddMenu(myApplication::appID, dsUIState_Document, MENU_POSITION, UserCommandName, &pMenu);

dsString UserCmdID1;

pUserCmd->GetID( &UserCmdID1 );

dsMenuItem_ptr pMenuItem;

pMenu->InsertMenuItem(myApplication::appID, dsMenuItemType_UserCommand, 1, L"Open Notepad", UserCmdID1, &pMenu);

if( ( dsCreateCommand_Succeeded == Error ) && ( NULL != pUserCmd ) )

{

dsString ToolbarName = L"QAddIn1_Toolbar";

dsToolbar_ptr pToolbar;

dsApp->AddToolbar( myApplication::appID, dsUIState_Document, ToolbarName, &pToolbar );

if( NULL != pToolbar )

 

{

dsToolbarItem_ptr pToolbarItem;

dsString ButtonName = L"Notepad";

dsString UserCmdID;

pMenu->GetID( &UserCmdID );

pToolbar->InsertToolbarItem( myApplication::appID, dsToolBarItemType_UserCommand, 1, ButtonName, UserCmdID, &pToolbarItem );

}

}

 

Back to top

 

See Also

Availability

DraftSight V1R1


Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   InsertMenuItem Method (IMenuItem)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2021 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.