Overwrite in batchmesh
Hello everyone,
is it possible to include a syntax in the batch mesh script which defines that the newly created fe output should replace or overwrite the existing fe output in the same name? For instance, if the existing file is named as 'dyna.key', then I make some changes to the geometry and mesh it again, it should not be saved as dyna_1.key (which is now) but should overwrite the existing dyna.key every time.
the script looks like
-nogui -cad_translator step -cad_model_file E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1\Schweller.stp -criteria_file C:\FK-Programme\Altair\hm\batchmesh\crash_5mm.criteria -param_file C:\FK-Programme\Altair\hm\batchmesh\crash_5mm.param -user_procedure POST_BATCHMESH C:\FK-Programme\Altair\hm\batchmesh\ExportMesh.tcl exportmesh 'dyna' -work_dir E:\Datei\Results\Optimization\LS_OPT_results\Optimization_model_1
Thank you. any suggestion will be greatly appreciated.
Answers
-
Hello all,
I am new to this forum and seeing that I didn't get any help on this particular thread, I am wondering if I am not proposing this question in the proper way or I am not following the rules? I fi didn't, I apologise and would be really great if any of you could help me deal with this problem?
Thank you very much.
0 -
Hi
Sorry for late reply /emoticons/default_rolleyes.gif' title=':rolleyes:' />
the name is controlled by ExportMesh.tcl, I think so
Please show us its content first
0 -
Hello,
Thank you very much for your feedback. I greatly appreciate it. I have attached the export mesh.tcl file in this part of the thread for your kind reference. I would want the script to overwrite the existing mesh file with the newly created mesh file.
Thank you very much again and looking forward to hear from you.
0 -
# export model
set modelName 'mesh';
if {[llength $args]>0} {
set modelName [lindex $args 0];
}
if {[catch {set Relocate $::env(RELOCATE_TO_INPUT)} str_errMsg] > 0} {
set Relocate 0;
}
set postfix '';
set postfixIdx 2;
while {[file exists ${modelName}${postfix}.${extension}] != 0 } {
set postfix '_$postfixIdx';
incr postfixIdx;
}
*feoutputwithdata '$template' ${modelName}${postfix}.${extension} 0 0 1 1 0
if {$Relocate == 1} {
if {[catch {set InpDir [file dirname $::hmbm::gVarArray(modelpath)] } str_errMsg] == 0} {
if {$InpDir != '' && [file exists '$InpDir']} {
set opostfix '';
set postfixIdx 2;
while {[file exists ${InpDir}/${modelName}${opostfix}.${extension}] != 0 } {
set opostfix '_$postfixIdx';
incr postfixIdx;
}
catch [file rename -force -- ${modelName}${postfix}.${extension} ${InpDir}/${modelName}${opostfix}.${extension}]
}
}
}
}
This is how the 'export mesh' script for exporting the mesh looks like. should I change any variable in this to make the script overwrite the existing FE output in the same directory?thank you
0 -
Altair Forum User said:
Hi, add below red codes:
# export model
set modelName 'mesh';
if {[llength $args]>0} {
set modelName [lindex $args 0];
}
if {[catch {set Relocate $::env(RELOCATE_TO_INPUT)} str_errMsg] > 0} {
set Relocate 0;
}
set postfix '';
set postfixIdx 2;
while {[file exists ${modelName}${postfix}.${extension}] != 0 } {
set postfix '_$postfixIdx';
incr postfixIdx;
}
*feoutputwithdata '$template' ${modelName}${postfix}.${extension} 0 0 1 1 0set FileName ${modelName}${postfix}.${extension}
if {$Relocate == 1} {
if {[catch {set InpDir [file dirname $::hmbm::gVarArray(modelpath)] } str_errMsg] == 0} {
if {$InpDir != '' && [file exists '$InpDir']} {
set opostfix '';
set postfixIdx 2;
while {[file exists ${InpDir}/${modelName}${opostfix}.${extension}] != 0 } {
set opostfix '_$postfixIdx';
incr postfixIdx;
}
catch [file rename -force -- ${modelName}${postfix}.${extension} ${InpDir}/${modelName}${opostfix}.${extension}]set FileName ${InpDir}/${modelName}${opostfix}.${extension}
}
}
}set FileName [file normalize $FileName]
set OFileName [file join [file dirname $FileName] $modelName].$extension
if {[file exists $OFileName]} {
file delete -force $OFileName
}
file rename -force $FileName $OFileName
}
This is how the 'export mesh' script for exporting the mesh looks like. should I change any variable in this to make the script overwrite the existing FE output in the same directory?thank you
0 -
hello Tinh,
Thank you very much for the script. I had adapted those changes to the existing script. it still won't overwrite the existing .key file but create new one like dyna_1.key, dyna_2.key and so on. I have attached the Exportmesh.tcl script which I used after adding the changes you mentioned in your previous reply. I have also attached 'new 1.txt' file which I used in the command line from windows. Could you please check it once and help me with how to fix the problem? thank you again
0 -
in txt file you have to refer to ExportMesh-2.tcl !
0 -
Hello Tinh,
The files are the same. sorry. since I had downloaded the file two times from the other mailbox, the second one was renamed as export mesh-2.tcl. I did not notice and it was a honest mistake. But in reality, the export mesh-2.tcl is changed only by the name but the content is the same. I sincerely apologise for the mistake.
Thank you.
0 -
maybe you have something wrong because the tcl file will not output dyna_1.key
just dyna.key , dyna_2.key, dyna_3...
anyway I think it has error.
could you try replacing all content of ExportMesh.tcl by these code and rerun:
set modelName 'mesh';
if {[llength $args]>0} {
set modelName [lindex $args 0];
}set postfix '';
hm_answernext yes
*feoutputwithdata '$template' ${modelName}${postfix}.${extension} 0 0 1 1 0
0 -
hello Tinh,
I tried your suggestion from command line. However I got an error ' Error:Sourcing: .......(directory of export mesh.tcl) - can't read 'args': no such variable. I have attached the Exportmesh.tcl which I used in this thread.
Thank you very much.
0 -
Hmm, you did not tell me that the ExportMesh.tcl is your own file, not hypermesh file.
So you looked for export file for dyna template, and you didn't find?, then you build it your self with reference to optistruct file?
0 -
Hi Samraj
in exportmesh.tcl file , you must have a proc name 'exportmesh' , because batchmesher will invoke it (as indicated in your txt file), and args is its arguments, and first argument will be name of output file dyna.k
Try again with below ExportMesh.tcl
proc exportmesh args { set modelName lsdyna_mesh if {[llength $args]} { set modelName [lindex $args 0] } set template_dir [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] set template [file join $template_dir feoutput ls-dyna971 dyna.key] hm_answernext yes *feoutputwithdata $template $modelName.k 0 0 1 1 0 }
0 -
Altair Forum User said:
Hmm, you did not tell me that the ExportMesh.tcl is your own file, not hypermesh file.
So you looked for export file for dyna template, and you didn't find?, then you build it your self with reference to optistruct file?
Yes, you are correct. I had to seek altair support in order to write the Exportmesh.tcl file that would suit for my case.
0 -
Altair Forum User said:
Hi Samraj
in exportmesh.tcl file , you must have a proc name 'exportmesh' , because batchmesher will invoke it (as indicated in your txt file), and args is its arguments, and first argument will be name of output file dyna.k
Try again with below ExportMesh.tcl
proc exportmesh args { set modelName lsdyna_mesh if {[llength $args]} { set modelName [lindex $args 0] } set template_dir [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] set template [file join $template_dir feoutput ls-dyna971 dyna.key] hm_answernext yes *feoutputwithdata $template $modelName.k 0 0 1 1 0 }
Hello Tinh,
The last line *feoutput.... $modelName.k or is it supposed to be $modelName.key?
Thank you very much
0 -
Hello Tinh,
The script works but only to an extent where only .hm file is produced as an output but not in .key format. ?
the command line as follows 'hm_ batchmesh.bat' -nogui - cad data 'critical' 'param' 'user_proce 'export mesh.tcl exportmesh 'dyna'' -work_dir
Thank you very much.
0 -
Hello Samraj
please change $modelName.k to $modelName.key and try again
0 -
Altair Forum User said:
Hello Tinh,
The script works but only to an extent where only .hm file is produced as an output but not in .key format. ?
the command line as follows 'hm_ batchmesh.bat' -nogui - cad data 'critical' 'param' 'user_proce 'export mesh.tcl exportmesh 'dyna'' -work_dir
Thank you very much.
I am not sure about command line but please try with command as in your txt file that you shown
where does the above command come from? your own writing?
0 -
Hello Tinh,
1. I tried with .key modification. it creates a hm file but not a .key file. I have attached the .bat file which I used from the command line (windows).
2. The batch file which I used to invoke HM from command file is in .txt file here in the attachments because I couldn't email to other inbox as .bat file. but the contents are same. I created the contents of batch script file based on the tutorial help from batch mesh ----> start up batch mesh under HM tutorial.
3. I have also attached the ExportMesh.tcl file which I used for this problem.
Thank you very much
0 -
Hello Samraj,
your ExportMesh.tcl is missing a ']' at the end of line:
set template [file join $template_dir feoutput ls-dyna971 dyna.key]
So hm was failed to export the mesh
Try again and confirm any error in file 'OUTPUT' (open it by notepad), it should indicate 'HM exiting with code 0' - means no error
0 -
Hello Tinh,
Thank you for your feedback. i tried with the correction. But it didnt export the mesh as.key file but only as .hm file. So the suggestion didnt work, unfortunately. is there any other way to address this problem?
Thank you.
0 -
i tested it in my computer and it worked
so just a reason that you did not do it as my guide, please understand and do it step by step carefully.
send me file OUTPUT
0 -
Hello Tinh,
Thank you and apologies for the late reply. was away. okay. I think I am just confused by which are the contents I should have and which I should delete from the original .tcl file from the beginning of this thread :-( .
so, in the export mesh.tcl file, you only have following code, right?
proc exportmesh args { set modelName lsdyna_mesh if {[llength $args]} { set modelName [lindex $args 0] } set template_dir [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] set template [file join $template_dir feoutput ls-dyna971 dyna.key] hm_answernext yes *feoutputwithdata $template $modelName.key 0 0 1 1 0 }
then in the batch script file (command line), its must to add -user_proc post batchmesh ' directory of exportmesh.tcl' exportmesh 'dyna' ?
Thank you and looking forward to hear from you.
0 -
Yes, that's right.
try it and send me file 'OUTPUT'
0 -
Hello Tinh,
Sincere apologies for late reply. I checked the code again and realised I made some mistakes where the model directory was mentioned. the code now works very well. thanks very much .
Regards,
Sam
0 -
Hello Tinh,
Is it possible to add the function to the script where it prints 'normal termination' message every time this script is run? Because, its expected of to print such a message when coupled with LS-Opt. I couldn't figure out how to include such functionality to the script which was discussed in this thread. Could you please help me with it?
thank you very much
Regards,
Sam
0 -
after command *feoutput... of proc ExportMesh, add a command:
return 'normal termination'
0 -
Hello Tinh,
Thank you very much. your suggestion works.
Regards,
Sam
0 -
Hello Tinh,
I used the following script to invoke the batchmesher from Windows command line. The batchmesher GUI opens but i dont see any .key file being produced. Could you please hlep me with it? Am i missing any syntax which you think might be causing the problems?
from the command line, the input looks like
'C:\FK-Programme\Altair\hm\batchmesh\hw_batchmesh.bat' 'E:\Datei\Results\Optimization\Schweller_Optimization\hm_batch.bat'
where as hw_batchmesh.bat file is default which i didnt make any changes to, Under the hm_batch.bat file the input looks like
set MODEL_DIR=E:\Datei\Results\Optimization\Schweller_Optimization -nogui -cad_translator step -cad_model_file E:\Datei\Results\Optimization\Schweller_Optimization\Schweller.stp -criteria_file C:\FK-Programme\Altair\hm\batchmesh\crash_5mm.criteria -param_file C:\FK-Programme\Altair\hm\batchmesh\crash_5mm.param -user_procedure POST_BATCHMESH C:\FK-Programme\Altair\hm\batchmesh\exportdynamesh.tcl exportmesh 'dyna' -work_dir E:\Datei\Results\Optimization\Schweller_Optimization
Exportdynamesh.tcl file looks like
proc exportmesh args { set modelName lsdyna_mesh if {[llength $args]} { set modelName [lindex $args 0] } set template_dir [hm_info -appinfo SPECIFIEDPATH TEMPLATES_DIR] set template [file join $template_dir feoutput ls-dyna971 dyna.key] hm_answernext yes *feoutputwithdata $template $modelName.key 0 0 1 1 0 return 'normal termination'
}Thank you very much,
0 -
Hi Samraj
wrong usage of .bat
cannot bind args from a .bat to other
put command and args in 1 .bat and call that bat from cmd prompt
0 -
Hello Tinh,
Thank you very much. I couldn't get around any idea how to add all the aforementioned arguments (in my previous thread) in one .bat file? can I simply put them together and save as .bat file ? i.e. values from the default 'hw_batchmesh.bat' and the rest of the contents from hm_batch.bat?
Thank you
0