Run Command on Open for HyperView

Blake Berk
Blake Berk Altair Community Member
edited April 2022 in Community Q&A

Hi,

Looking for a way to run a command on open in HyperView, just like I can run hmcustom.tcl in HyperMesh to set some defaults and prep macros. Any ideas?

Thanks,

Blake

Best Answer

  • PaulAltair
    PaulAltair
    Altair Employee
    edited April 2022 Answer ✓

    Hi Paul,

    The last thing you said is what I am interested in - creating a "permanent" button to run a macro. Do you know how to add that to the preference file? When I save a standard .mvw with the button added, it does not add it to the .mvw 'code.'

    Thanks for your time so far! Let me know if you have code to assist the creation of a button or tool bar addition.

    Best,

    Blake

    Ok, I created a generic annotated preferences file for you (attached) with a few of the alternatives for menus/buttons, depending on what your tcl is doing, one of these may be more appropriate than the others, you ought to be able to hack it to do what you want (edit the tcl references, remove anything you don't need), it includes menu options for both hyperview and hypergraph, It is possible to make submenus etc if needed, this is just a simple example.

    To use it, download it, put it somewhere sensible (e.g. create an 'AltairPrefs' Folder somewhere)

    Then in hyperview/graph, go to load --> Preference File

    image

     

    Click 'Register' and browse to the mvw you saved, and 'open' it

    image

     

    It should then appear in the list of preferences, you can pick it and click 'Load', this should be 'sticky' i.e. the selected prefs file is loaded by default on every HV/HG launch.

    image

     

    It will mostly work straight away, but at this point, to make sure, it is worth closing/reopening HV/HG

     

    In HyperView Client, you should now have a menu dropdown called 'MyMacro' with a single entry (points to a tool built into the installation)

    image

     

    And in HyperGraph Client a similar dropdown, this time with 2 entries, one for the same tool, one for a shortcut to a filter macro

    image

     

    also in Hypergraph, there should be 2 other menus

    A 'My Macro' Menu on right clicking a curve in the browser (performs tasks on that curve)

    image

     

     

    And a 'My Macro' Menu on right clicking a curve in the graphics area (performs tasks on that curve)

    image

     

     

    You can edit this, unregister/register it, load it, as many times as you need to, it is worth doing a close/open on HV/HG to check it too, and see what you get, if you break things don't worry, you can just 'load' the default settings back again and try something else.

    Good luck!

    if you have a play with this and can't get it doing what you want, get back to me!

Answers

  • PaulAltair
    PaulAltair
    Altair Employee
    edited April 2022

    You can create, register and load a preference file

    imageimage

    Preference Files in Help

    Below is mine for example:

    // HWVERSION_HW11.0.120-HWDesktop_Mar 5 2012_10:15:53  // Preference file for Altair HyperWorks // Please use "Set Preferences File..."  // under the File menu for specifying this customized preferences file.  *Id("HyperWorks v8.0")  {mvp_toolbar_dir = "D:/AltairTemp/Macros/MVP_Toolbar";include(mvp_toolbar_dir + "/preferences_macro.mvw")} {include("D:/AltairWin64/HW2021.2/hwdesktop/utility/VehicleSafetyTools/mv_hv_hg/vst.mvw")} {include("D:/AltairTemp/Macros/VPI_Calc/VPI_Calc_V1.0.mvw")} {include("D:/AltairTemp/Macros/SpragueAndGeers/Sprague-Geers.mvw")}      *BeginGraphicDefaults() 		*BeginContextMenu(viewFlip, "Flip View") 			*ContextMenuItem(viewFlip,"Flip Horizontal","D:/AltairTemp/MACROS/FlipHorizVert/flipViewHorVer.tcl",::cMenu::flipHorizontal, animation) 			*ContextMenuItem(viewFlip,"Flip Vertical","D:/AltairTemp/MACROS/FlipHorizVert/flipViewHorVer.tcl",::cMenu::flipVertical, animation) 		*EndContextMenu()                     *NoteForeGroundColor("Black")                     *DefaultPostContourLegendFile ("D:/AltairTemp/MACROS/Legend/LegendPref2017.tcl")                     //*SetOrientation(Top)                     //*SetBackgroundColor(0)                     //*Part(Default, On, IdOn, 12, Opaque, Shaded, NoTrace)     *EndGraphicDefaults()  *Id("HyperWorks", "11.*")  //*BeginAnimator(Static) //    *CurrentPosition(0) //   *NumberOfSteps(100) //    *Increment(Forward, Frame, 1, BounceOn) //*EndAnimator()  *BeginDefaults()   *BeginPlotDefaults()      *SetPreloadMaximum(1000000000)   *EndPlotDefaults() *EndDefaults()  //*EndGraphicDefaults()  *BeginPlot3DDefaults()      *SetPreloadMaximum(1000000000) *EndPlot3DDefaults()

     

  • Blake Berk
    Blake Berk Altair Community Member
    edited April 2022

    Hi Paul,

    This looks great! Appreciate the support.

    Do you know how to execute a TCL function directly from this preference file? I am looking to run a macro I have already created. This preference file looks like another syntax to learn (with limited documentation?) and I already have quite a few lines of code associated with the TCL function!

    Thanks,

    Blake

  • PaulAltair
    PaulAltair
    Altair Employee
    edited April 2022

    Hi Paul,

    This looks great! Appreciate the support.

    Do you know how to execute a TCL function directly from this preference file? I am looking to run a macro I have already created. This preference file looks like another syntax to learn (with limited documentation?) and I already have quite a few lines of code associated with the TCL function!

    Thanks,

    Blake

    What task are you trying to do on start up? What are you trying to do with the TCL? If the tcl is performing something on a model then the model would need to be loaded first? i.e. is this an automated post processing task? in that case it might be better executed with a report template?

    If you can describe your end goal then there might be a better way of getting there!

    The Preferences mvw can pre-load your macros and put them into menus for you so they are ready to use e.g. below from the MVP toolbar but it can't run them on its own, it is a 'settings' loader effectively.

    image 

  • Blake Berk
    Blake Berk Altair Community Member
    edited April 2022

    What task are you trying to do on start up? What are you trying to do with the TCL? If the tcl is performing something on a model then the model would need to be loaded first? i.e. is this an automated post processing task? in that case it might be better executed with a report template?

    If you can describe your end goal then there might be a better way of getting there!

    The Preferences mvw can pre-load your macros and put them into menus for you so they are ready to use e.g. below from the MVP toolbar but it can't run them on its own, it is a 'settings' loader effectively.

    image 

    Hi Paul,

    The last thing you said is what I am interested in - creating a "permanent" button to run a macro. Do you know how to add that to the preference file? When I save a standard .mvw with the button added, it does not add it to the .mvw 'code.'

    Thanks for your time so far! Let me know if you have code to assist the creation of a button or tool bar addition.

    Best,

    Blake

  • PaulAltair
    PaulAltair
    Altair Employee
    edited April 2022 Answer ✓

    Hi Paul,

    The last thing you said is what I am interested in - creating a "permanent" button to run a macro. Do you know how to add that to the preference file? When I save a standard .mvw with the button added, it does not add it to the .mvw 'code.'

    Thanks for your time so far! Let me know if you have code to assist the creation of a button or tool bar addition.

    Best,

    Blake

    Ok, I created a generic annotated preferences file for you (attached) with a few of the alternatives for menus/buttons, depending on what your tcl is doing, one of these may be more appropriate than the others, you ought to be able to hack it to do what you want (edit the tcl references, remove anything you don't need), it includes menu options for both hyperview and hypergraph, It is possible to make submenus etc if needed, this is just a simple example.

    To use it, download it, put it somewhere sensible (e.g. create an 'AltairPrefs' Folder somewhere)

    Then in hyperview/graph, go to load --> Preference File

    image

     

    Click 'Register' and browse to the mvw you saved, and 'open' it

    image

     

    It should then appear in the list of preferences, you can pick it and click 'Load', this should be 'sticky' i.e. the selected prefs file is loaded by default on every HV/HG launch.

    image

     

    It will mostly work straight away, but at this point, to make sure, it is worth closing/reopening HV/HG

     

    In HyperView Client, you should now have a menu dropdown called 'MyMacro' with a single entry (points to a tool built into the installation)

    image

     

    And in HyperGraph Client a similar dropdown, this time with 2 entries, one for the same tool, one for a shortcut to a filter macro

    image

     

    also in Hypergraph, there should be 2 other menus

    A 'My Macro' Menu on right clicking a curve in the browser (performs tasks on that curve)

    image

     

     

    And a 'My Macro' Menu on right clicking a curve in the graphics area (performs tasks on that curve)

    image

     

     

    You can edit this, unregister/register it, load it, as many times as you need to, it is worth doing a close/open on HV/HG to check it too, and see what you get, if you break things don't worry, you can just 'load' the default settings back again and try something else.

    Good luck!

    if you have a play with this and can't get it doing what you want, get back to me!

  • Blake Berk
    Blake Berk Altair Community Member
    edited April 2022

    Ok, I created a generic annotated preferences file for you (attached) with a few of the alternatives for menus/buttons, depending on what your tcl is doing, one of these may be more appropriate than the others, you ought to be able to hack it to do what you want (edit the tcl references, remove anything you don't need), it includes menu options for both hyperview and hypergraph, It is possible to make submenus etc if needed, this is just a simple example.

    To use it, download it, put it somewhere sensible (e.g. create an 'AltairPrefs' Folder somewhere)

    Then in hyperview/graph, go to load --> Preference File

    image

     

    Click 'Register' and browse to the mvw you saved, and 'open' it

    image

     

    It should then appear in the list of preferences, you can pick it and click 'Load', this should be 'sticky' i.e. the selected prefs file is loaded by default on every HV/HG launch.

    image

     

    It will mostly work straight away, but at this point, to make sure, it is worth closing/reopening HV/HG

     

    In HyperView Client, you should now have a menu dropdown called 'MyMacro' with a single entry (points to a tool built into the installation)

    image

     

    And in HyperGraph Client a similar dropdown, this time with 2 entries, one for the same tool, one for a shortcut to a filter macro

    image

     

    also in Hypergraph, there should be 2 other menus

    A 'My Macro' Menu on right clicking a curve in the browser (performs tasks on that curve)

    image

     

     

    And a 'My Macro' Menu on right clicking a curve in the graphics area (performs tasks on that curve)

    image

     

     

    You can edit this, unregister/register it, load it, as many times as you need to, it is worth doing a close/open on HV/HG to check it too, and see what you get, if you break things don't worry, you can just 'load' the default settings back again and try something else.

    Good luck!

    if you have a play with this and can't get it doing what you want, get back to me!

    Awesome! Thank you! This worked as desired!