My custom menu is not reloading when i change the profile?

Jouher_20929
Jouher_20929 Altair Community Member
edited March 18 in Community Q&A

My custom menu from hmcustom.tclis not reloading when i change the profile?

Which code should be added and where, how to add?

 

Also, tell me some materials or links where i can learn to customize hypermesh dropdown menu.

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi

    you have to register a callback:

    hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile

     

    then in body of the callback proc, you reload dropdown menus

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited April 2018

    Hi Tinh, I am new to framework. Please tell me where I have to put my code

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi Jouher,

    example in file c:/users/jouher/hmcustom.tcl 

    you put these codes:

    hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile

    proc ::p_CallbackAfterUserProfileChanged args {

         p_CreateDropdown Jouher

         #and other codes you want to run after changing profile

    }

    proc ::p_CreateDropdown Menu {

         set main  [. cget -menu]

         catch {menu $main.mnu$Menu -tearoff 0}

         $main add cascade -label $Menu -menu $main.mnu$Menu

         return $main.mnu$Menu

     }

    ::p_CreateDropdown Jouher

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited April 2018

    Hi Tinh, 

    Below is my code,

    ############

     set mypath 'C:/Users/MYNAME/myscripts';   set top_menu [hm_framework getpulldowns]  catch {$top_menu delete [.hmMainMenuBar index 'MyMenu']}  catch {destroy $top_menu.custom}   menu $top_menu.custom -tearoff 0  $top_menu insert 20 cascade -label 'MyMenu' -menu $top_menu.custom   set cat1 $top_menu.custom  $cat1 add cascade -label 'Category 1' -underline 0 -menu [menu $cat1.mnu1 -title 'Cat-1']  $cat1.mnu1 add command -label 'Script 1' -command 'source {$mypath/script1.tcl}' -underline 0  $cat1.mnu1 add command -label 'Script 2' -command 'source {$mypath/script2.tcl}' -underline 0   $top_menu.custom add separator   set cat2 $top_menu.custom  $cat2 add cascade -label 'Category 2' -underline 0 -menu [menu $cat2.mnu2 -title 'Cat-2']  $cat2.mnu2 add command -label 'Script 21' -command 'source {$mypath/script21.tcl}' -underline 0  $cat2.mnu2 add command -label 'Script 22' -command 'source {$mypath/script22.tcl}' -underline 0 

    ####################

     

    how should i add this in your command?

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi Jouher

    save your codes in a file example C:\Users\YourName\yourmenu.tcl

     

    and modify below proc in the hmcustom.tcl

    proc ::p_CallbackAfterUserProfileChanged args {

           source 'C:\Users\YourName\yourmenu.tcl'

    }

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited April 2018

    Hi Tinh, its throwing error. I want my code at start and after changing profile too.

  • tinh
    tinh Altair Community Member
    edited April 2018

    Sorry Jouher, it is due to \

    It (C:/Users/YourName/hmcustom.tcl file) should be

    proc ::p_CallbackAfterUserProfileChanged args {

           source 'C:/Users/YourName/yourmenu.tcl'

    }

    hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile

    ::p_CallbackAfterUserProfileChanged

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited April 2018

    i have done that.

    but still it show error after changing the profile as shown in figure.

     

    window name 'summary' already exists in parent
    window name 'summary' already exists in parent
        while executing
    'frame $f'
        (file 'C:/Users/Jouher/Desktop/Jouher_custom/hmcustom.tcl' line 13)

     

     

    There is a frame already in my file.

    See the above replies to see my code in file.

     

    see my code also.

     

    proc ::p_CallbackAfterUserProfileChanged args {

           source 'C:/Users/Jouher/Desktop/Jouher_custom/hmcustom.tcl'

    }

    hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile

    ::p_CallbackAfterUserProfileChanged

    <?xml version="1.0" encoding="UTF-8"?>image.png

  • tinh
    tinh Altair Community Member
    edited April 2018

    Hi Jouher,

    just add a destructor before command 'frame $f' , like this:

    destroy $f

    frame $f

  • Jouher_20929
    Jouher_20929 Altair Community Member
    edited April 2018

    Thanks Tinh, its working.

  • Jack LC_22402
    Jack LC_22402 Altair Community Member
    edited November 2020

    Hello tinh,

    I've a problem with custom menu in the HM release 2019. Now the custom menu is not reloading when I import a model, while your code works great with user profile change. I tried to find something in the manual "hm_framework registerproc" but without success.

    May you suggest me a code to reload custom menu when I import new models?

    Many thanks

    Jack LC

  • tinh
    tinh Altair Community Member
    edited November 2020

    Hi Jack,

    as I know, when we import a model, HM will not reset its menus.

    So your case looks strange. Could you take some photos?

    We can register a callback to reload menus after importing new models. But i suggest you first to close HM and delete files .../Documents/hmsettings.tcl; .../Documents/hmmenu.set; .../Documents/command.tcl

    then try again

  • Jack LC_22402
    Jack LC_22402 Altair Community Member
    edited November 2020

    Hi tinh,

    thanks tinh for your reply and your suggestions.

    To make a test, I created a simplified version of the custom menu. Then I did the following:

    1) Delete files hmmenu.set and command.tcl (hmsettings.tcl not present in my starting folder)

    2) Open HM, the menu is present

    image

    3) Import an abaqus model; as you can see in the picture below, the menu disappeared

    image

     

     

    The files I used are the following (I'm not an expert, I copied them from your posts):

    1) hmcustom.tcl

     

    proc ::p_CallbackAfterUserProfileChanged args {         source "C:/Disk_D/Dati/settings/HW/TestMenu.tcl"  }  hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile  ::p_CallbackAfterUserProfileChanged  hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_menudraw  ::p_CallbackAfterUserProfileChanged

    2) TestMenu.tcl

     

    # # Creation Menu in HM # set TopMenu [hm_framework getpulldowns]  catch {$TopMenu delete [.hmMainMenuBar index "TEST"]} catch {destroy $TopMenu.test}  menu $TopMenu.test -tearoff 0 $TopMenu insert 20 cascade -label "TEST" -menu $TopMenu.test   $TopMenu.test add separator

     

    Since my case is strange, maybe it is related to my HM version (2019.1)

     

    Best regards,

    Jack LC

  • tinh
    tinh Altair Community Member
    edited November 2020
    Hi I will check abaqus profile, it could register a proc to reset menus. It is not registered to profile-change event, so we will bind our callback to something else, there are several ways to bind a callback. Let's check it later because i don't have hypermesh at home :D
  • Jack LC_22402
    Jack LC_22402 Altair Community Member
    edited November 2020

    Hi,

    you are right, it seems related to the abaqus profile. I tried with the Optistruct profile and it works fine, no reset of the custom menu.

    Thanks,

    Jack LC

  • tinh
    tinh Altair Community Member
    edited November 2020

    Hi Jack,

    i found a registered proc is hooked to import command, so it (calls to) reset menus.

    in your hmcustom.tcl :

    proc ::p_AddUserMenus args { 	source "C:/Disk_D/Dati/settings/HW/TestMenu.tcl" } proc ::p_CallbackAfterUserProfileChanged args { 	#check if Abaqus profile is loaded: 	if {[string equal -nocase $args Abaqus]} { 		trace remove execution ::UserProfiles::Abaqus::UpdatePulldowns leave ::p_AddUserMenus 		trace add execution ::UserProfiles::Abaqus::UpdatePulldowns leave ::p_AddUserMenus 	} 	::p_AddUserMenus }  hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile  ::p_CallbackAfterUserProfileChanged

     

    do not register proc for event "after_menudraw", it may hang your hypermesh!

     

  • Jack LC_22402
    Jack LC_22402 Altair Community Member
    edited November 2020

    Hi tinh,

    wow, it works perfectly! Honestly, I don't understand how the lines "trace remove ..." and "trace add ..." can solve the issue, but it works.

     

    Many thanks for your valuable help!

    Jack LC

  • Ajay Prabhakaran
    Ajay Prabhakaran Altair Community Member
    edited March 18

    Hi tinh,

    Do you have any alternative way for registering a proc , as the method (

    hm_framework registerproc ::p_CallbackAfterUserProfileChanged after_userprofile

    ) wont work in Hyperworks X version with hm_framework. Do you have an alternative that will work for Hyperworks -X version?