Challenge

TCL/TK PROJECT 2: Macro for creating report in excel sheet format for Hypermesh

AIM: To create a macro for Hypermesh using TCL/TK which automatically creates an excel report which includes information about the user, profile used, components, materials, properties and elements. To also highlight failed and duplicate elements and empty components, unused properties and unused materials.

PROCEDURE:

The following code was created using TCL/TK for the present assignment:

*clearmarkall 1; *clearmarkall 2
set file [open results.xlsm w]
puts $file "Username, $env(USERNAME)"
puts $file "Date,[clock format [clock seconds] -format {%b. %d %Y}]"
puts $file "Time,[clock format [clock seconds] -format {%I:%M:%S %p}]"
set profile [hm_info templatetype]
puts $file "User Profile,$profile"
*createmark comps 1 "all" 
set comp_count [hm_marklength comps 1]
set comp_ids [hm_getmark comps 1]
*createmark elems 1 "all"
set elem_count [hm_marklength elems 1]
*createmark mats 1 "all"
set mat_count [hm_marklength mats 1]
set mat_ids [hm_getmark mats 1]
*createmark prop 1 "all"
set prop_count [hm_marklength props 1]
set prop_ids [hm_getmark props 1]
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"



*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"

*EntityPreviewUnused 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"

*EntityPreviewUnused 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"


*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestwarpage elems 1 15 2 2 0 "2D Warpage"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_warp [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestlength elems 1 2 2 1 2 0 "Minimum edge length"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_minlen [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestlength elems 1 8 2 0 2 0 "Maximum edge length"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_maxlen [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestaspect elems 1 5 2 2 0 "Aspect Ratio"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_aspect [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestskew elems 1 45 2 2 0 "2D Skew"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_skew [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestjacobian elems 1 0.6 2 2 0 "Jacobian"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_jacobian [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 20 1 2 1 2 0 "Minimum length Tria"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_mintria [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 120 1 2 0 2 0 "Maximum length Tria"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_maxtria [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 45 0 2 1 2 0 "Minimum quad length"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_minquad [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestinterangle elems 1 135 0 2 0 2 0 "Maximum quad length"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_maxquad [hm_marklength elems 1]
*unmaskall2
}

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
if {[hm_marklength elems 1] !=0} {hm_getduplicateelements 1 2 0
*maskentitymark elems 2 0
*maskreverse elems
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set dupl_elems [hm_marklength elems 1]
*unmaskall2
}

puts $file "Quality Criteria, No of Elements Failed"

puts $file "Warpage, $fail_warp"

puts $file "Minimum element length, $fail_minlen"

puts $file "Maximum element length, $fail_maxlen"

puts $file "Aspect Ratio, $fail_aspect"

puts $file "Skewness, $fail_skew"

puts $file "Jacobian, $fail_jacobian"

puts $file "Minimum tria angle, $fail_mintria"

puts $file "Maximum tria angle, $fail_maxtria"

puts $file "Minimum quad angle, $fail_minquad"

puts $file "Maximum quad angle, $fail_maxquad"

puts $file "Duplicate elements, $dupl_elems"

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"}

puts $file "Property ID,Property Name"
foreach j $prop_ids {set prop_name [hm_getvalue props id=$j dataname=name]
	puts $file "$j,$prop_name"}

puts $file "Material ID, Material Name"
foreach k $mat_ids {set mat_name [hm_getvalue mats id=$k dataname=name]
	puts $file "$k,$mat_name"}



close $file

The breakdown of the code is given below:

set file [open results.xlsm w]
puts $file "Username, $env(USERNAME)"
puts $file "Date,[clock format [clock seconds] -format {%b. %d %Y}]"
puts $file "Time,[clock format [clock seconds] -format {%I:%M:%S %p}]"
set profile [hm_info templatetype]
puts $file "User Profile,$profile"

Using "open" command, a file named "results.xlsm" file is written and stored as variable "file". Then using "puts" command the Username, Date, Time and profile type are entered to the excel file. The profile type is obtained using command "hm_info templatetype" and username is obtained using "$env(USERNAME)".

*createmark comps 1 "all" 
set comp_count [hm_marklength comps 1]
set comp_ids [hm_getmark comps 1]
*createmark elems 1 "all"
set elem_count [hm_marklength elems 1]
*createmark mats 1 "all"
set mat_count [hm_marklength mats 1]
set mat_ids [hm_getmark mats 1]
*createmark prop 1 "all"
set prop_count [hm_marklength props 1]
set prop_ids [hm_getmark props 1]

All components are added to a mark and the mark length which gives the count of all components is stored in variable "comp_count". All the component ids that are stored in the mark are given to variable "comp_ids". Similar steps are followed respectively for elements, materials and properties.

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"

The number of components, elements, materials and properties are added to the excel file.

*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"

*EntityPreviewUnused 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"

*EntityPreviewUnused 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"

Using command *EntityPreviewEmpty, all the empty components are stored in mark 1. Their ids are stored in "empty_comps" variable and using a foreach loop, the component ids are stored in variable "comp_empty". The count of empty components is put into the excel file. Similarly, unused properties and materials are put into the excel file.

*createmark elems 1 "displayed"
*createmark elems 2 
if {[hm_marklength elems 1] !=0} {*elementtestwarpage elems 1 15 2 2 0 "2D Warpage"
*maskentitymark elems 2 0
*maskreverse elems 
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_warp [hm_marklength elems 1]
*unmaskall2
}

All elements are tested for warpage using *elementtestwarpage command. The failed elements are isolated and nodes added to the failed elements using *nodemarkaddtempmark command. The number of failed elements are stored in variable "fail_warp" variable. Similarly, elements are tested for 9 other quality criteria such as skewness, quad angles, tria angles, etc.

*clearmarkall 1; *clearmarkall 2
*createmark elems 1 "displayed"
if {[hm_marklength elems 1] !=0} {hm_getduplicateelements 1 2 0
*maskentitymark elems 2 0
*maskreverse elems
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set dupl_elems [hm_marklength elems 1]
*unmaskall2
}

Similar to quality criteria checks, duplicate elements are checked using hm_getduplicateelments command and the number of duplicate elements is stored in variable "dupl_elems".

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"}

Using a foreach loop, the names of all the components are stored in "comp_name" and the respective properties and materials stored in "comp_prop_name" and "comp_mat_name" respectively. They are all added to the excel file along with the component ids. Similarly, all properties and materials ids and names are added to the excel file using the foreach loop.

close $file

The file opened for writing is closed.

Elements failing quality criteria are shown below:

The temporary nodes are added to highlight the failed elements. The duplicate elements are shown below:

The report obtained as excel file is shown below:

CONCLUSION: The macro required for creating a report automatically for Hypermesh was successfully created using TCL/TK.

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.