Challenge

Project - 2 - Generating the report for hypermesh file

# -------------------------------------------------------------------------------------------
# Window creation
# -------------------------------------------------------------------------------------------

# Create a variable outside all "namespaces" to retrieve the username from the HM session

set username $tcl_platform(user)

# Create a window to input all desired quality values

namespace eval Buttons {

set a .window
catch {destroy a}
toplevel $a -class TopClass

# Define the title of the window, size and position
wm title $a "Master Macro"
wm geometry $a 850x380+500+250 ; update
wm resizable $a 0 0
wm deiconify $a

# Quality Checks

label $a.09 -text "2D Parameters" -bg skyblue2 -font {Arial 10 bold} ; place $a.09 -x 10 -y 10 -width 200 -height 20
label $a.10 -text "Quality Criteria" -bg skyblue2 -font {Arial 10 bold} ; place $a.10 -x 220 -y 10 -width 200 -height 20

label $a.12 -text "Minimum Length <" -bg skyblue2 -font {Arial 10 bold} ; place $a.12 -x 10 -y 40 -width 200 -height 20
entry $a.13 -textvariable Buttons::minl ; place $a.13 -x 220 -y 40 -width 200 -height 20

label $a.15 -text "Maximum Length >" -bg skyblue2 -font {Arial 10 bold} ; place $a.15 -x 10 -y 70 -width 200 -height 20
entry $a.16 -textvariable Buttons::maxl ; place $a.16 -x 220 -y 70 -width 200 -height 20

label $a.18 -text "Warpage >" -bg skyblue2 -font {Arial 10 bold} ; place $a.18 -x 10 -y 100 -width 200 -height 20
entry $a.19 -textvariable Buttons::warp ; place $a.19 -x 220 -y 100 -width 200 -height 20

label $a.21 -text "Aspect >" -bg skyblue2 -font {Arial 10 bold} ; place $a.21 -x 10 -y 130 -width 200 -height 20
entry $a.22 -textvariable Buttons::asp ; place $a.22 -x 220 -y 130 -width 200 -height 20

label $a.24 -text "Skew >" -bg skyblue2 -font {Arial 10 bold} ; place $a.24 -x 10 -y 160 -width 200 -height 20
entry $a.25 -textvariable Buttons::skewa ; place $a.25 -x 220 -y 160 -width 200 -height 20

label $a.27 -text "Jacobian <" -bg skyblue2 -font {Arial 10 bold} ; place $a.27 -x 10 -y 190 -width 200 -height 20
entry $a.28 -textvariable Buttons::jaco ; place $a.28 -x 220 -y 190 -width 200 -height 20

label $a.30 -text "Minimum Angle quad <" -bg skyblue2 -font {Arial 10 bold} ; place $a.30 -x 10 -y 220 -width 200 -height 20
entry $a.31 -textvariable Buttons::minaq ; place $a.31 -x 220 -y 220 -width 200 -height 20

label $a.33 -text "Max Angle Quad >" -bg skyblue2 -font {Arial 10 bold} ; place $a.33 -x 10 -y 250 -width 200 -height 20
entry $a.34 -textvariable Buttons::maxaq ; place $a.34 -x 220 -y 250 -width 200 -height 20

label $a.36 -text "Minimum Angle Tria <" -bg skyblue2 -font {Arial 10 bold} ; place $a.36 -x 10 -y 280 -width 200 -height 20
entry $a.37 -textvariable Buttons::minat ; place $a.37 -x 220 -y 280 -width 200 -height 20

label $a.39 -text "Maximum Angle Tria >" -bg skyblue2 -font {Arial 10 bold} ; place $a.39 -x 10 -y 310 -width 200 -height 20
entry $a.40 -textvariable Buttons::maxat ; place $a.40 -x 220 -y 310 -width 200 -height 20

# 3d buttons

label $a.41 -text "3D Parameters" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.41 -x 430 -y 10 -width 200 -height 20
label $a.42 -text "Quality Criteria" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.42 -x 640 -y 10 -width 200 -height 20

label $a.44 -text "Minimum Length <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.44 -x 430 -y 40 -width 200 -height 20
entry $a.45 -textvariable Buttons::minl3d ; place $a.45 -x 640 -y 40 -width 200 -height 20

label $a.47 -text "Maximum Length >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.47 -x 430 -y 70 -width 200 -height 20
entry $a.48 -textvariable Buttons::maxl3d ; place $a.48 -x 640 -y 70 -width 200 -height 20

label $a.50 -text "Warpage >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.50 -x 430 -y 100 -width 200 -height 20
entry $a.51 -textvariable Buttons::warp3d ; place $a.51 -x 640 -y 100 -width 200 -height 20

label $a.53 -text "Aspect >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.53 -x 430 -y 130 -width 200 -height 20
entry $a.54 -textvariable Buttons::asp3d ; place $a.54 -x 640 -y 130 -width 200 -height 20

label $a.56 -text "Skew >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.56 -x 430 -y 160 -width 200 -height 20
entry $a.57 -textvariable Buttons::skewa3d ; place $a.57 -x 640 -y 160 -width 200 -height 20

label $a.59 -text "Jacobian <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.59 -x 430 -y 190 -width 200 -height 20
entry $a.60 -textvariable Buttons::jaco3d ; place $a.60 -x 640 -y 190 -width 200 -height 20

label $a.62 -text "Minimum Angle Hexa <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.62 -x 430 -y 220 -width 200 -height 20
entry $a.63 -textvariable Buttons::minaq3d ; place $a.63 -x 640 -y 220 -width 200 -height 20

label $a.65 -text "Max Angle Hexa >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.65 -x 430 -y 250 -width 200 -height 20
entry $a.66 -textvariable Buttons::maxaq3d ; place $a.66 -x 640 -y 250 -width 200 -height 20

label $a.68 -text "Minimum Angle Penta <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.68 -x 430 -y 280 -width 200 -height 20
entry $a.69 -textvariable Buttons::minat3d ; place $a.69 -x 640 -y 280 -width 200 -height 20

label $a.71 -text "Maximum Angle Penta >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.71 -x 430 -y 310 -width 200 -height 20
entry $a.72 -textvariable Buttons::maxat3d ; place $a.72 -x 640 -y 310 -width 200 -height 20

# Create a button to run the report_master procedure

button $a.70 -text "Run Report" -bg "indian red" -font {Arial 10 bold} -command {report_master } ; place $a.70 -x 10 -y 340 -width 200 -height 20

}

# ----------------------------------------------------------------------------------------------------------
# Elements failed in quality aspects - 2D - Global procedures
# ----------------------------------------------------------------------------------------------------------

# Create a procedure for each 2D quality criteria, where variable "a" stores all failed elements,
# variable "d" stores all elements in the session, variable "allel2dlin" stores all linear 2D elements,
# variable "allel2dsec" stores all second order elements. Variables "x1", "x2" and "x3" store the length of
# variable "a", length of variable "d" and the sum of the length of variables "allel2dlin" and "allel2dsec",
# respectively. Lastly, the procedure prints in the target document a sentence stating how many elements
# failed, the ratio of failed elements vs total and the ratio of failed elements vs 2D elements (linear and second order).

proc minlength {minlength} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "all"
*elementtestlength elements 1 $minlength 2 1 2 0 "2D Length < "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_below_minimum_length_criteria_are [llength $a] ($minlength mm)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxlength {maxlength} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "all"
*elementtestlength elements 1 $maxlength 2 0 2 0 "2D Length > "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_below_minimum_length_criteria_are [llength $a] ($maxlength mm)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc warpage {warpangle} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestwarpage elements 1 $warpangle 2 2 0 "2D Warpage "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_above_maximum_warp_angle_tolerance_are [llength $a] ($warpangle deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc aspect {aspect} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestaspect elements 1 $aspect 2 2 0 "2D Aspect Ratio "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_above_the_aspect_ratio_tolerance_are [llength $a] ($aspect)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc skew {skewness} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestskew elements 1 $skewness 2 2 0 "2D skewness "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_above_skewness_tolerance_are [llength $a] ($skewness deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc jacobian {jacobiann} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $jacobiann 2 2 0 "Jacobian "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_below_the_jacobian_tolerance_are [llength $a] ($jacobiann)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc minanglequad {interangleminquad} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interangleminquad 0 2 1 2 0 "2D Quad min angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_below_the_minimum_angle_tolerance_(quads)_are [llength $a] ($interangleminquad deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxanglequad {interanglemaxquad} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxquad 0 2 0 2 0 "2D Quad max angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_above_the_maximum_angle_tolerance_(quads)_are [llength $a] ($interanglemaxquad deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc minangletria {interanglemintria} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemintria 1 2 1 2 0 "2D Tria min angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_below_the_minimum_angle_tolerance_(trias)_are [llength $a] ($interanglemintria deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxangletria {interanglemaxtria} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxtria 1 2 0 2 0 "2D Tria max angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel2dlin] + [llength $allel2dsec]}]]
puts $filechannelid "The_number_of_2D_elements_that_are_above_the_maximum_angle_tolerance_(trias)_are [llength $a] ($interanglemaxtria deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_2D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

# ----------------------------------------------------------------------------------------------------------
# Elements failed in quality aspects - 3D - Global procedures
# ----------------------------------------------------------------------------------------------------------

# Create a procedure for each 3D quality criteria, where variable "a" stores all failed elements,
# variable "d" stores all elements in the session, variable "allel3dlin" stores all linear 3D elements,
# variable "allel2dsec" stores all 3D second order elements. Variables "x1", "x2" and "x3" store the length of
# variable "a", length of variable "d" and the sum of the length of variables "allel2dlin" and "allel2dsec",
# respectively. Lastly, the procedure prints in the target document a sentence stating how many elements
# failed, the ratio of failed elements vs total and the ratio of failed elements vs 3D elements (linear and second order).

proc minlength3d {minlength} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestlength elements 1 $minlength 2 1 4 0 "3D Length < "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_below_minimum_length_criteria_are [llength $a] ($minlength mm)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxlength3d {maxlength} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestlength elements 1 $maxlength 2 0 4 0 "3D Length > "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_minimum_length_criteria_are [llength $a] ($maxlength mm)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc warpage3d {warpangle} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestwarpage elems 1 $warpangle 2 4 0 "3D Warpage "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_maximum_warp_angle_tolerance_are [llength $a] ($warpangle deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc aspect3d {aspect} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestaspect elems 1 $aspect 2 4 0 "3D Aspect Ratio "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_the_aspect_ratio_tolerance_are [llength $a] ($aspect)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc skew3d {skewness} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestskew elements 1 $skewness 2 4 0 "3D skewness "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_skewness_tolerance_are [llength $a] ($skewness deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc jacobian3d {jacobiann} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $jacobiann 2 4 0 "3D Jacobian "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_below_the_jacobian_tolerance_are [llength $a] ($jacobiann)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc minanglequad3d {interangleminquad} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interangleminquad 0 2 1 4 0 "3D Quad min angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_below_the_minimum_angle_tolerance_(hexas)_are [llength $a] ($interangleminquad deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxanglequad3d {interanglemaxquad} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxquad 0 2 0 4 0 "3D Quad max angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_the_maximum_angle_tolerance_(hexas)_are [llength $a] ($interanglemaxquad deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc minangletria3d {interanglemintria} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemintria 1 2 1 4 0 "3D Tria min angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_below_the_minimum_angle_tolerance_(pentas)_are [llength $a] ($interanglemintria deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

proc maxangletria3d {interanglemaxtria} {
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxtria 1 2 0 4 0 "3D Tria max angle "
set a [hm_getmark elems 2]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
set x1 [format "%f" [llength $a]]
set x2 [format "%f" [llength $d]]
set x3 [format "%f" [expr {[llength $allel3dlin] + [llength $allel3dsec]}]]
puts $filechannelid "The_number_of_3D_elements_that_are_above_the_maximum_angle_tolerance_(pentas)_are [llength $a] ($interanglemaxtria deg)"
puts $filechannelid "Ratio_of_failed_elements_vs_total_element_count_(Percentage) [format "%.2f" [expr {($x1/$x2)*100}]]%"
puts $filechannelid "Ratio_of_failed_elements_vs_3D_element_count_(1st_and_2nd_order)_(Percentage) [format "%.2f" [expr {($x1/$x3)*100}]]%"
puts $filechannelid ""
close $filechannelid
}

# ----------------------------------------------------------------------------------------------------------
# Master Procedures
# ----------------------------------------------------------------------------------------------------------

# A procedure to run global counts of components, properties and materials is written:

proc report_start {} {

# ----------------------------------------------------------------------------------------------------------
# Creation of variables for components, properties, materials and elements
# ----------------------------------------------------------------------------------------------------------

# Set file to write ouput, create variables "a","b","c" and "d" to store lists of all components,
# properties, materials and elements. Create variables "allel1d", "allel2dlin", "allel2dsec", "allel3dlin",
# "allel3dsec" to store 1D elements, 2D linear elements, 2D second order elements, 3D linear elements and
# 3D second order elements respectively. Write in the output file a sentence for each of the described variables with the length of each variable.

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
*createmark comps 1 "all"
set a [hm_getmark comps 1]
*createmark props 1 "all"
set b [hm_getmark props 1]
*createmark mats 1 "all"
set c [hm_getmark mats 1]
*createmark elems 1 "all"
set d [hm_getmark elems 1]
*createmark elems 1 "by config" mass plot weld rbe2 rbe3 spring bars gap rod ice
set allel1d [hm_getmark elems 1]
*createmark elems 1 "by config" quad4 tria3
set allel2dlin [hm_getmark elems 1]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [hm_getmark elems 1]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [hm_getmark elems 1]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [hm_getmark elems 1]
puts $filechannelid ""
puts $filechannelid "-------------------------Global_stats-------------------------"
puts $filechannelid ""
puts $filechannelid "The_total_number_of_components_is [llength $a]"
puts $filechannelid "The_total_number_of_properties_is [llength $b]"
puts $filechannelid "The_total_number_of_materials_is [llength $c]"
puts $filechannelid "The_total_number_of_elements_is [llength $d]"
puts $filechannelid "The_total_number_of_1D_elements_is [llength $allel1d]"
puts $filechannelid "The_total_number_of_2D_linear_elements_is [llength $allel2dlin]"
puts $filechannelid "The_total_number_of_3D_linear_elements_is [llength $allel3dlin]"
puts $filechannelid "The_total_number_of_2D_second_order_elements_is [llength $allel2dsec]"
puts $filechannelid "The_total_number_of_3D_second_order_elements_is [llength $allel3dsec]"

# ----------------------------------------------------------------------------------------------------------
# Name of components, elements contained in each component and total number of empty components
# ----------------------------------------------------------------------------------------------------------

puts $filechannelid ""
puts $filechannelid "----------------------Stats_by_component----------------------"
puts $filechannelid ""

# For each component contained in list "a", obtain the length of elements on each component and
# state it in a sentence.

foreach i $a {
*createmark elems 1 "by component" $i
set ellength [hm_getmark elems 1]
puts $filechannelid "Component_[hm_entityinfo name component $i],_elements_contained [llength $ellength]"
}

# Create a variable called empty to store empty components and print it in a sentence.

*clearmarkall 1 ; *clearmarkall 2
*EntityPreviewEmpty comps 1
set empty [hm_getmark comps 1]
puts $filechannelid ""
puts $filechannelid "The_total_number_of_empty_components_is [llength $empty]"

*clearmarkall 1 ; *clearmarkall 2

puts $filechannelid ""
puts $filechannelid "-----------------------Empty_properties-----------------------"
puts $filechannelid ""

# ----------------------------------------------------------------------------------------------------------
# Properties with thickness equal to 0
# ----------------------------------------------------------------------------------------------------------

set emptyprop {}

# For each property in the model, store the thickness in a list called emptyprop and print a sentence
# stating the thickness of the property. With the list populated with all the thicknesses, create a sentence
# stating the length of the search of elements equal to 0 in the emptyprop list.

foreach i $b {
lappend emptyprop [hm_getthickness property $i]
puts $filechannelid "The_thickness_of_property_[hm_entityinfo name property $i]_is [hm_getthickness property $i]"
}

puts $filechannelid ""
puts $filechannelid "Total_number_of_properties_that_have_thickness_equal_to_0.0_mm [llength [lsearch -all $emptyprop 0.0]] "

puts $filechannelid ""
puts $filechannelid "------------------------Empty_materials-----------------------"
puts $filechannelid ""
# ----------------------------------------------------------------------------------------------------------
# Materials with empty Rho, E or Nu
# ----------------------------------------------------------------------------------------------------------

# If the materials list is not empty, for each material create 3 sentences stating what is the defined Density,
# young's modulus and Poisson's ratio. Create an empty list called "lmatfail". Create another foreach statement
# to sweep through all materials, then an if clause to filter materials that have at least one missing value
# (density,Young's modulus or Poisson's ratio) and print it in a sentence. Finally, the filtered values are
# appended to the list called "lmatfail". One more sentence with the length of materials that have at least
# one parameter missing is printed.

if {[llength $c] != 0} {
foreach i $c {
puts $filechannelid "The_density_of_material_[hm_entityinfo name material $i]_is [hm_getvalue mats id=$i dataname=Rho]"
}

puts $filechannelid ""

foreach i $c {
puts $filechannelid "The_Young's_modulus_of_material_[hm_entityinfo name material $i]_is [hm_getvalue mats id=$i dataname=E]"
}

puts $filechannelid ""

foreach i $c {
puts $filechannelid "The_Poisson's_ratio_of_material_[hm_entityinfo name material $i]_is [hm_getvalue mats id=$i dataname=Nu]"
}

puts $filechannelid ""
}

set lmatfail {}

foreach i $c {
if {[hm_getvalue mats id=$i dataname=Rho] == 0 || [hm_getvalue mats id=$i dataname=E] == 0 || [hm_getvalue mats id=$i dataname=Nu] == 0} {
puts $filechannelid "Material_[hm_entityinfo name material $i]_has_at_least_one_parameter_missing_(Rho/young's_modulus_or_Nu)"
lappend lmatfail [hm_entityinfo name material $i]
}
}

puts $filechannelid ""
puts $filechannelid "Total_number_of_materials_that_are_missing_at_least_1_parameter_(Rho/_young's_modulus_or_Nu) [llength $lmatfail] "

close $filechannelid
}

# A master procedure is written to obtain global and quality values for the model.

proc report_master {} {
# ----------------------------------------------------------------------------------------------------------
# Introduction
# ----------------------------------------------------------------------------------------------------------

# Set output file, print 4 sentences for the following values:
# Username, date, time and current profile.

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
set systemTime [clock seconds]
puts $filechannelid "-------------------------Introduction-------------------------"
puts $filechannelid ""
puts $filechannelid "Welcome $::username"
puts $filechannelid "Today_is: [clock format $systemTime -format {%A_%B_%d,%Y}] "
puts $filechannelid "Time [clock format $systemTime -format %r]"
puts $filechannelid "The_current_profile_is [hm_info templatetype]"
close $filechannelid

# Run procedure described previously to obtain global stats on components, properties and materials.

report_start

# Create variables "allel1d", "allel2dlin", "allel2dsec", "allel3dlin", "allel3dsec" to store 1D elements,
# 2D linear elements, 2D second order elements, 3D linear elements and 3D second order elements respectively.
# Write in the output file a sentence for each of the described variables with the length of each variable.

*createmark elems 1 "by config" quad4 tria3
set allel2dlin [llength [hm_getmark elems 1]]
*createmark elems 1 "by config" tetra4 pyramid5 penta6 hex8
set allel3dlin [llength [hm_getmark elems 1]]
*createmark elems 1 "by config" quad8 tria6
set allel2dsec [llength [hm_getmark elems 1]]
*createmark elems 1 "by config" tetra10 pyramid13 penta15 hex20
set allel3dsec [llength [hm_getmark elems 1]]

# Create if conditional to run set of 2D and 3D quality criteria procedures depending on if the type of element (2D or 3D)
# are present in the model. The quality criteria are run with the values obtained from the input window created at the beginning
# of the macro.

if {[expr {$allel2dlin + $allel2dsec}] != 0 && [expr {$allel3dlin+$allel3dsec}] == 0} {

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
puts $filechannelid ""
puts $filechannelid "-----------------------2D_quality_check-----------------------"
puts $filechannelid ""
close $filechannelid

minlength $Buttons::minl
maxlength $Buttons::maxl
warpage $Buttons::warp
aspect $Buttons::asp
skew $Buttons::skewa
jacobian $Buttons::jaco
minanglequad $Buttons::minaq
maxanglequad $Buttons::maxaq
minangletria $Buttons::minat
maxangletria $Buttons::maxat
} elseif {[expr {$allel2dlin+$allel2dsec}] == 0 && [expr {$allel3dlin+$allel3dsec}] != 0} {

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
puts $filechannelid ""
puts $filechannelid "-----------------------3D_quality_check_-----------------------"
puts $filechannelid ""
close $filechannelid

minlength3d $Buttons::minl3d
maxlength3d $Buttons::maxl3d
warpage3d $Buttons::warp3d
aspect3d $Buttons::asp3d
skew3d $Buttons::skewa3d
jacobian3d $Buttons::jaco3d
minanglequad3d $Buttons::minaq3d
maxanglequad3d $Buttons::maxaq3d
minangletria3d $Buttons::minat3d
maxangletria3d $Buttons::maxat3d
} elseif {[expr {$allel2dlin+$allel2dsec}] != 0 && [expr {$allel3dlin+$allel3dsec}] != 0} {

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
puts $filechannelid ""
puts $filechannelid "-----------------------2D_quality_check-----------------------"
puts $filechannelid ""
close $filechannelid

minlength $Buttons::minl
maxlength $Buttons::maxl
warpage $Buttons::warp
aspect $Buttons::asp
skew $Buttons::skewa
jacobian $Buttons::jaco
minanglequad $Buttons::minaq
maxanglequad $Buttons::maxaq
minangletria $Buttons::minat
maxangletria $Buttons::maxat

set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
puts $filechannelid ""
puts $filechannelid "-----------------------3D_quality_check-----------------------"
puts $filechannelid ""
close $filechannelid

minlength3d $Buttons::minl3d
maxlength3d $Buttons::maxl3d
warpage3d $Buttons::warp3d
aspect3d $Buttons::asp3d
skew3d $Buttons::skewa3d
jacobian3d $Buttons::jaco3d
minanglequad3d $Buttons::minaq3d
maxanglequad3d $Buttons::maxaq3d
minangletria3d $Buttons::minat3d
maxangletria3d $Buttons::maxat3d

} elseif {[expr {$allel2dlin+$allel2dsec}] == 0 && [expr {$allel3dlin+$allel3dsec}] == 0} {
set filechannelid [open C:/Users/luis-rafael.rodrigue/Desktop/Week_14_HM_Excel_Report.txt a+]
puts $filechannelid ""
puts $filechannelid "There_are_no_2D_or_3D_elements_to_calculate_quality_values_for"
puts $filechannelid ""
close $filechannelid
}
}

The macro is run with an active model in Hypermesh and the .txt file gets generated.

----------------------------------VBA in Excel----------------------------------

Sub Write_Info()
'
' Write_Info Macro
' The first part of the macro imports the .txt file generated by the tcl macro in Hypermesh
' The file is separated by the first space it encounters from left to right, then the second
' column is separated again by the first space it encounters from left to right again.

ActiveWorkbook.Queries.Add Name:="Week_14_HM_Excel_Report (2)", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Source = Csv.Document(File.Contents(""C:\Users\luis-rafael.rodrigue\Desktop\Week_14_HM_Excel_Report.txt""),[Delimiter=""="", Columns=1, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Changed Type"" = Table.TransformColumnTypes(Source,{{""Column1"", type text}})," & Chr(13) & "" & Chr(10) & " #""Split Column by Delimiter"" = Table.SplitColumn(#""Changed Type"", ""Column1"", Sp" & _
"litter.SplitTextByEachDelimiter({"" ""}, QuoteStyle.Csv, false), {""Column1.1"", ""Column1.2""})," & Chr(13) & "" & Chr(10) & " #""Changed Type1"" = Table.TransformColumnTypes(#""Split Column by Delimiter"",{{""Column1.1"", type text}, {""Column1.2"", type text}})," & Chr(13) & "" & Chr(10) & " #""Split Column by Delimiter1"" = Table.SplitColumn(#""Changed Type1"", ""Column1.2"", Splitter.SplitTextByEachDelimiter({" & _
""" ""}, QuoteStyle.Csv, false), {""Column1.2.1"", ""Column1.2.2""})," & Chr(13) & "" & Chr(10) & " #""Changed Type2"" = Table.TransformColumnTypes(#""Split Column by Delimiter1"",{{""Column1.2.1"", type text}, {""Column1.2.2"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Changed Type2"""
' ActiveWorkbook.Worksheets.Add
ActiveWorkbook.Sheets("Sheet1").Activate
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=""Week_14_HM_Excel_Report (2)"";Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [Week_14_HM_Excel_Report (2)]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "Week_14_HM_Excel_Report__2"
.Refresh BackgroundQuery:=False
End With

ActiveWorkbook.Queries("Week_14_HM_Excel_Report (2)").Delete

' Format_cells_red
' A range to refer to all rows in column B is generated.
' 3 conditional format rules are created and applied to the range created previously.

Dim MyRange As Range
Set MyRange = Range("B:B")

MyRange.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($A1=""The_total_number_of_empty_components_is"",$B1<>""0"")"
With MyRange.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
' MyRange.FormatConditions(1).StopIfTrue = False
' Application.CutCopyMode = False

MyRange.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($A1=""Total_number_of_properties_that_have_thickness_equal_to_0.0_mm"",$B1<>""0"")"
With MyRange.FormatConditions(2).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
' Selection.FormatConditions(1).StopIfTrue = False
' Application.CutCopyMode = False

MyRange.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($A1=""Total_number_of_materials_that_are_missing_at_least_1_parameter_(Rho/_young's_modulus_or_Nu)"",$B1<>""0"")"
With MyRange.FormatConditions(3).Interior
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent5
.TintAndShade = 0.599963377788629
End With
' Selection.FormatConditions(1).StopIfTrue = False
' Application.CutCopyMode = False

' The headers of the list are removed.

ActiveSheet.ListObjects("Week_14_HM_Excel_Report__2").ShowHeaders = False

End Sub

The macro is run and the information contained in the .txt file is pasted into the excel file with the appropriate format to highlight in red the cells in case there are empty components, empty properties or empty materials.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.