Project - 2 - Generating the report for hypermesh file
*clearmarkall 1; *clearmarkall 2;
These commands clear any existing marks with IDs 1 and 2.
set file [open final_data.csv w]
This line opens a file named "final_data.csv" in write mode and assigns the file object to the variable file.
set a $env(USERNAME)
This line retrieves the value of the environment variable USERNAME and assigns it to the variable a.
puts $file "Username, $a"
This line writes the username (stored in the variable a) to the file.
puts $file "Date,[clock format [clock seconds] -format {%b.%d.%Y}]"
puts $file "Time,[clock format [clock seconds] -format {%I:%M:%S %p}]"
These two lines write the current date and time to the file in the specified format using the clock command.
set profile [hm_info templatetype]
This line retrieves the template type from the HyperMesh session and assigns it to the variable profile.
puts $file "User Profile,$profile"
This line writes the user profile (stored in the variable profile) to the file.
puts $file "No.of components, $comp_count"
puts $file "No.of elements, $elem_count"
puts $file "No.of Materials, $mat_count"
puts $file "No.of properties, $prop_count"
These lines write the counts of components, elements, materials, and properties to the file. The values of these counts are not provided in the code snippet and should be defined earlier in the script.
*EntityPreviewEmpty comps 1
set empty_comps [hm_getmark comps 1]
if {[hm_marklength comps 1] == 0} {
foreach i $empty_comps {
*setvalue comps id=$i color=#FF0000
}
}
set comp_empty [hm_marklength comps 1]
puts $file "No.of empty components,$comp_empty"
These lines mark and count the empty components. If there are no empty components (length of mark comps with ID 1 is 0), it skips the foreach loop. Otherwise, it iterates over each empty component ($empty_comps) and sets its color to red. Finally, it calculates the count of empty components and writes it to the file.
*EntityPreviewEmpty props 1
set empty_props [hm_getmark props 1]
if {[hm_marklength props 1] == 0} {
foreach j $empty_props {
*setvalue props id=$j color=#FF0000
}
}
set prop_unused [hm_marklength props 1]
puts $file "No.of unused properties,$prop_unused"
These lines mark and count the unused properties. If there are no unused properties (length of mark props with ID 1 is 0), it skips the foreach loop. Otherwise, it iterates over each unused property ($empty_props) and sets its color to red. Finally, it calculates the count of unused properties and writes it to the file.
*EntityPreviewEmpty mats 1
set empty_mats [hm_getmark mats 1]
if {[hm_marklength mats 1] == 0} {
foreach k $empty_mats {
*setvalue mats id=$k color=#FF0000
}
}
set mats_unused [hm_marklength mats 1]
puts $file "No.of unused Materials,$mats_unused"
These lines mark and count the unused materials. If there are no unused materials (length of mark mats with ID 1 is 0), it skips the foreach loop. Otherwise, it iterates over each unused material ($empty_mats) and sets its color to red. Finally, it calculates the count of unused materials and writes it to the file.
The remaining code follows a similar pattern of marking elements, performing tests, counting the failed elements, and writing the counts to the file for various criteria such as minimum length, maximum length, aspect ratio, warpage, quad angle, triangle angle, skewness, and Jacobian. Additionally, it also identifies and counts duplicate elements.
The code snippet ends with the following lines:
set comp_prop_name "Nil"
set comp_mat_name "Nil"
puts $file "Comp ID,Component Name,Property Assigned,Material Assigned"
foreach i $comp_ids {
set comp_name [hm_getvalue comps id=$i dataname=name]
set comp_prop_id [hm_getvalue comps id=$i dataname=property]
if {$comp_prop_id != 0} {
set comp_prop_name [hm_getvalue props id=$comp_prop_id dataname=name]
}
set comp_mat_id [hm_getvalue comps id=$i dataname=material]
if {$comp_mat_id != 0} {
set comp_mat_name [hm_getvalue mats id=$comp_mat_id dataname=name]
}
puts $file "$i,$comp_name,$comp_prop_name,$comp_mat_name"
}
These lines handle component properties and materials. It initializes two variables comp_prop_name and comp_mat_name with the value "Nil". Then, it writes a header line to the file for component information. Next, it iterates over each component ID ($comp_ids) and retrieves the component name, property ID, and material ID using HyperMesh commands. If a property or material is assigned to the component (IDs are non-zero), it retrieves their names. Finally, it writes the component ID, component name, property name, and material name to the file.
close $file
This line closes the file after all the data has been written.