How do I take input from the user about the type of element?

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

I am writing a script to hide to remove certain types of elements like rbe3s,rbe2s etc that are attached to a component.  But I want to ask the user the type of elements he wants to remove. Is there anyway I can take this input? 

Answers

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited August 2020

    The simple way is asking user to choice one element and you get element type from this selected element.

    So user has selected element type indirectly, via element.

     *createmarkpanel elems 1 'Select Element' set eList [hm_getmark elems 1] hm_markclear elems 1 set eid [lindex $eList 0] # we work only with the 1st element set typename [hm_getvalue elems id=$eid dataname=typename]  puts 'Element type= $typename'   # Do something with selected typename

     

  • Adriano A. Koga
    Adriano A. Koga
    Altair Employee
    edited August 2020

    You can have also the user to type a string with the element type name:

    set user_choice [hm_getstring 'buttom name' 'some string']

     

    Then do something.

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2020

    The simple way is asking user to choice one element and you get element type from this selected element.

    So user has selected element type indirectly, via element.

      *createmarkpanel elems 1 'Select Element' set eList [hm_getmark elems 1] hm_markclear elems 1 set eid [lindex $eList 0] # we work only with the 1st element set typename [hm_getvalue elems id=$eid dataname=typename]  puts 'Element type= $typename'   # Do something with selected typename

     

    thank you so much(thank you for your other answers in other threads as well)! I have another doubt, if i select multiple elements from the panel, in what order are they stored in the list.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited August 2020

    You can have also the user to type a string with the element type name:

    set user_choice [hm_getstring 'buttom name' 'some string']

     

    Then do something.

     

    Thank you!!

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited August 2020

    You can have also the user to type a string with the element type name:

    set user_choice [hm_getstring 'buttom name' 'some string']

     

    Then do something.

     

     

    When you get information from user, you have always some risk of wrong data. In this case, the risk is so high. Instead of enter 'quad4', user can entrer 'qua4'?

    The best way is to get all valid type name in Hypermesh and build a GUI script with this list of type name. User is asked just to select an item of list.

     

  • tinh
    tinh Altair Community Member
    edited August 2020

    Hi

    utilize hwtk 'selectlist' to build a GUI

     proc ::selectConfigs args { 	lassign $args btn sl 	if {$btn in {ok cancel}} { 		set listConfigs {} 		if {$btn == 'ok'} { 			foreach row [$sl selectionget] { 				lappend listConfigs [dict get [$sl rowcget $row -values] config] 			} 			append listConfigs ' ' 		} 		[winfo toplevel $sl] unpost 		set ::selectConfigs $listConfigs 	} else { 		set w .selConfigs 		destroy $w 		hwtk::dialog $w 		wm title $w 'Select Configs' 		#wm protocol $w ... => already set by hwtk 		set f [$w recess] 		set sl [hwtk::selectlist $f.sl -stripes 1 -selectmode multiple] 		pack $sl -fill both -expand 1 		$w hide apply 		$w buttonconfigure ok -command [list ::selectConfigs ok $sl] 		$w buttonconfigure cancel -command [list ::selectConfigs cancel $sl] 		$sl columnadd config -text Configs: 		foreach config $args { 			$sl rowadd row[incr i] -values [list config $config] 		} 		$w post 		set ::selectConfigs {} 		tkwait variable ::selectConfigs 		return $::selectConfigs 	} } #example: set MySelectedConfigs [selectConfigs rbe3 rigid rigidlink weld rod spring] puts 'Selected configs = $MySelectedConfigs'