Challenge

Project 1- Building a Master TCL/TK Macro

Objective

The purpose of this task is to integrate into a window all the procedures of code generated during this course. This window will help us have all these tools at hand.

Problem statement

The problem consists of a single deliverable

A window that concentrates all tools generated during this course. These tools will have to come from the code generated in past weeks and will have to integrate if conditionals to exclude null cases.

Tcl Code Explanation

# -------------------------------------------------------------------------------------------
# Week 3 - procedures to delete elements and find their locator
# -------------------------------------------------------------------------------------------

Create a procedure to delete elements easily, by taking the code to delete elements and put it inside a procedure. Insert an if clause that will make this code work only if there are elements selected, otherwise the code will print in the console a message saying that there is "no selection"

proc delete_elements {} {
*createmarkpanel elems 1 "Select the elements you wish to delete"
set a [hm_getmark elems 1]
if {[llength $a] != 0} {
*deletemark elems 1
} elseif {[llength $a] == 0} {
puts "No Selection"
*clearmarkall 1
}
}

Take the code to obtain the component of a given element and intoduce it into a procedure. Insert an if clause that will make this code work only if there are elements selected, otherwise the code will print in the console a message saying that there is "Your Selection is empty"

proc locator {} {
*createmarkpanel elems 1 "Select the elements you wish to know what component they belong to"
hm_getwhollycontainedcollectormark elems 1 1 1
set a [hm_getmark comps 1]
set al [llength $a]
if {$al == 1} {
puts "The elements you selected belong to component: [hm_getcollectorname comps $a]"
hm_markclearall 1
} elseif {$al > 1} {
set i 1
puts "The elements you selected belong to components: "
while {$i <= $al} {
puts "[hm_getcollectorname comps [lindex $a [expr $i-1]]]"
incr i 1
}
hm_markclearall 1
} elseif {$al == 0} {
puts "Your selection is empty"
}
}

# -------------------------------------------------------------------------------------------
# Week 6 - Cleanup operations
# -------------------------------------------------------------------------------------------

# Functions to delete displayed entities, delete empty components,

# Procedure to delete displayed entities, a as input determines
# if what is going to be deleted is a solid, surface, line or point

proc delete {a} {
*createmark $a 1 "displayed"
if {[hm_marklength $a 1] != 0} {*deletemark $a 1}
}

# Procedure to delete and select empty component, assembly,
# property or material

proc empty {a} {
*EntityPreviewEmpty $a 1
if {[hm_marklength $a 1] != 0} {*deletemark $a 1}
}

# Procedure to delete and select any unused component, assembly,
# property or material

proc unused {a} {
*EntityPreviewUnused $a 1
if {[hm_marklength $a 1] != 0} {*deletemark $a 1}
}

# Procedure to isolate any solid, surface, line or point that may
# be of interest with the purpose of easing the reading of an assembly

proc isolate_displayed {a} {
hm_createmark $a 1 "advanced" "displayed"
hm_createmark $a 1 "advanced" "reverse"
if {[hm_marklength $a 1] != 0} {*deletemark $a 1}
}

# Procedure to renumber all components, assemblies, properties and materials
# depending on their alphabetical order

proc renumber {a} {
hm_createmark $a 1 "advanced" "all"
if {[hm_marklength $a 1] != 0} {*renumbersolverid $a 1 1 1 0 0 0 0 0}
}

# Procedure to renorder all components, assemblies, properties and materials
# depending on their alphabetical order

proc reorder {a} {
hm_createmark $a 1 "advanced" "all"
if {[hm_marklength $a 1] != 0} {*collectormarkmove $a 1 1 1}
}

# Master procedure to execute all tasks required to clean the assembly

proc master {} {
delete solids
delete surfaces
delete line
delete point
empty component
empty assemblies
empty properties
empty materials
reorder components
reorder materials
reorder properties
renumber components
renumber materials
renumber properties
}

# -------------------------------------------------------------------------------------------
# Week 7 - Free Edges
# -------------------------------------------------------------------------------------------

# Procedure to extract edges form bodies and change the color of edgs to red

proc format_edges {} {
*createmark elems 1 "all"
*findedges1 elements 1 0 0 0 30
set b [hm_entitymaxid comps]
*setvalue comps id=$b name=Edges
*setvalue comps id=$b color=3
*createmark comps 1 [hm_entitymaxid comps] [expr [hm_entitymaxid comps]-1]
*createmark comps 1 "reverse"
*setmarkdisplayattributes components 1 4 1
}

# Procedure to extract T-connections form bodies and change the color of edges to cyan

proc format_tedges {} {
*createmark elems 1 "all"
*findedges1 elements 1 1 0 0 30
set a [hm_entitymaxid comps]
*setvalue comps id=$a name=T-Edges
*setvalue comps id=$a color=7
*createmark comps 1 [hm_entitymaxid comps] [expr [hm_entitymaxid comps]-1]
*createmark comps 1 "reverse"
*setmarkdisplayattributes components 1 4 1
}

# -------------------------------------------------------------------------------------------
# Week 8 - Components
# -------------------------------------------------------------------------------------------

# Create a procedure to make new components and properties to define thickness

proc comp_create_prop {a b} {
set n $a\_$b
*createentity comps cardimage=Part name=$n
*createmark comps 1 $n
set compid [hm_getmark comps 1]
*createentity props cardimage=SectShll name=$n
*createmark props 2 $n
set propid [hm_getmark props 2]
if {[hm_info templatetype] == "nastran"} {
*setvalue props id=$propid cardimage="PSHELL"
*setvalue props id=$propid STATUS=1 95=$b
*setvalue comps id=$compid propertyid={props $propid};
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "abaqus"} {
*setvalue props id=$propid cardimage="SHELLSECTION"
*setvalue props id=$propid STATUS=1 111=$b
*setvalue comps id=$compid propertyid={props $propid};
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "ansys"} {
*setvalue props id=$propid cardimage="SHELL28p" usingxmldata=Ansys.xml
*setvalue comps id=$compid cardimage="HM_COMP" usingxmldata=Ansys.xml
*setvalue props id=$propid STATUS=2 136={$b 0 0}
*setvalue comps id=$compid propertyid={props $propid}
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "lsdyna"} {
*setvalue props id=$propid cardimage="SectShll"
*setvalue props id=$propid STATUS=1 431=$b
*setvalue comps id=$compid propertyid={props $propid}
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "radioss"} {
*setvalue props id=$propid cardimage="P10_SH_COMP"
*setvalue props id=$propid STATUS=1 431=$b
*setvalue comps id=$compid propertyid={props $propid}
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "samcef"} {
*setvalue props id=$propid cardimage="SHELLPHP"
*setvalue props id=$propid STATUS=2 1143=1
*setvalue props id=$propid STATUS=1 1003=$b
*setvalue comps id=$compid propertyid={props $propid}
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "permas"} {
*setvalue props id=$propid cardimage="SHELL"
*setvalue comps id=$compid cardimage="PART_ELPROP"
*setvalue props id=$propid STATUS=2 417=$b
*setvalue comps id=$compid propertyid={props $propid}
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
}
}

# Create a procedure to make new components that do not require properties to define thickness

proc comp_create {a b} {
if {[hm_info templatetype] == "exodus"} {
set n $a\_$b
*createentity comps cardimage=SHELL name=$n
*createmark comps 1 $n
set compid [hm_getmark comps 1]
*setvalue comps id=$compid cardimage="Shell"
*setvalue comps id=$compid STATUS=1 95=$b
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
} elseif {[hm_info templatetype] == "pamcrash2g"} {
set n $a\_$b
*createentity comps cardimage=PART_2D name=$n
*createmark comps 1 $n
set compid [hm_getmark comps 1]
*setvalue comps id=$compid STATUS=2 416=$b
*createmark comps 1 $compid
*autocolorwithmark components 1
*createmark properties 1 $propid
*autocolorwithmark properties 1
}
}

# Create a procedure that by nesting the procedures avobe decides appropriately how to create a component with a defined thickness.

proc comp_create_master {name thickness} {
if {[hm_info templatetype] == "exodus" || [hm_info templatetype] == "pamcrash2g"} {
comp_create $name $thickness
} elseif {[hm_info templatetype] == "nastran" || [hm_info templatetype] == "abaqus" || [hm_info templatetype] == "ansys" || [hm_info templatetype] == "lsdyna" || [hm_info templatetype] == "radioss" || [hm_info templatetype] == "samcef" || [hm_info templatetype] == "permas"} {
comp_create_prop $name $thickness
}
}

# -------------------------------------------------------------------------------------------
# Week 9 - Reflect
# -------------------------------------------------------------------------------------------

Insert the code for reflecting geometries of week 9. Introduce an if statement that requires the origin geometry, target geometry and fea components to be present. If this statement is not covered, the elseif clause prints in the console a message stating that there is one or more missing inputs.

proc reflectgeom {} {
*clearmarkall 1 ; *clearmarkall 2;
set name [hm_getstring "Component Name" "Enter the name of reflect component"]
*createmarkpanel comps 1 "Select the component containing the original geometry to be reflected"
set o_geom [hm_getmark comp 1]
*createmarkpanel comps 1 "Select the containing target geometry"
set t_geom [hm_getmark comp 1]
*createmarkpanel comps 1 "Select the FE elements you wish to reflect"
set o_fea [hm_getmark comps 1]

if {[llength $o_geom] != 0 && [llength $t_geom] != 0 && [llength $o_fea] != 0} {

foreach i $o_fea {
set t [hm_getthickness comps $i]
set old_n [hm_entityinfo name comps $i]
set n $name
comp_create_master $n $t
*createmark elems 1 $old_n
*copymark elems 1 $n\_$t
*displaycollectorwithfilter component "off" $old_n 1 0
}
*createmark comps 2 "displayed"
*autocolorwithmark components 2

*clearmarkall 1 ; *clearmarkall 2;
*createmark solids 1 $o_geom
set x1 [lindex [hm_getcentroid solid 1] 0]
set y1 [lindex [hm_getcentroid solid 1] 1]
set z1 [lindex [hm_getcentroid solid 1] 2]
*createnode $x1 $y1 $z1 0 0 0
*createmark node 1 -1
set node_1 [hm_getmark node 1]

*createmark solids 1 $t_geom
set x2 [lindex [hm_getcentroid solid 1] 0]
set y2 [lindex [hm_getcentroid solid 1] 1]
set z2 [lindex [hm_getcentroid solid 1] 2]
*createnode $x2 $y2 $z2 0 0 0
*createmark node 1 -1
set node_2 [hm_getmark node 1]

set intercepts [hm_getdistance nodes $node_1 $node_2 0]
set int_1 [lindex $intercepts 1]
set int_2 [lindex $intercepts 2]
set int_3 [lindex $intercepts 3]

*createnodesbetweennodes $node_1 $node_2 1
*createmark nodes 1 -1
set m_node [hm_getmark nodes 1]
set m_node_info [hm_nodevalue $m_node]
set base_1 [lindex [lindex $m_node_info 0] 0]
set base_2 [lindex [lindex $m_node_info 0] 1]
set base_3 [lindex [lindex $m_node_info 0] 2]

*clearmarkall 1 ; *clearmarkall 2;
*createmark elems 1 "displayed"
*createplane 1 $int_1 $int_2 $int_3 $base_1 $base_2 $base_3
*reflectmarkwithoption elements 1 1 0
} elseif {[llength $o_geom] != 0 || [llength $t_geom] != 0 || [llength $o_fea] != 0} {
puts "One or more of your selections is empty"
}
}

# -------------------------------------------------------------------------------------------
# Week 10 - The importance of order
# -------------------------------------------------------------------------------------------

# Welding Macro
# -------------------------------------------------------------------------------------------

Introduce the code generated in week 10 to create weld lines into a procedure. Insert an "if" clause that will make this code work only if there are nodes selected for each input and the length of both selections is the same. Otherwise, the code will print in the console a message saying that there is "The lists are not of equal length or one or both are empty"

proc welding_line {} {
*createlistbypathpanel nodes 1 "Select the first path of nodes where you want the welds to pass through"
set a [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select the second path of nodes where you want the welds to pass through"
set b [hm_getlist nodes 2]
createcomp
*currentcollector components "WeldLines"
if {[llength $a] == [llength $b]} {
foreach i $a j $b {
*rigid $i $j 123456
}
} elseif {[llength $a] != [llength $b] || [llength $a] == 0 || [llength $b] == 0} {
puts "The lists are not of equal length or one or both are empty"
}
}

# Midline macro
# -------------------------------------------------------------------------------------------

Introduce the code generated in week 10 to create mid-linesinto a procedure. Insert an "if" clause that will make this code work only if there are lines selected for each input and the length of both selections is the same. Otherwise, the code will print in the console a message saying that there is "The lists are not of equal length or one or both are empty"

proc midlinecreate {} {
*createlistbypathpanel lines 1 "Select the first line to build the mid-line"
set a [hm_getlist lines 1]
*createlistbypathpanel lines 2 "Select the second line to build the mid-line"
set b [hm_getlist lines 2]
*createentity comps cardimage=Part name=Mid_line
*createlist nodes 1
*createlist nodes 2
if {[llength $a] == [llength $b]} {
foreach i $a j $b {
*createlist lines 1 $i
*createlist lines 2 $j
*linescreatemidline 1 1 2 2
}
*createmark lines 1 "by comp" Mid_line
*linecombinemark 1 0.1 60 0
} elseif {[llength $a] != [llength $b] || [llength $a] == 0 || [llength $b] == 0} {
puts "The lists are not of equal length or one or both are empty"
}
}

# -------------------------------------------------------------------------------------------
# Week 11 - Element quality
# -------------------------------------------------------------------------------------------

# 2D procedures

# Create a procedure for each and every single mesh quality check

proc minlength {minlength} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestlength elements 1 $minlength 2 1 2 0 "2D Length < "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxlength {maxlength} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestlength elements 1 $maxlength 2 0 2 0 "2D Length > "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc warpage {warpangle} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestwarpage elements 1 $warpangle 2 2 0 "2D Warpage "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc aspect {aspect} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestaspect elements 1 $aspect 2 2 0 "2D Aspect Ratio "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc skew {skewness} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestskew elements 1 $skewness 2 2 0 "2D skewness "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc jacobian {jacobiann} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $jacobiann 2 2 0 "Jacobian "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc minanglequad {interangleminquad} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interangleminquad 0 2 1 2 0 "2D Quad min angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxanglequad {interanglemaxquad} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxquad 0 2 0 2 0 "2D Quad max angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc minangletria {interanglemintria} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemintria 1 2 1 2 0 "2D Tria min angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxangletria {interanglemaxtria} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxtria 1 2 0 2 0 "2D Tria max angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

# 3D procedures

proc minlength3d {minlength} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestlength elements 1 $minlength 2 1 4 0 "3D Length < "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxlength3d {maxlength} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestlength elements 1 $maxlength 2 0 4 0 "3D Length > "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc warpage3d {warpangle} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestwarpage elems 1 $warpangle 2 4 0 "3D Warpage "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc aspect3d {aspect} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestaspect elems 1 $aspect 2 4 0 "3D Aspect Ratio "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc skew3d {skewness} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestskew elements 1 $skewness 2 4 0 "3D skewness "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc jacobian3d {jacobiann} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $jacobiann 2 4 0 "3D Jacobian "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc minanglequad3d {interangleminquad} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interangleminquad 0 2 1 4 0 "3D Quad min angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxanglequad3d {interanglemaxquad} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxquad 0 2 0 4 0 "3D Quad max angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc minangletria3d {interanglemintria} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemintria 1 2 1 4 0 "3D Tria min angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

proc maxangletria3d {interanglemaxtria} {
*clearmarkall 1; *clearmarkall 2;
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $interanglemaxtria 1 2 0 4 0 "3D Tria max angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall
}

# -------------------------------------------------------------------------------------------
# Week 12 - Miscellaneous - Spot-welds, locators and components
# -------------------------------------------------------------------------------------------

Copy the code generated to create spotwelds in week 12. Introduce an if statement that creates rigid elements only when the selection list is not empty. When it is empty, the console displays a message saying "Selection is empty"

proc weld {} {
*clearmarkall 1 ; *clearmarkall 2
createcomp
*currentcollector components "SpotWelds"
*createmarkpanel nodes 2 "Select the nodes where you want to create the welding"
set nodelist [hm_getmark nodes 2]
if {[llength $nodelist] != 0} {
*rigidlinkinodecalandcreate 2 0 0 123456
*clearmarkall 2
} elseif {[llength $nodelist] == 0} {
puts "Selection is empty"
}
}

Copy the code generated to create x-locators in week 12. Introduce an if statement that creates rigid elements only when the selection list is not empty. When it is empty, the console displays a message saying "One or both selections are empty", if the selections are of more than 1 node, a message is displayed saying "Both elections must be of 1 node"

proc xlocator {} {
*clearmarkall 1 ; *clearmarkall 2
createcomp
*currentcollector components "X_locator"
*createlistbypathpanel nodes 1 "Select the first node where you want to create the x-locator"
set a [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select the second node where you want to create the x-locator"
set b [hm_getlist nodes 2]
if {[llength $a] == 0 || [llength $b] == 0} {
puts "One or both selections are empty"
} elseif {[llength $a] == 1 && [llength $b] == 1} {
*rigid $a $b 156
} elseif {[llength $a] > 1 || [llength $b] > 1} {
puts "Both selections must be of 1 node"
}
}

Copy the code generated to create y-locators in week 12. Introduce an if statement that creates rigid elements only when the selection list is not empty. When it is empty, the console displays a message saying "One or both selections are empty", if the selections are of more than 1 node, a message is displayed saying "Both elections must be of 1 node"

proc ylocator {} {
*clearmarkall 1 ; *clearmarkall 2
createcomp
*currentcollector components "Y_locator"
*createlistbypathpanel nodes 1 "Select the first node where you want to create the y-locator"
set a [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select the second node where you want to create the y-locator"
set b [hm_getlist nodes 2]
if {[llength $a] == 0 || [llength $b] == 0} {
puts "One or both selections are empty"
} elseif {[llength $a] == 1 && [llength $b] == 1} {
*rigid $a $b 246
} elseif {[llength $a] > 1 || [llength $b] > 1} {
puts "Both selections must be of 1 node"
}
}

Copy the code generated to create z-locators in week 12. Introduce an if statement that creates rigid elements only when the selection list is not empty. When it is empty, the console displays a message saying "One or both selections are empty", if the selections are of more than 1 node, a message is displayed saying "Both elections must be of 1 node"

proc zlocator {} {
*clearmarkall 1 ; *clearmarkall 2
createcomp
*currentcollector components "Z_locator"
*createlistbypathpanel nodes 1 "Select the first node where you want to create the z-locator"
set a [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select the second node where you want to create the z-locator"
set b [hm_getlist nodes 2]
if {[llength $a] == 0 || [llength $b] == 0} {
puts "One or both selections are empty"
} elseif {[llength $a] == 1 && [llength $b] == 1} {
*rigid $a $b 345
} elseif {[llength $a] > 1 || [llength $b] > 1} {
puts "Both selections must be of 1 node"
}
}

Create a procedure that sets the current component to "spotwelds", "X_locator", "Y_locator" and "Z_locator". If the macro does not find these components, it creates them.

proc createcomp {} {
*clearmarkall 1 ; *clearmarkall 2
*createmark component 1 SpotWelds; if {[hm_marklength components 1] == 0} {*createentity component name=SpotWelds color=3}
*createmark component 1 X_locator; if {[hm_marklength components 1] == 0} {*createentity component name=X_locator color=56}
*createmark component 1 Y_locator; if {[hm_marklength components 1] == 0} {*createentity component name=Y_locator color=5}
*createmark component 1 Z_locator; if {[hm_marklength components 1] == 0} {*createentity component name=Z_locator color=6}
*createmark component 1 WeldLines; if {[hm_marklength components 1] == 0} {*createentity component name=WeldLines color=40}
}

# -------------------------------------------------------------------------------------------
# Detective macro
# -------------------------------------------------------------------------------------------

Copy the code to look for components with the same amount of surfaces as in week 12. Introduce an if statement where if the target component is not selected, a message gets displayed saying "No selection"

proc similar {} {
*clearmarkall 1 ; *clearmarkall 2
*createmark comps 1 "all"
set all_comps [hm_getmark comps 1]

*clearmarkall 1 ; *clearmarkall 2

foreach i $all_comps {
*createmark surfs 1 "by collector" $i
lappend all_comps_surf_count [hm_marklength surfaces 1]
}

*clearmarkall 1 ; *clearmarkall 2
*createmarkpanel comps 1 "Select the component you wish to look for"
set target [hm_getmark comps 1]

if {[llength $target] != 0} {

*isolateentitybymark 1
puts "Target comp id $target"
*createmark surfs 2 "by collector" $target
set target_surf_count [hm_marklength surfaces 2]

*clearmarkall 1 ; *clearmarkall 2
set match [lsearch -all $all_comps_surf_count $target_surf_count]
puts "Match list surfaces $match"

foreach j $match {
*clearmarkall 1 ; *clearmarkall 2
set comp_id [lindex $all_comps $j]
set comp_name [hm_entityinfo name components $comp_id]
*displaycollectorwithfilter components "on" "$comp_name" 0 1
}

} elseif {[llength $target] == 0} {
puts "No Selection"
}
}

# -------------------------------------------------------------------------------------------
# Read and write nodes
# -------------------------------------------------------------------------------------------

Copy the procedure of week 12 to read node coordinates from a .csv file.

proc read_nodes {} {
set filename [tk_getOpenFile -title "Select node info file"]
set fileChannelId [open $filename r]
while {[eof $fileChannelId] == 0} {
puts [set lst_nodeCord [gets $fileChannelId]]
*createnode [lindex $lst_nodeCord 0] [lindex $lst_nodeCord 1] [lindex $lst_nodeCord 2];
}
close $fileChannelId
}

Copy the procedure of week 12 to write selected nodes into a .csv file. Introduce an if conditional where if no nodes are selected the console displays a message saying "No Selection"

proc write_nodes {} {
*clearmarkall 1 ; *clearmarkall 2;
*createlistpanel nodes 1 "Select the nodes you wish to write in the text file"
set nodelist [hm_getlist nodes 1]
if {[llength nodeslist] != 0} {
set fileChannelId [open "write_nodes.csv" w]
foreach i $nodelist {
set info [hm_nodevalue $i]
puts $fileChannelId [lindex $info 0]
}
close $fileChannelId
} elseif {[llength nodeslist] == 0} {
puts "No Selection"
}
}

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

Create the window to display the buttons and labels, fill every button with the appropriate command.

# Create window to store 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 1300x600+500+250 ; update
wm resizable $a 0 0
wm deiconify $a

button $a.01 -text "Delete Elements" -bg "light salmon" -font {Arial 10 bold} -command {delete_elements} ; place $a.01 -x 10 -y 10 -width 200 -height 20
button $a.02 -text "Entity Info" -bg "light salmon" -font {Arial 10 bold} -command {locator} ; place $a.02 -x 10 -y 40 -width 200 -height 20
button $a.03 -text "Master Clean-up" -bg "light salmon" -font {Arial 10 bold} -command {master} ; place $a.03 -x 10 -y 70 -width 200 -height 20
button $a.04 -text "Edges" -bg "light salmon" -font {Arial 10 bold} -command {format_edges} ; place $a.04 -x 10 -y 100 -width 200 -height 20
button $a.81 -text "T-Connections" -bg "light salmon" -font {Arial 10 bold} -command {format_tedges} ; place $a.81 -x 10 -y 130 -width 200 -height 20
button $a.06 -text "Reflect Geometry" -bg "light salmon" -font {Arial 10 bold} -command {reflectgeom} ; place $a.06 -x 10 -y 160 -width 200 -height 20
button $a.07 -text "Welding Line" -bg "pale violet red" -font {Arial 10 bold} -command {welding_line} ; place $a.07 -x 220 -y 160 -width 200 -height 20
button $a.08 -text "Middle Line" -bg "light salmon" -font {Arial 10 bold} -command {midlinecreate} ; place $a.08 -x 10 -y 190 -width 200 -height 20
button $a.05 -text "Create Components" -bg "light salmon" -font {Arial 10 bold} -command {comp_create_master $compname $compthick} ; place $a.05 -x 10 -y 220 -width 200 -height 20
entry $a.100 -textvariable ::compname ; place $a.100 -x 220 -y 220 -width 200 -height 20
entry $a.101 -textvariable ::compthick ; place $a.101 -x 430 -y 220 -width 200 -height 20
label $a.102 -text "Component name" -font {Arial 10 bold} ; place $a.102 -x 220 -y 190 -width 200 -height 20
label $a.103 -text "Component thickness" -font {Arial 10 bold} ; place $a.103 -x 430 -y 190 -width 200 -height 20

# Quality Checks

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

button $a.11 -text "Min Length Check" -bg skyblue2 -command {minlength $minl} -command {minlength $minl} ; place $a.11 -x 10 -y 280 -width 200 -height 20
label $a.12 -text "Minimum Length <" -bg skyblue2 -font {Arial 10 bold} ; place $a.12 -x 220 -y 280 -width 200 -height 20
entry $a.13 -textvariable ::minl ; place $a.13 -x 430 -y 280 -width 200 -height 20

button $a.14 -text "Max Length Check" -bg skyblue2 -command {maxlength $maxl} -command {maxlength $maxl} ; place $a.14 -x 10 -y 310 -width 200 -height 20
label $a.15 -text "Maximum Length >" -bg skyblue2 -font {Arial 10 bold} ; place $a.15 -x 220 -y 310 -width 200 -height 20
entry $a.16 -textvariable ::maxl ; place $a.16 -x 430 -y 310 -width 200 -height 20

button $a.17 -text "Warpage Check" -bg skyblue2 -command {warpage $warp} -command {warpage $warp} ; place $a.17 -x 10 -y 340 -width 200 -height 20
label $a.18 -text "Warpage >" -bg skyblue2 -font {Arial 10 bold} ; place $a.18 -x 220 -y 340 -width 200 -height 20
entry $a.19 -textvariable ::warp ; place $a.19 -x 430 -y 340 -width 200 -height 20

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

button $a.23 -text "Skew Check" -bg skyblue2 -command {skew $skewa} -command {skew $skewa} ; place $a.23 -x 10 -y 400 -width 200 -height 20
label $a.24 -text "Skew >" -bg skyblue2 -font {Arial 10 bold} ; place $a.24 -x 220 -y 400 -width 200 -height 20
entry $a.25 -textvariable ::skewa ; place $a.25 -x 430 -y 400 -width 200 -height 20

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

button $a.29 -text "Min Angle Quad Check" -bg skyblue2 -command {minanglequad $minaq} -command {minanglequad $minaq} ; place $a.29 -x 10 -y 460 -width 200 -height 20
label $a.30 -text "Minimum Angle quad <" -bg skyblue2 -font {Arial 10 bold} ; place $a.30 -x 220 -y 460 -width 200 -height 20
entry $a.31 -textvariable ::minaq ; place $a.31 -x 430 -y 460 -width 200 -height 20

button $a.32 -text "Max Angle Quad Check" -bg skyblue2 -command {maxanglequad $maxaq} -command {maxanglequad $maxaq} ; place $a.32 -x 10 -y 490 -width 200 -height 20
label $a.33 -text "Max Angle Quad >" -bg skyblue2 -font {Arial 10 bold} ; place $a.33 -x 220 -y 490 -width 200 -height 20
entry $a.34 -textvariable ::maxaq ; place $a.34 -x 430 -y 490 -width 200 -height 20

button $a.35 -text "Min Angle Tria Check" -bg skyblue2 -command {minangletria $minat} -command {minangletria $minat} ; place $a.35 -x 10 -y 520 -width 200 -height 20
label $a.36 -text "Minimum Angle Tria <" -bg skyblue2 -font {Arial 10 bold} ; place $a.36 -x 220 -y 520 -width 200 -height 20
entry $a.37 -textvariable ::minat ; place $a.37 -x 430 -y 520 -width 200 -height 20

button $a.38 -text "Max Angle Tria Check" -bg skyblue2 -command {maxangletria $maxat} -command {maxangletria $maxat} ; place $a.38 -x 10 -y 550 -width 200 -height 20
label $a.39 -text "Maximum Angle Tria >" -bg skyblue2 -font {Arial 10 bold} ; place $a.39 -x 220 -y 550 -width 200 -height 20
entry $a.40 -textvariable ::maxat ; place $a.40 -x 430 -y 550 -width 200 -height 20

# 3d buttons

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

button $a.43 -text "Min Length Check" -bg "medium aquamarine" -command {minlength3d $minl3d} -command {minlength3d $minl3d} ; place $a.43 -x 640 -y 280 -width 200 -height 20
label $a.44 -text "Minimum Length <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.44 -x 850 -y 280 -width 200 -height 20
entry $a.45 -textvariable ::minl3d ; place $a.45 -x 1060 -y 280 -width 200 -height 20

button $a.46 -text "Max Length Check" -bg "medium aquamarine" -command {maxlength3d $maxl3d} -command {maxlength3d $maxl3d} ; place $a.46 -x 640 -y 310 -width 200 -height 20
label $a.47 -text "Maximum Length >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.47 -x 850 -y 310 -width 200 -height 20
entry $a.48 -textvariable ::maxl3d ; place $a.48 -x 1060 -y 310 -width 200 -height 20

button $a.49 -text "Warpage Check" -bg "medium aquamarine" -command {warpage3d $warp3d} -command {warpage3d $warp3d} ; place $a.49 -x 640 -y 340 -width 200 -height 20
label $a.50 -text "Warpage >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.50 -x 850 -y 340 -width 200 -height 20
entry $a.51 -textvariable ::warp3d ; place $a.51 -x 1060 -y 340 -width 200 -height 20

button $a.52 -text "Aspect Check" -bg "medium aquamarine" -command {aspect3d $asp3d} -command {aspect3d $asp3d} ; place $a.52 -x 640 -y 370 -width 200 -height 20
label $a.53 -text "Aspect >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.53 -x 850 -y 370 -width 200 -height 20
entry $a.54 -textvariable ::asp3d ; place $a.54 -x 1060 -y 370 -width 200 -height 20

button $a.55 -text "Skew Check" -bg "medium aquamarine" -command {skew3d $skewa3d} -command {skew3d $skewa3d} ; place $a.55 -x 640 -y 400 -width 200 -height 20
label $a.56 -text "Skew >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.56 -x 850 -y 400 -width 200 -height 20
entry $a.57 -textvariable ::skewa3d ; place $a.57 -x 1060 -y 400 -width 200 -height 20

button $a.58 -text "Jacobian Check" -bg "medium aquamarine" -command {jacobian3d $jaco3d} -command {jacobian3d $jaco3d} ; place $a.58 -x 640 -y 430 -width 200 -height 20
label $a.59 -text "Jacobian <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.59 -x 850 -y 430 -width 200 -height 20
entry $a.60 -textvariable ::jaco3d ; place $a.60 -x 1060 -y 430 -width 200 -height 20

button $a.61 -text "Min Angle Hexa Check" -bg "medium aquamarine" -command {minanglequad3d $minaq3d} -command {minanglequad3d $minaq3d} ; place $a.61 -x 640 -y 460 -width 200 -height 20
label $a.62 -text "Minimum Angle Hexa <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.62 -x 850 -y 460 -width 200 -height 20
entry $a.63 -textvariable ::minaq3d ; place $a.63 -x 1060 -y 460 -width 200 -height 20

button $a.64 -text "Max Angle Hexa Check" -bg "medium aquamarine" -command {maxanglequad3d $maxaq3d} -command {maxanglequad3d $maxaq3d} ; place $a.64 -x 640 -y 490 -width 200 -height 20
label $a.65 -text "Max Angle Hexa >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.65 -x 850 -y 490 -width 200 -height 20
entry $a.66 -textvariable ::maxaq3d ; place $a.66 -x 1060 -y 490 -width 200 -height 20

button $a.67 -text "Min Angle Penta Check" -bg "medium aquamarine" -command {minangletria3d $minat3d} -command {minangletria3d $minat3d} ; place $a.67 -x 640 -y 520 -width 200 -height 20
label $a.68 -text "Minimum Angle Penta <" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.68 -x 850 -y 520 -width 200 -height 20
entry $a.69 -textvariable ::minat3d ; place $a.69 -x 1060 -y 520 -width 200 -height 20

button $a.70 -text "Max Angle Penta Check" -bg "medium aquamarine" -command {maxangletria3d $maxat3d} -command {maxangletria3d $maxat3d} ; place $a.70 -x 640 -y 550 -width 200 -height 20
label $a.71 -text "Maximum Angle Penta >" -bg "medium aquamarine" -font {Arial 10 bold} ; place $a.71 -x 850 -y 550 -width 200 -height 20
entry $a.72 -textvariable ::maxat3d ; place $a.72 -x 1060 -y 550 -width 200 -height 20

button $a.77 -text "1D Collectors" -bg "pale violet red" -font {Arial 10 bold} -command {createcomp} ; place $a.77 -x 220 -y 10 -width 200 -height 20
button $a.73 -text "Spotwelds" -bg "pale violet red" -font {Arial 10 bold} -command {weld} ; place $a.73 -x 220 -y 40 -width 200 -height 20
button $a.74 -text "X-Locator" -bg "pale violet red" -font {Arial 10 bold} -command {xlocator} ; place $a.74 -x 220 -y 70 -width 200 -height 20
button $a.75 -text "Y-Locator" -bg "pale violet red" -font {Arial 10 bold} -command {ylocator} ; place $a.75 -x 220 -y 100 -width 200 -height 20
button $a.76 -text "Z-Locator" -bg "pale violet red" -font {Arial 10 bold} -command {zlocator} ; place $a.76 -x 220 -y 130 -width 200 -height 20

button $a.78 -text "Detective" -bg "honeydew2" -font {Arial 10 bold} -command {similar} ; place $a.78 -x 430 -y 10 -width 200 -height 20

button $a.79 -text "Read Nodes" -bg "honeydew2" -font {Arial 10 bold} -command {read_nodes} ; place $a.79 -x 430 -y 40 -width 200 -height 20
button $a.80 -text "Write Nodes" -bg "honeydew2" -font {Arial 10 bold} -command {write_nodes} ; place $a.80 -x 430 -y 70 -width 200 -height 20

Conclusion

The development of this task has brought to light the significance of all the previous procedures. Working in small but constant efforts has brought fruitful results.

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.