Challenge

Automation Window for easy clean up of meshed model

Code

sset a .window
catch {destroy $a}
toplevel $a -class Toplevel
wm title $a "Automation Window"
wm geometry $a 300x950+30+30
wm resizable $a 0 0 ; update
wm deiconify $a



# normal reverse and Normal off
proc normal {} {
*clearmarkall 1 
*setnormalsdisplaytype 1
*createmark elements 1 "displayed"
*normalsdisplay elements 1 
*clearmarkall 1
*createmarkpanel elements 1 "Select the elements for which the normals to be reversed"
set ele [ hm_getmark elements 1 ]

if { $ele == {} } { 
puts " No element selected " 

*normalsoff} else {

*createmark elements 1 $ele

*normalsreverse elements 1
*createmark elements 1 "displayed"
*normalsdisplay elements 1
}

}

proc normaloff {} {
*createmark elements 1 "displayed"
*normalsdisplay elements 1
*normalsoff
}

label $a.03 -text "Normals" -bg white -font {times 9 bold} ;              			place $a.03 -x 30 -y 10
button $a.01 -text " Reverse Normal " -command { normal } -font {times 9 bold}; 							place $a.01 -x 30 -y 40
button $a.02 -text " Normals Off " -command { normaloff } -font {times 9 bold}; 							place $a.02 -x 180 -y 40


# free Edgees and T Edges

proc edges {} {

# display set to transparent mode
*setdisplayattributes 4 1

# Preview Equivalence
*createmark elements 1 "displayed"
*equivalence elements 1 0.01 0 0 0

# Save Preview Equivalence Nodes
*createmark elements 1 "displayed"
*equivalence elements 1 0.01 3 0 0

# Retrieving the equivlence nodes
*createmark nodes 1
*nodemarkaddtempmark 1

# Find Edges
*createmark elements 1 "displayed"
if { [hm_entityinfo exist comps Free_Edges ] == 0 } { *findedges1 elements 1 0 0 0 30 }

# Renaming Component
if { [hm_entityinfo exist comps Free_Edges ] == 0 } { *setvalue component name=^edges name=Free_Edges }

# T_Edges 
*createmark elements 1 "displayed"
if { [hm_entityinfo exist comps T_Edges ] == 0 } {*findedges1 elements 1 1 0 0 30 }

# Renaming Component
if { [hm_entityinfo exist comps T_Edges ] == 0 } { *setvalue comps name=^edges name=T_Edges } 

# Changing Color of Free_Edges

*createmark components 1 "Free_Edges"
*setvalue comps mark=1 color=3
*createmark components 1 "Free_Edges"
*clearmark components 1

# Changing Color of T_Edges

*createmark components 1 "T_Edges" 
*setvalue comps mark=1 color=30
*createmark components 1 "T_Edges"
*clearmark components 1

# Changing to Solid Rep

*setcomponentdisplayattributes "T_Edges" 2 1 
*setcomponentdisplayattributes "Free_Edges" 2 1
}

proc Edges_Off {} {
*createmark components 1  "Free_Edges" "T_Edges"
if { [hm_marklength comps 1 ]!= 0 } {*deletemark comps 1}
*setdisplayattributes 2 0
}

label $a.06 -text "Free Edges & T Edges" -bg white -font {times 9 bold} ;              			place $a.06 -x 30 -y 82
button $a.04 -text "Edges " -command { edges } -font {times 9 bold}; 									place $a.04 -x 30 -y 110
button $a.05 -text " Edges Off " -command { Edges_Off } -font {times 9 bold}; 							place $a.05 -x 180 -y 110


# Creating Collectors
proc collector {} {
set name [ hm_getstring "components ="  "Enter the name followed by _" ] 
set t [ hm_getstring "thickness="  "Enter the value of the thickness" ] 
set sol [hm_getsolver id]             
if { $sol == 1 } {

*createentity comps includeid=0 name=$name$t
*createmark comps 1 $name$t
set compid [ hm_getmark comps 1 ]
if { [hm_marklength comps 1 ] !=0 } {*createentity props cardimage=PSHELL includeid=0 name=$name$t }
*createmark props 2 $name$t
set propid [ hm_getmark props 2 ]
*setvalue props id=$propid STATUS=1 95=$t
*setvalue comps id=$compid propertyid={props $propid}
*autocolor comps
}

if { $sol == 20 } {

*createentity comps cardimage=Part includeid=0 name= $name$t
*createmark comps 1 $name$t
set compid [hm_getmark comps 1 ]
if { [hm_marklength comps 1 ] !=0 } { *createentity props cardimage=P1_SHELL includeid=0 name=$name$t 
*createmark props 1 $name$t
set propid [hm_getmark props 1 ]
*setvalue props id=$propid STATUS=1 431=$t
*setvalue comps id=$compid propertyid={props $propid}
*autocolor props
}
}
}

label $a.07 -text "Collector Creation" -bg white -font {times 9 bold} ;             place $a.07 -x 30 -y 150
button $a.08 -text " Create " -command { collector }; 								place $a.08 -x 50 -y 180


# Reflect

proc nastran { name t } {

*createentity comps includeid=0 name=$name
*createmark comps 1 $name
set compid [ hm_getmark comps 1 ]
*createentity props cardimage=PSHELL includeid=0 name=$name
*createmark props 2 $name
set propid [ hm_getmark props 2 ]
*setvalue props id=$propid STATUS=1 95=$t
*setvalue comps id=$compid propertyid={props $propid}
*autocolor comps
}

 
proc radioss { name t } {

*createentity comps cardimage=Part includeid=0 name= $name
*createmark comps 1 $name
set compid [hm_getmark comps 1 ]
*createentity props cardimage=P1_SHELL includeid=0 name=$name
*createmark props 1 $name	
set propid [hm_getmark props 1 ]
*setvalue props id=$propid STATUS=1 431=$t
*setvalue comps id=$compid propertyid={props $propid}
*autocolor props

}

proc Reflect {} {

# inputs
*clearmarkall 1 ; *clearmarkall 2 
set name [hm_getstring Component_name "Enter the name of the component followed by _"]
if { $name == {} } { 
hm_exitpanel 
} else {
*createmarkpanel comps 1 "select the component containing orginal geometry to be reflected" 
set o_gom [hm_getmark comps 1 ]
*createmarkpanel comps 1 " Select the componenet containing the target geometry "
set t_gom [ hm_getmark comps 1]
*createmarkpanel comps 1 " Select the component having the Fe entities that you want to reflect "
set o_fea [ hm_getmark comps 1 ]
set profile [ hm_info templatetype ]

foreach i $o_fea {
set t [hm_getthickness comps $i ]
set old_n [ hm_entityinfo name comps $i ]
set n $name$t
$profile $n $t
*createmark elements 1 $old_n
*copymark elements 1 $n
*displaycollectorwithfilter components "off" "$old_n" 1 0

}

*createmark comps 2 "displayed"
*autocolorwithmark components 2 

# creating centroids

*clearmarkall 1 ; *clearmarkall 2 
*createmark surfaces 1 "by collector" $o_gom 
if { [hm_marklength surfaces 1 ] != 0 } { 
set o_cog [hm_getcentroid surfaces 1 ] 

*createnode [lindex $o_cog 0] [lindex $o_cog 1] [lindex $o_cog 2] 0

*createmark node 2 -1
set o_node [hm_getmark node 2]


*createmark surfaces 1 "by collector" $t_gom
if { [hm_marklength surfaces 1 ] != 0 } { 
set t_cog [hm_getcentroid surfaces 1] 
*createnode [lindex $t_cog 0] [lindex $t_cog 1] [lindex $t_cog 2] 0
*createmark node 2 -1

set t_node [hm_getmark node 2]


# creating intercepts

set intercepts [ hm_getdistance nodes $o_node $t_node 0 ]
*clearmarkall 1 ;

*createnodesbetweennodes $o_node $t_node 1
*createmark node 1 -1
set m_node [hm_getmark node 1]
set m_node_info [ hm_nodevalue $m_node]



# reflecting the entities

*clearmarkall 1 ; *clearmarkall 2
*createmark elements 1 "displayed"
*createplane 1 [lindex $intercepts 1] [lindex $intercepts 2] [lindex $intercepts 3] [lindex $m_node_info 0 0] [lindex $m_node_info 0 1] [lindex $m_node_info 0 2]

*reflectmarkwithoption elements 1 1 0

# equivalence

*clearmarkall 1 ; *clearmarkall 2 
*createmark component 1 "displayed"
*equivalence components 1 0.01 1 0 0
}
}
}
}
label $a.09 -text "Mesh Reflect" -bg white -font {times 9 bold} ;              		place $a.09 -x 30 -y 220
button $a.10 -text " Reflect " -command { Reflect }; 						   		place $a.10 -x 50 -y 250


# Element Quality checks

label $a.52 -text "Element Quality Check" -bg white -font {times 9 bold} ;           place $a.52 -x 30 -y 290
entry $a.11 -textvariable w ;	 	place $a.11 -x 130 -y 330
entry $a.12 -textvariable as ; 		place $a.12 -x 130 -y 360
entry $a.13 -textvariable j ; 		place $a.13 -x 130 -y 390
entry $a.14 -textvariable s ; 		place $a.14 -x 130 -y 420
entry $a.15 -textvariable mil ;	 	place $a.15 -x 130 -y 450
entry $a.16 -textvariable mal ; 	place $a.16 -x 130 -y 480
entry $a.17 -textvariable mit ; 	place $a.17 -x 130 -y 510
entry $a.18 -textvariable mat ; 	place $a.18 -x 130 -y 540
entry $a.19 -textvariable miq ; 	place $a.19 -x 130 -y 570
entry $a.20 -textvariable maq ; 	place $a.20 -x 130 -y 600
entry $a.50 -textvariable tet ; 	place $a.50 -x 130 -y 630

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


proc aspect { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*createmark elements 2
*elementtestaspect elements 1 $a 2 2 0 " 2D Aspect Ratio "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc jacobian { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestjacobian elements 1 $a 2 2 0 "Jacobian"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc skew { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestskew elements 1 $a 2 2 0 "Skewness"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}
proc minl { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestlength elements 1 $a 2 1 2 0 "Minl"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}
proc maxl { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestlength elements 1 $a 2 0 2 0 "Maxl"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc mintria { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $a 2 2 2 2 0 "Minangle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1
*unmaskall2
}
proc maxtria { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $a 2 2 0 2 0 "Maxangle"
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc minquad { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $a 0 2 1 2 0 " Min quad Angle "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc maxquad { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtestinterangle elements 1 $a 0 2 0 2 0 " Max Angle quad "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

proc tetcollapse { a } {
*nodecleartempmark
*createmark elements 1 "displayed"
*elementtesttetracollapse elements 1 $a 2 0 " Max Angle quad "
*maskentitymark elements 2 0
*maskreverse elements
*createmark nodes 1 "displayed"
*nodemarkaddtempmark 1 
*unmaskall2
}

button $a.21 -text "Warpage" -command { warpage $w } -font {times 7 bold }					; place $a.21 -x 10 -y 329
button $a.22 -text "Aspect Ratio" -command { aspect $as } -font {times 7 bold } 			; place $a.22 -x 10 -y 359
button $a.23 -text "Jacobian" -command { jacobian $j  } -font {times 7 bold } 				; place $a.23 -x 10 -y 389 
button $a.24 -text "Skew" -command {skew $s } -font {times 7 bold } 						;place $a.24 -x 10 -y 419
button $a.25 -text "Min Length" -command {minl $mil } -font {times 7 bold } 				; place $a.25 -x 10 -y 449 
button $a.26 -text "Max Length" -command {maxl $mal } -font {times 7 bold } 				; place $a.26 -x 10 -y 479 
button $a.27 -text "Min Angle Tria" -command { mintria $mit } -font {times 7 bold } 		; place $a.27 -x 10 -y 509 
button $a.28 -text "Max Angle Tria" -command { maxtria $mat } -font {times 7 bold }			; place $a.28 -x 10 -y 539
button $a.29 -text "Min Angle Quad" -command { minquad $miq } -font {times 7 bold } 		; place $a.29 -x 10 -y 569
button $a.30 -text "Max Angle Quad" -command { maxquad $maq } -font {times 7 bold } 		; place $a.30 -x 10 -y 599
button $a.31 -text "Tet Collapse" -command { tetcollapse $tet } -font {times 7 bold } 		; place $a.31 -x 10 -y 629

#deleting empty and Unused

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

}


proc close_panel {} {
hm_exitpanel
}

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

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

proc renumber_and_reorder {} {
*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } { *collectormarkmove components 1 0 1 }

*createmark assemblies 1 "all"
if {[ hm_marklength assemblies 1 ] != 0 } { *collectormarkmove assemblies 1 0 1 }

*createmark nodes 1 "all"
if {[ hm_marklength nodes 1 ] != 0 } {*renumbersolverid nodes 1 1 1 0 0 0 0 0 }

*createmark elements 1 "all"
if {[ hm_marklength elements 1 ] != 0 } {*renumbersolverid elements 1 1 1 0 0 0 0 0 }

*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } {*renumbersolverid components 1 1 1 0 0 0 0 0 }

*createmark materials 1 "all"
if {[ hm_marklength materials 1 ] != 0 } {*renumbersolverid materials 1 1 1 0 0 0 0 0 }

*createmark properties 1 "all"
if {[ hm_marklength properties 1 ] != 0 } {*renumbersolverid properties 1 1 1 0 0 0 0 0 }

}



label $a.32 -text "Clean Up Empty" -bg white -font {times 9 bold} ;              				place $a.32 -x 30 -y 664
button $a.33 -text "Component" -command { deleteempty comps } -font {times 7 bold } 		; 	place $a.33 -x 10 -y 694
button $a.34 -text "Assemblies" -command {  deleteempty assemblies } -font {times 7 bold } 	; 	place $a.34 -x 10 -y 724
label $a.35 -text "Clean Up Unused" -bg white -font {times 9 bold} ;              				place $a.35 -x 30 -y 754
button $a.36 -text "Materials" -command {  unused mats } -font {times 7 bold } 				; 	place $a.36 -x 10 -y 784
button $a.37 -text "Properties" -command {  unused props } -font {times 7 bold } 		; 		place $a.37 -x 10 -y 814
label $a.39 -text "Delete Entities" -bg white -font {times 9 bold} ;              				place $a.39 -x 30 -y 844
button $a.38 -text "Points" -command {  delete points } -font {times 7 bold } 		; 			place $a.38 -x 10 -y 874
button $a.40 -text "lines" -command {  delete lines } -font {times 7 bold } 		; 			place $a.40 -x 10 -y 904	
button $a.100 -text "Close HM Panel" -command { close_panel } -font {times 7 bold } 		; 	place $a.100 -x 180 -y 784

Automation Tk GUI Window

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.