Challenge

Project 1- Building a Master TCL/TK Macro

AIM: To create a master macro using previous challenge

PROCEDURE:

CODE:

#setting up the window
set a .master
catch {destroy $a}
toplevel $a -class TopLevel
wm title $a "Master Macro"
#size of a window tab is defined:
wm geometry $a 660x515+0+0; update
wm resizable $a 0 0
wm deiconify $a

#creating label

label $a.001 -text "2D Element Check" -bg red -font {Arial 9 bold }; place $a.001 -x 10 -y 10 -width 170 -height 20

#creating entry box and button for 2D element check:

entry $a.01 -textvariable "::mil" -font {arial 9}; place $a.01 -x 140 -y 40 -width 40 -height 20
button $a.02 -text "Min Length" -command "minl" -font {arial 9} ; place $a.02 -x 10 -y 40 -width 100 -height 20

entry $a.03 -textvariable "::mal" -font {arial 9}; place $a.03 -x 140 -y 70 -width 40 -height 20
button $a.04 -text "Max Length" -command "maxl" -font {arial 9} ; place $a.04 -x 10 -y 70 -width 100 -height 20

entry $a.05 -textvariable "::wa" -font {arial 9}; place $a.05 -x 140 -y 100 -width 40 -height 20
button $a.06 -text "Warpage" -command "warpage" -font {arial 9} ; place $a.06 -x 10 -y 100 -width 100 -height 20

entry $a.07 -textvariable "::as" -font {arial 9}; place $a.07 -x 140 -y 130 -width 40 -height 20
button $a.08 -text "Aspect" -command "aspect" -font {arial 9} ; place $a.08 -x 10 -y 130 -width 100 -height 20

entry $a.09 -textvariable "::sk" -font {arial 9}; place $a.09 -x 140 -y 160 -width 40 -height 20
button $a.10 -text "Skewness" -command "skew" -font {arial 9} ; place $a.10 -x 10 -y 160 -width 100 -height 20

entry $a.11 -textvariable "::ja" -font {arial 9}; place $a.11 -x 140 -y 190 -width 40 -height 20
button $a.12 -text "Jacobian" -command "jacob" -font {arial 9} ; place $a.12 -x 10 -y 190 -width 100 -height 20

entry $a.13 -textvariable "::miq" -font {arial 9}; place $a.13 -x 140 -y 220 -width 40 -height 20
button $a.14 -text "Min Angle Quad" -command "minq" -font {arial 9} ; place $a.14 -x 10 -y 220 -width 100 -height 20

entry $a.15 -textvariable "::maq" -font {arial 9}; place $a.15 -x 140 -y 250 -width 40 -height 20
button $a.16 -text "Max Angle Quad" -command "maxq" -font {arial 9} ; place $a.16 -x 10 -y 250 -width 100 -height 20

entry $a.17 -textvariable "::mit" -font {arial 9}; place $a.17 -x 140 -y 280 -width 40 -height 20
button $a.18 -text "Min Angle Tria" -command "mint" -font {arial 9} ; place $a.18 -x 10 -y 280 -width 100 -height 20

entry $a.19 -textvariable "::mat" -font {arial 9}; place $a.19 -x 140 -y 310 -width 40 -height 20
button $a.20 -text "Max Angle Tria" -command "maxt" -font {arial 9} ; place $a.20 -x 10 -y 310 -width 100 -height 20

#Creating label for 3D check:

label $a.002 -text "3D Element Check" -bg red -font {Arial 9 bold}; place $a.002 -x 200 -y 10 -width 170 -height 20

#creating entry box and button for 3D element check:

entry $a.21 -textvariable "::tet" -font {arial 9}; place $a.21 -x 330 -y 60 -width 40 -height 20
button $a.22 -text "Tet Collapse" -command "tetc" -font {arial 9} ; place $a.22 -x 200 -y 60 -width 100 -height 20

entry $a.23 -textvariable "::war3" -font {arial 9}; place $a.23 -x 330 -y 100 -width 40 -height 20
button $a.24 -text "Warpage" -command "warpage3d" -font {arial 9} ; place $a.24 -x 200 -y 100 -width 100 -height 20

entry $a.25 -textvariable "::asp3" -font {arial 9}; place $a.25 -x 330 -y 140 -width 40 -height 20
button $a.26 -text "Aspect" -command "aspect3d" -font {arial 9} ; place $a.26 -x 200 -y 140 -width 100 -height 20

#procedure for minimum length

proc minl {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestlength elements 1 $::mil 2 1 2 0 " Min length "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for maximum length

proc maxl {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestlength elements 1 $::mal 2 0 2 0 " Max length "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for warpage 2D

proc warpage {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestwarpage elements 1 $::wa 2 2 0 "Warpage"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure Aspect ration 2D

proc aspect {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestaspect elements 1 $::as 2 2 0 " Aspect"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for skewness

proc skew {} {
*clearmarkall 1
*clearmarkall 2
*createmark elements 1 "displayed"
*elementtestskew elements 1 $::sk 2 2 0 " Skew "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for jacobian

proc jacob {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $::ja 2 2 0 " Jacobian "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for minimum quad angle

proc minq {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $::miq 0 2 1 2 0 " Min angle Quad "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for maximum quand angle

proc maxq {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $::maq 0 2 0 2 0 " Max angle Quad"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for minimum tria angle

proc mint {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $::mit 1 2 1 2 0 " Min angle Tria "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for maximum trai angle

proc maxt {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $::mat 1 2 0 2 0 " Max angle Tria "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for tet collapse

proc tetc {} {
*clearmarkall 1
*clearmarkall 2
*createmark elements 1 "displayed"
*elementtesttetracollapse elements 1 $::tet 2 0 " 3D Tetra Collapse "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for warpage 3D

proc warpage3d {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestwarpage elements 1 $::war3 2 4 0 "3D Warpage"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}

#procedure for aspect ratio 3D

proc aspect3d {} {
*clearmarkall 1
*clearmarkall 2
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestaspect elements 1 $::asp3 2 4 0 " 3D Aspect Ratio "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

label $a.003 -text "Normals" -bg pink -font {Arial 9 bold }; place $a.003 -x 10 -y 360 -width 210 -height 20

button $a.27 -text " Reverse Normals" -font {Arial 9 } -command {*createmark elements 1 "displayed" ; *normalsreverse elements 1} ; place $a.27 -x 10 -y 390 -width 110 -height 20

button $a.28 -text " Normals Off" -font {Arial 9 } -command {*createmark elements 1 "displayed" ; *normalsoff} ; place $a.28 -x 130 -y 390 -width 90 -height 20

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

label $a.004 -text "EDGES" -bg green -font {Arial 9 bold }; place $a.004 -x 250 -y 360 -width 230 -height 20
# Adding procedure 1
proc FREE {} {
*setdisplayattributes 4 1


*createmark elements 1 "displayed"
*equivalence elements 1 0.01 0 0 0


*createmark elements 1 "displayed"
*equivalence elements 1 0.01 3 0 0


*createmark nodes 1
*nodemarkaddtempmark 1


*createmark elements 1 "displayed"
*findedges1 elements 1 0 0 0 30


*startnotehistorystate {Renamed Components from "^edges" to "Free Edges"}
*setvalue comps name=^edges name={Free Edges}


*createmark elements 1 "displayed"
*findedges1 elements 1 1 0 0 30


*startnotehistorystate {Renamed Components from "^edges" to "T edges"}
*setvalue comps name=^edges name={T edges}


*createmark components 1 "T edges"
*setvalue comps mark=1 color=#FFFF00
*clearmark components 1


*applydisplayattributes 4 1
*setcomponentdisplayattributes "T edges" 4 1
*setcomponentdisplayattributes "Free Edges" 4 1
*setcomponentdisplayattributes "T edges" 2 1
*setcomponentdisplayattributes "Free Edges" 2 1
}

#Creating button 1
button $a.29 -text "FREE EDGES" -command {FREE} -font {arial 9 } ; place $a.29 -x 250 -y 390 -width 90 -height 20

#Adding procedure 2

proc off {} {
*clearmark components 1
*createmark components 1 "Free Edges" "T edges"
*deletemark components 1


*setdisplayattributes 2 0
}
#Creating button 2

button $a.30 -text "TURN OFF EDGES" -command {off} -font {arial 9 } ; place $a.30 -x 350 -y 390 -width 130 -height 20

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

#assigning labels
label $a.005 -text " Final Checks" -bg cyan -font {arial 9 bold}; place $a.005 -x 390 -y 10 -width 260 -height 20
label $a.006 -text "DELETE ENTITIES" -bg gray -font {arial 9 } ; place $a.006 -x 390 -y 40 -width 260 -height 20
label $a.007 -text "DELETE EMPTY ENTITIES" -bg gray -font {arial 9 } ; place $a.007 -x 390 -y 100 -width 260 -height 20
label $a.008 -text "RE-ORDER" -bg gray -font {arial 9 }; place $a.008 -x 390 -y 160 -width 260 -height 20
label $a.009 -text "RE-NUMBER" -bg gray -font {arial 9 }; place $a.009 -x 390 -y 220 -width 260 -height 20
label $a.0010 -text "x-x-x-x-x-x-x-x-x-x-x" -bg gray -font {arial 9 }; place $a.0010 -x 390 -y 280 -width 260 -height 20
#assigning buttons and procedure:

# 1 DELETE
button $a.31 -text "Delete surfaces" -command {delete surfaces} -bg yellow -font {arial 9 }; place $a.31 -x 390 -y 70 -width 120 -height 20

button $a.32 -text "Delete solids" -command {delete solids} -bg yellow -font {arial 9 }; place $a.32 -x 540 -y 70 -width 110 -height 20

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

# 2 EMPTY

button $a.33 -text "Empty comps" -command {empty comps} -bg yellow -font {arial 9 }; place $a.33 -x 390 -y 130 -width 120 -height 20

button $a.35 -text "Empty Assembly" -command {empty assemblies} -bg yellow -font {arial 9 }; place $a.35 -x 540 -y 130 -width 110 -height 20


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

# 3 RE-ORDER

button $a.37 -text "Reorder Comps(Name)" -command {reorderbyname comps} -bg yellow -font {arial 8 }; place $a.37 -x 390 -y 190 -width 120 -height 20

button $a.38 -text "Reorder Comps(ID)" -command {reorderbyid comps} -bg yellow -font {arial 8}; place $a.38 -x 540 -y 190 -width 110 -height 20

proc reorderbyname {o} {
*clearmarkall 1
*createmark $o 1 "all"
if {[hm_marklength $o 1] !=0} {*collectormarkmove $o 1 1 1}
}
proc reorderbyid {o} {
*clearmarkall 1
*createmark $o 1 "all"
if {[hm_marklength $o 1] !=0} {*collectormarkmove $o 1 1 2}
}

# 4 RE- NUMBER

button $a.39 -text "Renumber Comps" -command {renumber comps} -bg yellow -font {arial 9 }; place $a.39 -x 390 -y 250 -width 120 -height 20

button $a.40 -text "Renumber Props" -command {renumber props} -bg yellow -font {arial 9}; place $a.40 -x 540 -y 250 -width 110 -height 20

proc renumber {n} {
*clearmarkall 1
*createmark $n 1 "all"
if {[hm_marklength $n 1] !=0} {*renumber $n 1 100 1 0 0 }
}

# 5 MASTER BUTTON

button $a.41 -text "MASTER" -command {master} -bg violet -font {Times 10 bold}; place $a.41 -x 450 -y 310 -width 130 -height 25

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

#creating collector
proc master {} {
delete surfaces
delete solids
empty comps
empty assemblies
reorderbyid comps
reorderbyname comps
renumber props
renumber comps
}

label $a.0011 -text "Collector" -bg blue -font {arial 10 bold }; place $a.0011 -x 250 -y 440 -width 100 -height 25
button $a.42 -text "Collectors" -font {arial 9} -command collectors ; place $a.42 -x 10 -y 475 -width 100 -height 20
button $a.43 -text "X locator" -font {arial 9} -command X_loc ; place $a.43 -x 120 -y 475 -width 100 -height 20
button $a.44 -text "Y locator" -font {arial 9} -command Y_loc ; place $a.44 -x 230 -y 475 -width 100 -height 20
button $a.45 -text "Z locator" -font {arial 9} -command Z_loc ; place $a.45 -x 340 -y 475 -width 100 -height 20
button $a.46 -text "Weld" -font {arial 9} -command Weld ; place $a.46 -x 450 -y 475 -width 100 -height 20

proc collectors {} {
*createmark components 1 "Weld" ;if {[hm_marklength comp 1] == 0} {*createentity components name = Weld}
*createmark components 1 "X_loc" ;if {[hm_marklength comp 1] == 0} {*createentity components name = X_loc}
*createmark components 1 "Y_loc" ;if {[hm_marklength comp 1] == 0} {*createentity components name = Y_loc}
*createmark components 1 "Z_loc" ;if {[hm_marklength comp 1] == 0} {*createentity components name = Z_loc}
}

proc Weld {} {
*clearmarkall 1
*clearmarkall 2
*currentcollector comp "Weld"
*createmarkpanel nodes 1 "select the nodes for spider web rep"
*rigidlinkinodecalandcreate 1 0 0 123456
}

proc X_loc {} {
*clearmarkall 1
*clearmarkall 2
*currentcollector comp "X_loc"
*createmarkpanel nodes 1 "select the primary node "
set prim_node [hm_getmark node 1]
*createmarkpanel nodes 1 "select the target node "
set targ_node [hm_getmark node 1]
*rigid $prim_node $targ_node 156
}

proc Y_loc {} {
*clearmarkall 1
*clearmarkall 2
*currentcollector comp "Y_loc"
*createmarkpanel nodes 1 "select the primary node "
set prim_node [hm_getmark node 1]
*createmarkpanel nodes 1 "select the target node "
set targ_node [hm_getmark node 1]
*rigid $prim_node $targ_node 246
}

proc Z_loc {} {
*clearmarkall 1
*clearmarkall 2
*currentcollector comp "Z_loc"
*createmarkpanel nodes 1 "select the primary node "
set prim_node [hm_getmark node 1]
*createmarkpanel nodes 1 "select the target node "
set targ_node [hm_getmark node 1]
*rigid $prim_node $targ_node 345
}

OUTPUT:

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.