Project - 2 - Generating the report for hypermesh file
AIM: Generating the report for hypermesh file using tcl/tk script
OBJECTIVE: The objective of this project is to create an ergonomic and visually appealing excel (.xlsm) report that contains following information about your model:
· User name, date, time
· Profile/deck; count of component, prop, material, elements
· Count of empty comp/prop/mats
· Elements failed in all qualities or duplicates
PROCEDURE: To perform the given task, open any code editor ( here we use Notepad++) and type a code as follows:
# Code to create report in excel sheet format for hypermesh
*clearmarkall 1; *clearmarkall 2;
set filechannelid [open Report.csv w]
puts $filechannelid "Username,$env(USERNAME)"
puts $filechannelid "Date,[clock format [clock seconds] -format {%b:%d:%Y}]"
puts $filechannelid "Time,[clock format [clock seconds] -format {%I:%M:%S %p}]"
#Profile
set profile [hm_info templatetype]
puts $filechannelid "Profile,$profile"
#No of Components
*createmark components 1 "all"
set comps [hm_getmark components 1]
set no_of_comps [llength $comps]
puts $filechannelid "Total number of Components,$no_of_comps"
#No of Properties
*createmark properties 1 "all"
set props [hm_getmark properties 1]
set no_of_props [llength $props]
puts $filechannelid "Total number of Properties,$no_of_props"
#No of Materials
*createmark materials 1 "all"
set mats [hm_getmark materials 1]
set no_of_mats [llength $mats]
puts $filechannelid "Total number of Materials,$no_of_mats"
#No of Elements
*createmark elements 1 "all"
set elems [hm_getmark elements 1]
set no_of_elems [llength $elems]
puts $filechannelid "Total number of Elements,$no_of_elems"
*createmark elements 1
#Empty Components
*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 $filechannelid "Number of empty Components,$comp_empty"
#Unused Properties
*EntityPreviewUnused props 1
set unused_props [hm_getmark props 1]
if {[hm_marklength props 1]!=0} {foreach j $unused_props {*setvalue props id=$j color=#FF0000}}
set prop_unused [hm_marklength props 1]
puts $filechannelid "Number of unused Properties,$prop_unused"
#Unused Materials
*EntityPreviewUnused mats 1
set unused_mats [hm_getmark mats 1]
if {[hm_marklength mats 1]!=0} {foreach k $unused_mats {*setvalue mats id=$k color=#FF0000}}
set mats_unused [hm_marklength mats 1]
puts $filechannelid "Number of unused Materials,$mats_unused"
#Quality Criteria, Failed Elements
puts $filechannelid "Quality Criteria,Failed Elements"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestlength elems 1 2 2 1 2 0 "2D Min Length"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_min_length [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Minimum Length,$fail_min_length"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestlength elems 1 8 2 0 2 0 "2D Max Length"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_max_length [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Maximum Length,$fail_max_length"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestwarpage elems 1 15 2 2 0 "2D Warpage"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_warp [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Warpage,$fail_warp"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestaspect elems 1 5 2 2 0 "Aspect Ratio"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_ar [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Aspect Ratio,$fail_ar"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestskew elems 1 45 2 2 0 "2D Skew"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_skew [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "2D Skew,$fail_skew"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestjacobian elems 1 0.6 2 2 0 "Jacobian"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_jaco [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Jacobian,$fail_jaco"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestinterangle elems 1 20 1 2 1 2 0 "2D Tria Min Angle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_triamin [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Min Tria Angle,$fail_triamin"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestinterangle elems 1 120 1 2 0 2 0 "2D Tria Max Angle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_triamax [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Max Tria Angle,$fail_triamax"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestinterangle elems 1 45 0 2 1 2 0 "2D Quad Min Angle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_quadmin [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Min Quad Angle,$fail_quadmin"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*createmark elements 2
if {[hm_marklength elems 1]!=0} {*elementtestinterangle elems 1 135 0 2 0 2 0 "2D Quad Max Angle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*createmark elems 1 "displayed"
set fail_quadmax [hm_marklength elements 1]
*unmaskall2
}
puts $filechannelid "Max Quad Angle,$fail_quadmax"
*clearmarkall 1; *clearmarkall 2;
*createmark elements 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 $filechannelid "Duplicate elements,$dupl_elems"
puts $filechannelid "Component_id,Component_name,Thickness,Property,Material"
*clearmarkall 1; *clearmarkall 2;
*createmark components 1 "all"
set compid [hm_getmark components 1]
foreach info $compid {
*createmark elements 1 1 "by collector id" $info
set comp_name [hm_entityinfo name components $info]
set thickness [hm_getthickness components $info]
set prop_name [hm_getvalue component id=$info dataname=property.name]
set mat_name [hm_getvalue component id=$info dataname=material.name]
puts $filechannelid "$info,$comp_name,$thickness,$prop_name,$mat_name"
}
close $filechannelid
2. After writing the code save the file.
3. Then open any model in hypermesh and run this file in hypermesh using shortcut key assign to it.
4. After running these codes in hypermesh, following results will appear:

TCL COMMAND EXPLANATION:
1. open: Opens a new output file.
2. hm_info: This command returns general information about HyperMesh options and paths.
3. hm_getmark: Returns the entity IDs of the passed entity type on the specified mark
4. *EntityPreviewEmpty: Searches the entities specified and stores any empty entities in the outputmark
5. *setvalue:Updates an existing entity/entities with new/modified data. Data names, attributes, and metadata are allowed to be modified, assuming the proper card image is also assigned. If the specified data name is “name” and the entity type is enabled for the name pool, the provided name is used to update the solver name.
6. hm_marklength: Returns the number of entities on the specified mark
7. *EntityPreviewUnused: Searches the specified entities for any unused entities, and stores them in the outputmark.
8. *elementtestlength: Tests elements for whether or not they pass the edge length element quality check, and puts those that fail on the specified outputmark
9. *elementtestwarpage: Tests 2D and 3D elements for whether or not they pass the warpage element quality check, and puts those that fail on the specified outputmark
10. *elementtestaspect: Tests 2D and 3D elements using the aspect element quality check
11. *elementtestskew : Tests 2D and 3D elements for whether or not they pass the skew element quality check, and puts those that fail on the specified outputmark
12. *elementtestjacobian: Tests 2D and 3D elements for whether or not they pass the Jacobian ratio element quality check, and puts those that fail on the specified outputmark
13. *elementtestinterangle: Tests 2 and 3 dimensional elements for whether or not they pass the interior angle element quality check, and puts those that fail on the specified outputmark.
14. hm_getduplicateelements: Returns a list of lists containing duplicate elements.
15. *maskentitymark: This command masks the entities of entity_type that are on mark_id. Valid mark_ids are 1 and 2. Only entities in displayed collectors may be masked. To mask connectors and the realized FE, a flag of 1 must be passed. To mask only connectors (excluding realized FE) and all other entity types, a flag of zero must be passed.
16. *maskreverse: Reverses the masking state of a specific entity type. For collected entities, only entities in displayed collectors are affected.
17. *nodemarkaddtempmark: Places a node on the temporary node mark
18. *unmaskall: Unmasks all supported entities. For collected entities, only entities in displayed collectors are affected
19. hm_entityinfo: Returns various information on entities
20. hm_getthickness: Returns the thickness of the specified component, element or property.
21. hm_getvalue: Queries data names, attributes, and metadata on entities. It will return the value of any type of data name, attribute, or metadata of an entity. In addition, this command will also return the value at a specific index for array type of data names, attributes, and metadata
22. close: Terminates output to the currently open output file.
CONCLUSION: After executing proper tcl/tk code, we are able to create an excel (.xlsm) report for hypermesh that contains user name, date, time, profile/deck, count of component, properties, materials, elements, count of empty components/properties/materials, elements failed in all qualities or duplicates.