🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

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

User: "Jouher_20929"
Altair Community Member
Updated by Jouher_20929

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.

Find more posts tagged with

Sort by:
1 - 18 of 181
    User: "tinh"
    Altair Community Member
    Updated by tinh

    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

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

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

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    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?

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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'

    }

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

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

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    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

    User: "tinh"
    Altair Community Member
    Updated by tinh

    Hi Jouher,

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

    destroy $f

    frame $f

    User: "Jouher_20929"
    Altair Community Member
    OP
    Updated by Jouher_20929

    Thanks Tinh, its working.

    User: "Jack LC_22402"
    Altair Community Member
    Updated by Jack LC_22402

    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

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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

    User: "Jack LC_22402"
    Altair Community Member
    Updated by Jack LC_22402

    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

    User: "tinh"
    Altair Community Member
    Updated by tinh
    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
    User: "Jack LC_22402"
    Altair Community Member
    Updated by Jack LC_22402

    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

    User: "tinh"
    Altair Community Member
    Updated by tinh

    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!

     

    User: "Jack LC_22402"
    Altair Community Member
    Updated by Jack LC_22402

    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

    User: "Ajay Prabhakaran"
    Altair Community Member
    Updated by Ajay Prabhakaran

    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?