GUI for HyperMesh Script

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

Hello all,

 

When I need to have user interaction with a script I'm working on, usually I use Tk to create the user interface,

I was wondering if there's a way to generate a GUI similar to what we see for common HM functions, where all the steps and required information are displayed at the same time.

 

How can that be achieved?

 

Thanks,

Jefferson

Answers

  • tinh
    tinh Altair Community Member
    edited December 2018

    Could you show a screenshot what you have currently and what you want?

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    What I want is to have all the options and settings for the function being called to be selected and viewed all at once as any other HyperMesh function.

    For example, the Automesh function displays this dashboard when selected:

     

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

     

    For now what I have is based basically on yes or no questions using the tk_messageBox function and some functions like hm_getfloat and createmarkpanel to get user input. But I would like to have something more visual and easy for the user to navigate through the options and different selections the function can offer.

     

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

     

    Can that be done? Or how could this workflow be improved?

     

    Thanks,

    Jefferson

  • tinh
    tinh Altair Community Member
    edited December 2018

    Sure, that can.

    you need to make a window (using command 'toplevel'), or a frame (using command 'frame')

    create buttons (using command 'button'), entry box (using command 'entry'), other widgets like labels, menus, ...

    and then bring them into the toplevel window (using command 'pack', or 'grid', or 'place')

     

    many Tk commands help with building GUI you can refer here:

    https://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm

     

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    Great!!

    Thanks a lot tinh

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    Would you have any example or sample code where this type of GUI is implemented?

    It would be a good start for me.

     

    Thank you,

    Jefferson

  • tinh
    tinh Altair Community Member
    edited December 2018

    Hi

    Set w .wDemo

    Destroy $w

    Toplevel $w

    Wm transient $w .

    For {set i 1} {$i<5} {incr i} {

         Frame $w.f$i

         Label $w.f$i.lbl -text 'Input $i ='

         Entry $w.f$i.ent

         Pack $w.f$i.lbl -side left -anchor w

         Pack $w.f$i.ent -side right -anchor e

         Pack $w.f$i -side top -anchor nw -fill x

    }

    Button $w.b -text Proceed

    Pack $w.b -side top -anchor e

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    Thank you.

    But actually this is more like a floating box, a pop-up.

    Is there any way to build it in the HM interface just like the picture I showed before?

    With a pop-up it would work the same way, but I just wanted to know if that is possible so it would be easier for the user.

     

    Thanks,

    Jefferson

  • tinh
    tinh Altair Community Member
    edited December 2018

    Yes

    Same codes as above and add these lines:

    Wm forget $w

    Hm_framework addpanel $w 'My Panel'

    Hm_framework drawpanel 'My Panel'

     

  • RajeshSRSamsung
    RajeshSRSamsung Altair Community Member
    edited December 2018

    Hi

    Set w .wDemo

    Destroy $w

    Toplevel $w

    Wm transient $w .

    For {set i 1} {$i<5} {incr i} {

         Frame $w.f$i

         Label $w.f$i.lbl -text 'Input $i ='

         Entry $w.f$i.ent

         Pack $w.f$i.lbl -side left -anchor w

         Pack $w.f$i.ent -side right -anchor e

         Pack $w.f$i -side top -anchor nw -fill x

    }

    Button $w.b -text Proceed

    Pack $w.b -side top -anchor e

    Hello Tinh ,

    how i can i use the value of this 'Entry $w.f$i.ent' for making node coordinate in Hypermesh.

    Thanking You

  • tinh
    tinh Altair Community Member
    edited December 2018

    Hi

    Use

    Set X [$w.f$i.ent get]

  • RajeshSRSamsung
    RajeshSRSamsung Altair Community Member
    edited December 2018

    Hi

    Use

    Set X [$w.f$i.ent get]

    Thank You for your reply Mr. Tinh

    in  my tcl program i used a procedure for entry as shown below.

    #***********************************************************************************

    proc ::Execlug01LUG {args} {
    set w .lugType01
    destroy $w
    toplevel $w
    wm transient $w .    

      frame $w.f2
         #---------------------------------------
         label $w.f2.labL1 -text 'L1 ='
         entry $w.f2.entL1

         pack $w.f2.labL1 -side left -anchor w
         pack $w.f2.entL1 -padx 15 -pady 2 -side left

         label $w.f2.labL2 -text 'L2 ='
         entry $w.f2.entL2

         pack $w.f2.labL2 -side left -anchor w
         pack $w.f2.entL2 -padx 15 -pady 2 -side left
         pack $w.f2 -side top -anchor nw -fill x
         #---------------------------------------


    button $w.b -text Model -font {Helvetica -25 bold} -height 1 -width 10 -background gray75 -foreground blue -command {hm_setpanelproc ::modelclick}
    pack $w.b -side top -anchor nw -fill x

    }

    proc ::modelclick {args} {
    set l1 [$w.f2.entL1 get]
    set l2 [$w.f2.entL2 get]
    *createnode 0 0 0 0 0 0;
    *createnode l2 0 0 0 0 0;
    *createnode l2 l1 0 0 0 0;
    *createnode 0 l1 0 0 0 0;
    }

     

    #***********************************************************************************

     

    In this case i am not able to get the value of l1 and l2 to create the nodes. please help me

    Thank You

  • tinh
    tinh Altair Community Member
    edited December 2018

    You need this:

    set w .lugType01

  • RajeshSRSamsung
    RajeshSRSamsung Altair Community Member
    edited December 2018

    You need this:

    set w .lugType01

    Thank You for your reply Mr. Tinh

    but still getting error 'can't read 'w.lugType01': no such variable' when i run the following tcl file in hypermesh

    #***********************************************************************************

    proc ::Execlug01LUG {args} {
    set w .lugType01
    destroy $w
    toplevel $w
    wm transient $w .    

      frame $w.f2
         #---------------------------------------
         label $w.f2.labL1 -text 'L1 ='
         entry $w.f2.entL1

         pack $w.f2.labL1 -side left -anchor w
         pack $w.f2.entL1 -padx 15 -pady 2 -side left

         label $w.f2.labL2 -text 'L2 ='
         entry $w.f2.entL2

         pack $w.f2.labL2 -side left -anchor w
         pack $w.f2.entL2 -padx 15 -pady 2 -side left
         pack $w.f2 -side top -anchor nw -fill x
         #---------------------------------------


    button $w.b -text Model -font {Helvetica -25 bold} -height 1 -width 10 -background gray75 -foreground blue -command {hm_setpanelproc ::modelclick}
    pack $w.b -side top -anchor nw -fill x

    }

    proc ::modelclick {args} {

    set w.lugType01
    set l1 [$w.f2.entL1 get]
    set l2 [$w.f2.entL2 get]
    *createnode 0 0 0 0 0 0;
    *createnode l2 0 0 0 0 0;
    *createnode l2 l1 0 0 0 0;
    *createnode 0 l1 0 0 0 0;
    }

     

    #***********************************************************************************

     

  • tinh
    tinh Altair Community Member
    edited December 2018

    Lack a space

    Do your eyes have any problem? -_-/emoticons/default_sleep.png' srcset='/emoticons/sleep@2x.png 2x' title='-_-' width='20' />

  • RajeshSRSamsung
    RajeshSRSamsung Altair Community Member
    edited December 2018

    Thank you so much Mr. Tinh.. It worked~~~

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited December 2018

    Yes

    Same codes as above and add these lines:

    Wm forget $w

    Hm_framework addpanel $w 'My Panel'

    Hm_framework drawpanel 'My Panel'

     

    Hi tihn,

    With this addition I keep getting the following error:

     

     My Panel does not exist.                     while executing                                                                  'error '$frame does not exist.''                                                 ('drawpanel' arm line 11)                                         

    I'm sorry for so newbie question, but I'm struggling a little to work with GUI.

     

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    Ok, I just replaced 'My Panel' on the drawpanel line to $w and it worked fine.

     

    Now I'm trying to have in my GUI something like showed below to select entities:

    image.png.76ede4d5f8450ffaae9553bb426fe408.pngimage.png.1df34e603a1bb3754f244bdc1b797fbb.png

     

    How can this be achieved?

     

    Thank you

  • tinh
    tinh Altair Community Member
    edited January 2019

    Hi

    Use altair/.../hw/tcl/hw/collector/hwcollector.tcl

     

    Reference help:

    altair/.../hw/tcl/hw/collector/docs

     

     

    But it looks a bit difference from native hm collectors, can you override

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    Thanks for you answer tinh.

    However I'm not clear how this should be handled to use in one of my codes.

    Should I use exec to call the file or something else?

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    Thanks for you answer tinh.

    However I'm not clear how this should be handled to use in one of my codes.

    Should I use exec to call the file or something else?

     

    Hey @tinh, can you help me with that?

    Thank you.

  • tinh
    tinh Altair Community Member
    edited January 2019

    Hi

    Use 'source' command to load it

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    Good, that woks.

    Just not sure the format the callback must have.

    How should it be defined to retrieve elements or components?

  • tinh
    tinh Altair Community Member
    edited January 2019

    Read the html document in .../docs

    The callback is to process events

    When something happenning HM will call it with argument is event name

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    I've been playing around with this collector, but I still didn't get to do what I intend. Right now when I use HmMarkTool or HmEntSelCol I can only select the entities one by one, e.g. I cannot create a bounding box in the UI to select the entities inside the box. How can this be achieved?

     

    I also found this UI manager called Process Studio and I've been trying to make something work from that.

    If I add a collector from that and export a TCL code, I can see the script created to generate that collector, however I'm not being able to run it properly.

    So I have the following process on the script:

    ::hw::pmgr::${::hw::pmgr::namespace}::DisplayWnd

    ::hw::pmgr::${::hw::pmgr::namespace}::Exec

    ::hw::pmgr::${::hw::pmgr::namespace}::SetDataInDataModel

    ::hw::pmgr::${::hw::pmgr::namespace}::GetDataFromDataModel

    ::hw::pmgr::${::hw::pmgr::namespace}::OnDataModelChanged

     

    From that, what do I need to define in order to get this working?

    Also, what do I need to define in terms of 'hw::pmgr::namespace'?

     

    Thank you

  • tinh
    tinh Altair Community Member
    edited January 2019

    HmMarkTool is not useful, just to make example.

    use *createmarkpanel to activate graphic selection.

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    And is there a way to suppress this command to change the framework? (Because it takes the user to another 'page' when this command is called)

    Or just embed it within the Collector widget?

  • tinh
    tinh Altair Community Member
    edited January 2019

    I looked for that way too but cannot

  • Jeffersondhv
    Jeffersondhv Altair Community Member
    edited January 2019

    Ok, that's not too bad.

    Thanks for your help tinh!!!

  • tinh
    tinh Altair Community Member
    edited January 2019

    Actually I found a command to activate graphic selection in multiple mode: hmcollector

    But cannot retrieve selected entities by hm_getmark, even worse that it hanges from HM17, so the command seems to be developing...

     

    Cannot hide panel pops up by *createmarkpanel, it will activate 'function_lock' mode (prevents any panel posten onto it)

     

    Hope someone find a way.

    In hwcollector.tcl, it says user must develop the callback using some C headers not provided in hw installation!.