TCL/TK to import and export files

X2Murugesan, Arjun (A.)
X2Murugesan, Arjun (A.) Altair Community Member
edited October 2022 in Community Q&A

I have tried to automate the tetra creation and order change using tcl/tk for DOE study using hyperstudy. the script refers a location from which it works. i need to make the script dynamic such that it refers to the folder in which the tcl/tk is kept and should export it to the same folder. My Script:

set fullTemplate [file join [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] feoutput optistruct optistruct]
*templatefileset $fullTemplate
*feinputwithdata2 "\#optistruct\\optistruct" "C:/User/17/approaches/nom_1/run__00001/m_2/Model.fem" 0 0 0 0 0 1 10 1 0
*currentcollector components "mm2_mesh"
*createstringarray 2 "pars: upd_shell fix_comp_bdr aft" "tet: 99 1.2 2 0 0.5 0"
*createmark elems 2 "by comp id" 1; #select elements by comp (maybe by collector or comp name)
set elems_list [hm_getmark elems 1]; #store in a list
*tetmesh elements 2 1 elements 0 -1 1 2
#*clearmark elems 1
*createmark elems 3 "by comp id" 2; #select elements by comp (maybe by collector or comp name)
set elems_list [hm_getmark elems 3]; #store in a list
*orderchangetosecond 3 0 0
*startnotehistorystate {Assigned "shell" to component "Skin"}
*createmark components 1 "Skin"
*propertyupdate components 1 "shell"
*endnotehistorystate {Assigned "shell" to component "Skin"}
*createmark components 1
*clearmark components 1
*startnotehistorystate {Assigned "shell" to component "Skin"}
*feoutputwithdata "C:/Program Files/Altair/2017.4/templates/feoutput/optistruct/optistruct" "Model_run.fem" 1 0 0 1 1

kindly help me to update for the same. Thank you in advance

Tagged:

Answers

  • Ben Buchanan
    Ben Buchanan
    Altair Employee
    edited October 2022

    Hello,

    You can use the following line to get the script directory:

    set str_scrDir [file dir [info script]]

    Then use this throughout your code like so:

    set str_scrDir [file dir [info script]]
    set fullTemplate [file join [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] feoutput optistruct optistruct]
    *templatefileset $fullTemplate
    *feinputwithdata2 "\#optistruct\\optistruct" [file join $str_scrDir Model.fem] 0 0 0 0 0 1 10 1 0
    *currentcollector components "mm2_mesh"
    *createstringarray 2 "pars: upd_shell fix_comp_bdr aft" "tet: 99 1.2 2 0 0.5 0"
    *createmark elems 2 "by comp id" 1; #select elements by comp (maybe by collector or comp name)
    set elems_list [hm_getmark elems 1]; #store in a list
    *tetmesh elements 2 1 elements 0 -1 1 2
    #*clearmark elems 1
    *createmark elems 3 "by comp id" 2; #select elements by comp (maybe by collector or comp name)
    set elems_list [hm_getmark elems 3]; #store in a list
    *orderchangetosecond 3 0 0
    *startnotehistorystate {Assigned "shell" to component "Skin"}
    *createmark components 1 "Skin"
    *propertyupdate components 1 "shell"
    *endnotehistorystate {Assigned "shell" to component "Skin"}
    *createmark components 1
    *clearmark components 1
    *startnotehistorystate {Assigned "shell" to component "Skin"}
    *feoutputwithdata "str_scrDirt" "Model_run.fem" 1 0 0 1 1

    If you wanted the user to pick the import file you could use:

    set fname [hm_getfilename "Please select input file"]<br />set str_scrDir [file dir $fname]<br />

    https://2022.help.altair.com/2022.1/hwdesktop/hwd/topics/reference/hm/hm_getfilename.htm