Managing contextual menus

GiD - The personal pre and post processor

Managing contextual menus



Managing contextual menus

Overview
GiD provides a public API to customize contextual menus without directly modifying internal global arrays. This page follows the same decorated structure as Managing menus, highlighting usage notes, Tcl commands, arguments, return values, and workflow.

Where to use it

  • In initialization procedures such as InitGIDProject or InitGIDPostProcess.

  • In callbacks that rebuild or refresh menus.

  • In batch updates: disable refresh, apply changes, then update once.

Important notes

  • Menu names are identified by untranslated English names.

  • Use PRE, POST, or PREPOST depending on scope.

  • MainContextualMenu supports PRE and POST; GraphContextualMenu is handled as a graph-specific context.

Note: Contextual menu names and option paths must match their untranslated English identifiers. GiD automatically manages menu rebuilds, but plugin entries should be re-applied when menus are refreshed.

Namespace

GiDContextualMenu

Update control

  • GiDContextualMenu::Update {{contextual_menu_name ""}}
    Applies pending changes.
    Allowed values:

    • any or empty string: updates both main and graph contextual menus

    • MainContextualMenu: updates only main contextual menu

    • GraphContextualMenu: updates only graph contextual menu

Core API

  • GiDContextualMenu::Create {contextual_menu_name menu_name_untranslated prepost {pos -1} {translationfunc _}}
    Creates a root menu entry in the target contextual menu.

  • GiDContextualMenu::Delete {contextual_menu_name menu_name_untranslated prepost {translationfunc _}}
    Deletes a root menu entry.

  • GiDContextualMenu::InsertOption {contextual_menu_name menu_name_untranslated option_name_untranslated position prepost command {acceler ""} {icon ""} {ins_repl "replace"} {translationfunc _}}
    Inserts or replaces an option in a contextual menu path.

  • GiDContextualMenu::RemoveOption {contextual_menu_name menu_name_untranslated option_name_untranslated prepost {translationfunc _}}
    Removes an option (or separator) from a contextual menu path.

  • GiDContextualMenu::ModifyOption {contextual_menu_name menu_name_untranslated option_name_untranslated prepost new_option_name {new_command -default-} {new_acceler -default-} {new_icon -default-} {translationfunc _}}
    Modifies label, command, accelerator, or icon.

  • GiDContextualMenu::GetOptionIndex {contextual_menu_name menu_name_untranslated option_name_untranslated prepost {translationfunc _}}
    Returns a 0-based index, or -1 if not found.


Example: creating a contextual menu entry

The following example remove in the main contextual menu in preprocess the entry named “Layer” and in post the entry named “Mesh” and applies all pending changes at the end:

GiDContextualMenu::RemoveOption MainContextualMenu "Layer" {} PRE GiDContextualMenu::RemoveOption MainContextualMenu "Mesh" {} POST GiDContextualMenu::Update MainContextualMenu

Argument reference

  • contextual_menu_name:
    MainContextualMenu or GraphContextualMenu

  • menu_name_untranslated:
    root menu name in untranslated English

  • option_name_untranslated:
    list path to suboptions, for example list "Create#C#menu" "Arc#C#menu"

  • position:
    0-based index or end

  • prepost:
    PRE, POST, PREPOST

  • ins_repl:
    replace, insert, insertafter

  • translationfunc:
    _ for GiD strings, = for module/problemtype strings

Return values

  • 0: success

  • 1: not found / not applied

  • error: invalid menu name or invalid arguments

Recommended workflow

  1. Create/insert/modify/remove entries.

  2. Call Update once.

 

COPYRIGHT © 2026 · GID · CIMNE