CreateUserCommand Method (IApplication)

CreateUserCommand Method (IApplication) | Send Feedback
See Also Example

Cmd[out]
  User command

ApiUuid

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

UserCmdName

  Command name for the menu item or the toolbar button's ToolTip (see Remarks)

CmdString

  Command string (see Remarks)

Description

  Description of the command

SmallIcon
  Path image's file name for the command's small icon (see Remarks)

LargeIcon
  Path and image's file name for the command's large icon (see Remarks)

UiState

  Where to add the user command as defined in dsUIState_e

Error[out]

  Status of creating the command as defined in dsCreateCommandError_e

Creates a command for a menu item and toolbar.

# Syntax

Visual Basic |
--- | ---
    Function CreateUserCommand( _
       ByVal ApiUuid As System.String, _
       ByVal UserCmdName As System.String, _
       ByVal CmdString As System.String, _
       ByVal Description As System.String, _
       ByVal SmallIcon As System.String, _
       ByVal LargeIcon As System.String, _
       ByVal UiState As dsUIState_e, _
       ByRef Error As dsCreateCommandError_e _
    ) As UserCommand

C# |
--- | ---
    UserCommand CreateUserCommand(
       System.string ApiUuid,
       System.string UserCmdName,
       System.string CmdString,
       System.string Description,
       System.string SmallIcon,
       System.string LargeIcon,
       dsUIState_e UiState,
       out dsCreateCommandError_e Error
    )

JavaScript |
--- | ---
    CreateUserCommand(
       ApiUuid : String,
       UserCmdName : String,
       CmdString : String,
       Description : String,
       SmallIcon : String,
       LargeIcon : String,
       UiState : String
    ) : {
       Error : String,
       Cmd : dsUserCommand
    }

COM native C++ |
--- | ---
    HRESULT CreateUserCommand(
       BSTR ApiUuid,
       BSTR UserCmdName,
       BSTR CmdString,
       BSTR Description,
       BSTR SmallIcon,
       BSTR LargeIcon,
       dsUIState_e UiState,
       dsCreateCommandError_e* Error,
       IUserCommand** Cmd
    )

C++ |
--- | ---
    DSRESULT CreateUserCommand(
       const dsString& ApiUuid,
       const dsString& UserCmdName,
       const dsString& CmdString,
       const dsString& Description,
       const dsString& SmallIcon,
       const dsString& LargeIcon,
       dsUIState_e UiState,
       dsCreateCommandError_e* Error,
       dsUserCommand** Cmd
    )

#### Parameters

ApiUuid

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

UserCmdName

  Command name for the menu item or the toolbar button's ToolTip (see Remarks)

CmdString

  Command string (see Remarks)

Description

  Description of the command

SmallIcon
  Path image's file name for the command's small icon (see Remarks)
LargeIcon
  Path and image's file name for the command's large icon (see Remarks)
UiState

  Where to add the user command as defined in dsUIState_e

Error[out]

  Status of creating the command as defined in dsCreateCommandError_e

Cmd[out] or Return Value
  User command

# Example

The following code snippets show how to create a command for a menu item and toolbar:

- COM native C++ (from the DraftSight API COM native C++ template files DsAddinConnection.cpp and DsAddinUserCommand.cpp)
- C++ (from the DraftSight API C++ template file dsAddinConnection.cpp)

#### 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");

DsAddinUserCommand.cpp

DsAddinUserCommand::DsAddinUserCommand( _bstr_t ApiUuid, _bstr_t UserCmdName, _bstr_t CmdString, _bstr_t Description, _bstr_t SmallIcon, _bstr_t LargeIcon )

{

CDsAddinConnection *dsConnection = getMyApp();

dsCreateCommandError_e commandErr;

> // User command dependent on pre-defined command

ICommand* pCommand = dsConnection->m_DsApp->CreateCommand( ApiUuid, UserCmdName, &commandErr );

m_DsUserCommand = dsConnection->m_DsApp->CreateUserCommand( ApiUuid, UserCmdName, CmdString, Description, SmallIcon, LargeIcon, &commandErr );

DsAddinCommand *dsAddCom = new DsAddinCommand(pCommand);

}

#### 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;

// User command dependent on pre-defined command

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 );

Back to top

# Example

Create Context-sensitive Menu Items (C#)
Create Context-sensitive Menu Items (VB.NET)
Create Context-sensitive Menu Items (VBA)

# Remarks

If UserCmdName already exists, then dsCreateCommand_e.dsCreateCommandError_CommandNameExisted is returned for Error.

Specify the same string for UserCmdName as specified for IApplication::CreateCommand's CmdName parameter; e.g.; apiCmd.

The string to specify for CmdString is the same string specified for UserCmdName prefaced by ^C^C; e.g., ^C^CapiCmd.

To see a list of existing commands:

1. Right-click a toolbar in the user interface.
2. Select Customize Interface.
3. Click Commands on the left side of the dialog.
4. Use the scroll bar to see the list of existing commands.
5. To quickly locate a command that you've added:
   1. Type the name of the command in Find.
   2. Click the name of the command in the Name column.
   3. Examine the information at the bottom of the dialog.

The recommended size for:

- SmallIcon is 16 x 16
- LargeIcon is 24 x 24.

The supported format for both images is .png (Portable Network Graphics bitmap image).

# See Also

####

IApplication Interface
IApplication Members
IApplication::AbortRunningCommand Method
IApplication::GetRunningCommand Method
IApplication::RunCommand Method
IApplication::RunScript Method
IMenuItem::InsertMenuItem Method
IToolbar::InsertToolbarItem Method
IInterfaceFiles::CustomIconPath Property ()

# Availability

DraftSight V1R1