Hide Table of Contents
InsertToolbarItem Method (IToolbar)
Item[out]
Toolbar item

Inserts a toolbar item.

.NET Syntax

Visual Basic (Declaration) 
Function InsertToolbarItem( _
   const dsString& ApiUuid As System.String, _
   dsToolbarItemType_e ItemType As dsToolbarItemType_e, _
   long Position As System.Integer, _
   const dsString& ItemName As System.String, _
   const dsString& UserCmdID As System.String _
) As ToolbarItem
C# 
ToolbarItem InsertToolbarItem( 
   System.string ApiUuid,
   dsToolbarItemType_e ItemType,
   System.int Position,
   System.string ItemName,
   System.string UserCmdID
)
JavaScript 
InsertToolbarItem( 
   ApiUuid : String,
   ItemType : String,
   Position : Number,
   ItemName : String,
   UserCmdID : String
) : dsToolbarItem
COM native C++ 
HRESULT InsertToolbarItem( 
   BSTR ApiUuid,
   dsToolbarItemType_e ItemType,
   LONG Position,
   BSTR ItemName,
   BSTR UserCmdID,
   IToolbarItem** Item
) 
C++ 
DSRESULT InsertToolbarItem( 
   const dsString& ApiUuid,
   dsToolbarItemType_e ItemType,
   long Position,
   const dsString& ItemName,
   const dsString& UserCmdID,
   dsToolbarItem** Item
) 

Parameters

ApiUuid

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

ItemType
Type of toolbar item as defined in dsToolbarItemType_e
Position
1-based index indicating where to insert toolbar item in the toolbar
ItemName
Name of toolbar item
UserCmdID
User-defined command ID when ItemType is dsToolbarItemType_e.dsToolBarItemType_UserCommand
Item[out] or Return Value
Toolbar item

Example

The following code snippets show how to add a toolbar button with a ToolTip to a toolbar:

COM native C++

DsAddinConnection.cpp

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

IToolbarPtr pToolbar = m_DsApp->AddToolbar( m_sApiUuid, dsUIState_Document, L"DsAddin Toolbar");

IToolbarItemPtr pToolbarItem;

pToolbarItem = pToolbar->InsertToolbarItem( m_sApiUuid, dsToolBarItemType_UserCommand, ++position, L"Open Notepad", pNotepad.GetUserCommandID()); 

 

DsAddinUserCommand.cpp 

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

 

C++

bool myApplication::CreateUserInterfaceAndCommands()

{

dsString emptyStr = L"";

dsString UserCommandName = L"qAddin1_Notepad";

dsString Description = L"Opens Notepad";

dsString UserCmdString = L"^C^CqAddin1_Notepad";

 

const int MENU_POSITION = 9; //Menu should be between "Modify" and "Tools" menus

 

dsApplication_c *dsApp = getDsApp();

dsCreateCommandError_e Error;

 

dsApp->CreateCommand(myApplication::appID, UserCommandName, &Error, &pCmd );

if(( Error == 0 ) )

{

RegisterCommandExecuteNotifyHook( pCmd );

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

Remarks

To display the list of available toolbars, right-click a toolbar in the DraftSight user interface and select Toolbars to open the Specify Toolbars dialog.

 

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:   InsertToolbarItem Method (IToolbar)
*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) 2019 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.