This example includes the complete code for managing a macro.

The "My Macro" menu is built in the OnMenu function and added to the macro menu for graphic documents (DlxApp.MENU_DWG).

The OnMenuUpdateCommand function defines the status (enabled, disabled) of the commands.

The command is executed in the OnMenuCommand function. In the example, when the user selects the command in the menu, the command code is simply displayed in the report bar.

Example

  Copy codeCopy code
function OnMenu()
{
  var menuDwg = DlxApp.GetMenu(DlxApp.MENU_DWG);
  if (menuDwg.IsValid())
  {
    var myMenu = menuDwg.AddMenu("My Macro");
    myMenu.AddCommand("command10", 10, "Description of command 10\nCmd10");
    myMenu.AddCommand("command20", 20, "Description of command 20\nCmd20");
    myMenu.AddLabel("Label");
    myMenu.AddCommand("command30", 30, "Description of command 30\nCmd30");
    myMenu.AddCommand("command40", 40, "Description of command 40\nCmd40");
    myMenu.AddSeparator();
    myMenu.AddCommand("command50", 50, "Description of command 50\nCmd50");
    myMenu.AddCommand("command60", 60, "Description of command 60\nCmd60");
  }
}

function OnMenuUpdateCommand(cmd)
{
  switch (cmd.GetCommandId())
  {
  case 10:
    cmd.Enable(true);
    break;
  case 20:
    cmd.Enable(true);
    break;
  case 30:
    cmd.Enable(true);
    break;
  case 40:
    cmd.Enable(true);
    cmd.SetCheck(true);
    break;
  case 50:
   cmd.Enable(false);
    break;
  case 60:
    cmd.Enable(true);
    break;
  }
}

function OnMenuCommand(cmdId)
{
  switch (cmdId)
  {
    case 10:
      DlxApp.Printf("CmdId 10");
      break;
    case 20:
      DlxApp.Printf("CmdId 20");
      break;
    case 30:
      DlxApp.Printf("CmdId 30");
      break;
    case 40:
      DlxApp.Printf("CmdId 40");
      break;
    case 50:
      DlxApp.Printf("CmdId 50");
      break;
    case 60:
      DlxApp.Printf("CmdId 60");
      break;
  }
}

See also