Right-click context menu : could be customized?
Hi,
In Model browser, we have right-click context menu with several action on current collector.
Can we customize this menu? I would like to customize some action with my scripts.
Thanks,
Answers
-
Hi
I have an example here
I will give the code later because it is in my pc
https://community.altair.com/community?id=community_question&sys_id=e33648761b2bd0908017dc61ec4bcba7
0 -
Thanks Tinh!
0 -
Hi
Widget pathname of that menu is
.model._pw._fbr.content.frmTreeArea.frmTree._m
But from v14, it doesn't come in a static way (depends on what you click on) so if you add a menu item then it will be cleared before pop up.
To hook an item just before the menu pops up, thanks to Tk mechanism providing <<MenuSelect>> event. This is a way I used in menuexportdeck script:
proc ::nexpd::p_Initialize {} { set BindScript [bind Menu <<MenuSelect>>] if {![string match *::nexpd::p_HookMenu* $BindScript]} { bind Menu <<MenuSelect>> {+after idle [list ::nexpd::p_HookMenu %W]} } } proc ::nexpd::p_HookMenu {menuName} { if {![winfo exists $menuName]} return if {[string equal Menu [winfo class $menuName]]} { if {[string match .model*.frmTreeArea.frmTree.* $menuName]} { set menuParent [winfo parent $menuName] while {![string equal TreeCtrl [winfo class $menuParent]]} { set menuName $menuParent set menuParent [winfo parent $menuName] if {![string equal Menu [winfo class $menuName]]} return } set Hooked 0 set Count [$menuName index end] for {set i 0} {$i<=$Count} {incr i} { if {[lsearch -exact {cascade command} [$menuName type $i]]!=-1&&[string equal 'Export Deck' [$menuName entrycget $i -label]]} { set Hooked 1 break } } set Selection [$menuParent selection get] if {[llength $Selection]} { if {!$Hooked} { if {![winfo exists $menuName.exportdeck]} { menu $menuName.exportdeck -tearoff 0 -activebackground [$menuName cget -activebackground] \ -activeforeground [$menuName cget -activeforeground] \ -background [$menuName cget -background] \ -foreground [$menuName cget -foreground] $menuName.exportdeck add command -label 'Only Selected' -command [list ::nexpd::p_ExportSelection $menuParent $Selection 0] $menuName.exportdeck add command -label 'With References' -command [list ::nexpd::p_ExportSelection $menuParent $Selection 7] $menuName.exportdeck add command -label 'Save Geometry' -command [list ::nexpd::p_ExportSelection $menuParent $Selection -1] } $menuName insert 0 cascade -label 'Export Deck' -menu $menuName.exportdeck } else { if {[string equal disabled [$menuName entrycget 'Export Deck' -label]]} { $menuName entryconfigure 'Export Deck' -state normal } } } else { if {$Hooked} { if {![string equal disabled [$menuName entrycget 'Export Deck' -label]]} { $menuName entryconfigure 'Export Deck' -state disabled } } } } } }
0 -
Thanks!
0 -
Hi how can i pop up this gui..
ls-dyna profile
Model Tab > Create > Cross Section
0 -
Got it guys...
.model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain.popupMenuCreatechild_menu_cascade_16_child_menu invoke 11
.model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain.popupMenuCreatechild_menu_cascade_16_child_menu invoke 'Cross Section'
Thanks,
PD
0 -
Widget path may be changed. You should dump its binding command to use
0 -
I didnot get you...
can u give some example...
.model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain.popupMenuCreatechild_menu_cascade_16_child_menu invoke 'Cross Section'
here numerical value 16 changes every time...
Thanks,
PD
0 -
[winfo children .model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain] invoke 'Cross Section'
This one is working perfectly...
Regards,
PD
0 -
Altair Forum User said:
[winfo children .model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain] invoke 'Cross Section'
This one is working perfectly...
Regards,
PD
Maybe.
If it not working, then bind a script to <<MenuSelect>> to catch the menu widget path as my sample code.
0