Week - 12 - Creating the locator, writing and reading the node data
OBJECTIVE:
PART 1: Connector :
Create a macro that builds a GUI containing 4 buttons. Component creator, weld, xloc, yloc, zloc. Upon pressing the buttons corresponding 1D element must be created and moved to the desired collector.
PART 2 : Reading nodes from a file :
Create a macro that asks a .csv file as input and reads nodes from the file provided and also create tags for text in first column.
PART 3: Identical comp identifier
Create a macro that accepts a geometric component as input from the user and shows potential duplicate geometries ( Geometries that match the surface count)
PROCEDURE:
- Firstly create a GUI with buttons for welds create components, x y z -locators. Then create buttons to read node data and to create nodes. Also, create a button to search for matching surfaces.
- The program should also handle empty cases and warn the user.
- The lsearch command is used to search for identical components on the basis of the number of surfaces.
- *tagcreate command is used to create tags for the nodes.
CODE:
set a .window
catch {destroy $a}
toplevel $a -class toplevel
wm title $a "week 12"
wm geometry $a 230x320+200+200
#PART 1
button $a.01 -text "Create Components" -command "Create_Components" -bg yellow -font {times 12 bold}; place $a.01 -x 20 -y 30 -width 180 -height 30
button $a.02 -text "WELDS" -command "Create_weld" -bg yellow -font {times 12 bold}; place $a.02 -x 20 -y 70 -width 180 -height 30
button $a.03 -text "X-LOCATOR" -command "xlocator" -bg yellow -font {times 12 bold}; place $a.03 -x 20 -y 110 -width 180 -height 30
button $a.04 -text "Y-LOCATOR" -command "ylocator" -bg yellow -font {times 12 bold}; place $a.04 -x 20 -y 150 -width 180 -height 30
button $a.05 -text "Z-LOCATOR" -command "zlocator" -bg yellow -font {times 12 bold}; place $a.05 -x 20 -y 190 -width 180 -height 30
proc Create_Components {} {
if {[hm_entityinfo exist comps "Welds"] ==0} {*createentity comps name=Welds}
if {[hm_entityinfo exist comps "X_LOCATOR"] ==0} { *createentity comps name=X_LOCATOR}
if {[hm_entityinfo exist comps "Y_LOCATOR"] ==0} { *createentity comps name=Y_LOCATOR}
if {[hm_entityinfo exist comps "Z_LOCATOR"] ==0} { *createentity comps name=Z_LOCATOR}
}
proc Create_weld {} {
*clearmarkall 1;
*currentcollector comps "Welds"
*createmarkpanel nodes 1 "Select Nodes"
*rigidlinkinodecalandcreate 1 0 0 123456
}
proc xlocator {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "X_LOCATOR"
*createmarkpanel nodes 1 "Select First Node"
set s [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node"
set t [hm_getmark nodes 2]
*rigid $s $t 156
}
proc ylocator {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Y_LOCATOR"
*createmarkpanel nodes 1 "Select First Node"
set s [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node"
set t [hm_getmark nodes 2]
*rigid $s $t 246
}
proc zlocator {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Z_LOCATOR"
*createmarkpanel nodes 1 "Select First Node"
set s [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node"
set t [hm_getmark nodes 2]
*rigid $s $t 345
}
#PART 2
button $a.06 -text "READ NODE (.csv)" -command "read_n_data" -bg orange -font {times 12 bold}; place $a.06 -x 20 -y 230 -width 180 -height 30
proc read_n_data {} {
set fileChannelid [open [tk_getOpenFile -title "Select File"] r];
while {[eof $fileChannelid]==0} {
set n_row [gets $fileChannelid row]
if {$n_row > 0} {
set xyz [split $row ,];
set x [lindex $xyz 0]
set y [lindex $xyz 1]
set z [lindex $xyz 2]
*createnode $x $y $z
*createmark nodes 1 -1
set n_id [hm_getmark nodes 1]
*tagcreate nodes $n_id "$n_id"
}
}
close $fileChannelid;
}
#PART 3
button $a.07 -text "MATCH" -command "match" -bg blue -font {times 12 bold}; place $a.07 -x 20 -y 270 -width 180 -height 30
proc match {} {
*clearmarkall 1; *clearmarkall 2
*createmark comps 1 "all"
set a11_comp [hm_getmark comps 1];
foreach i $a11_comp {
*createmark surfaces 1 "by co11ector" $i
lappend a11_comp_surf [hm_marklength surfaces 1]
}
*createmarkpanel comps 2 "Select the geometric component of interest"
set target_comp [hm_getmark comp 2]
*isolateentitybymark 2
puts "Target comp id $target_comp"
*createmark surfaces 2 "by collector" $target_comp
puts [set target_comp_surf [hm_marklength surfaces 2]]
set match_list_surf [lsearch -all $a11_comp_surf $target_comp_surf]
puts "Match list surface $match_list_surf"
foreach j $match_list_surf {
set compid [lindex $a11_comp $j]
set comp_name [hm_entityinfo name comps $compid]
*displaycollectorwithfilter comps "on" "$comp_name" 0 1
}
}
GRAPHICAL USER INTERFACE:

CONCLUSION:
- Learned to create a GUI to help the user to read node data, search for similar components on the basis of the number of surfaces and to create welds, x, y, z locators.