Right-click context menu : could be customized?

QuyNguyenDai
QuyNguyenDai Altair Community Member
edited October 2020 in Community Q&A

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.

model_browser_context_menu.png.44700bd64ea36340a812eee6f5551e02.png

 

 

Thanks,

 

Tagged:

Welcome!

It looks like you're new here. Sign in or register to get started.

Answers

  • tinh
    tinh Altair Community Member
    edited October 2020

    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

    MenuExportDeck.png.fafa613841acc4ee9c1449d5579fc9b6.png

  • QuyNguyenDai
    QuyNguyenDai Altair Community Member
    edited September 2019

    Thanks Tinh!

  • tinh
    tinh Altair Community Member
    edited September 2019

    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 					} 				} 			} 		} 	} }

     

     

     

  • QuyNguyenDai
    QuyNguyenDai Altair Community Member
    edited September 2019

    Thanks!

  • Pandurang
    Pandurang Altair Community Member
    edited August 2020

    Hi how can i pop up this gui..

    ls-dyna profile

     

    Model Tab > Create > Cross Section

     

    /profile/3195-tinh/?do=hovercard' data-mentionid='3195' href='<___base_url___>/profile/3195-tinh/' rel=''>@tinh

  • Pandurang
    Pandurang Altair Community Member
    edited August 2020

    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

  • tinh
    tinh Altair Community Member
    edited August 2020

    Widget path may be changed. You should dump its binding command to use

  • Pandurang
    Pandurang Altair Community Member
    edited August 2020

    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

  • Pandurang
    Pandurang Altair Community Member
    edited August 2020

    [winfo children .model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain] invoke 'Cross Section'

     

    This one is working perfectly...

     

    Am i right? /profile/3195-tinh/?do=hovercard' data-mentionid='3195' href='<___base_url___>/profile/3195-tinh/' rel=''>@tinh

     

    Regards,

    PD

  • tinh
    tinh Altair Community Member
    edited August 2020

    [winfo children .model._pw._fbr.content.frmTreeArea.frmTree.__treectrl.popupMenumain] invoke 'Cross Section'

     

    This one is working perfectly...

     

    Am i right? /profile/3195-tinh/?do=hovercard' data-mentionid='3195' href='<___base_url___>/profile/3195-tinh/' rel=''>@tinh

     

    Regards,

    PD

    Maybe.

    If it not working, then bind a script to <<MenuSelect>> to catch the menu widget path as my sample code.

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.