Week - 12 - Creating the locator, writing and reading the node data
Objective:
- 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.
- 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.
- 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)
set a .window
catch {destroy $a}
toplevel $a -class top-level
wm title $a "Connector"
wm geometry $a 190x240+100+200
button $a.01 -text "Create Comps" -command "CreateComps" -bg grey -font {times 12 bold}; place $a.01 -x 20 -y 30 -width 150 -height 30
button $a.02 -text "Welds" -command "weldcreation" -bg grey -font {times 12 bold}; place $a.02 -x 20 -y 70 -width 150 -height 30
button $a.03 -text "X-Loc" -command "xloc" -bg grey -font {times 12 bold}; place $a.03 -x 20 -y 110 -width 150 -height 30
button $a.04 -text "Y-Loc" -command "yloc" -bg grey -font {times 12 bold}; place $a.04 -x 20 -y 150 -width 150 -height 30
button $a.05 -text "Z-Loc" -command "zloc" -bg grey -font {times 12 bold}; place $a.05 -x 20 -y 190 -width 150 -height 30
proc CreateComps {} {
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Welds"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Welds
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "X_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=X_Loc
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Y_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Y_Loc
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Z_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Z_Loc
}
}
proc weldcreation {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Welds"
*createmarkpanel nodes 2 "Select Nodes"
*rigidlinkinodecalandcreate 2 0 0 123456
}
proc xloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "X_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 156
}
proc yloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Y_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 246
}
proc zloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Z_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 345
}
2. Reading nodes from a file
proc read {} {
set filename [tk_getOpenFile -title "Select File"]
set fileid [open $filename r];
while {![eof $fileid]} {
set Coordinate [gets $fileid row]
if {$Coordinate > 0} {
set row [split $row ,];
set x [lindex $row 0]
set y [lindex $row 1]
set z [lindex $row 2]
*createnode $x $y $z
*createmark nodes 1 -1
set nid [hm_getmark nodes 1]
*tagcreate nodes $nid "$nid"
}
}
close $fileid;
}
read ;
3. Identical comp identifier
proc Cgeom {} {
*clearmarka11 1
*clearmarka11 2
*createmark comps 1 "a11"
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"
*creatmark surfaces 2 "by collector" $target_comp
puts [set target_comp_surf [hm_marklength surfaces 2]]
set match_list_surf [1search -a1l $a11_comp_surf $target_comp_surf]
puts "Match list surface $match_list_surf"
foreach j $match_list_surf {
set compid [1index $a11_comp $j]
set comp_name [hm_entityinfo name components $compid]
*displaycollectorwithfilter components "on" "$comp_name" 0 1
}
}
Cgeom;
TCL COMMAND EXPLANATION:-
1.Connector
set a .window
catch {destroy $a}
toplevel $a -class top-level
wm title $a "Connector"
wm geometry $a 190x240+100+200

button $a.01 -text "Create Comps" -command "CreateComps" -bg grey -font {times 12 bold}; place $a.01 -x 20 -y 30 -width 150 -height 30

button $a.02 -text "Welds" -command "weldcreation" -bg grey -font {times 12 bold}; place $a.02 -x 20 -y 70 -width 150 -height 30

button $a.03 -text "X-Loc" -command "xloc" -bg grey -font {times 12 bold}; place $a.03 -x 20 -y 110 -width 150 -height 30

button $a.04 -text "Y-Loc" -command "yloc" -bg grey -font {times 12 bold}; place $a.04 -x 20 -y 150 -width 150 -height 30

button $a.05 -text "Z-Loc" -command "zloc" -bg grey -font {times 12 bold}; place $a.05 -x 20 -y 190 -width 150 -height 30

# create comps button with command create comps
# welds creation button with command creating welds
# X-Locator button with command for creating xloc
# Y-Locator button with command for creating yloc
# Z-Locator button with command for creating zloc
proc CreateComps {} {
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Welds"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Welds
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "X_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=X_Loc
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Y_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Y_Loc
}
*clearmarkall 1;
*clearmarkall 2;
*createmark comps 1 "Z_Loc"
set id [hm_marklength comps 1]
if {$id!=1} {
*createentity comps name=Z_Loc
}
}
# clearing marked items
# creating comps collectors createcomps,X-Locator,Y-Locator,Z-Locator using checking with ids
proc weldcreation {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Welds"
*createmarkpanel nodes 2 "Select Nodes"
*rigidlinkinodecalandcreate 2 0 0 123456
}
# clearing marked items
# making the currentcollector as Welds
# selecting nodes using markpanel
# after selecting nodes, creating rigids with 6 dofs
proc xloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "X_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 156
}
# clearing marked items
# making the currentcollector as X-Locator
# selecting nodes using markpanel for independent and dependent nodes
# after selecting nodes, creating 1-1 rigid with x translatory and y &z rotational dofs
proc yloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Y_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 246
}
# clearing marked items
# making the currentcollector as Y-Locator
# selecting nodes using markpanel for independent and dependent nodes
# after selecting nodes, creating 1-1 rigid with y translatory and x &z rotational dofs
proc zloc {} {
*clearmarkall 1;
*clearmarkall 2;
*currentcollector components "Z_Loc"
*createmarkpanel nodes 1 "Select First Node - Independent Node"
set first [hm_getmark nodes 1]
*createmarkpanel nodes 2 "Select Second Node - Dependent Node"
set second [hm_getmark nodes 2]
*rigid $first $second 345
}
# clearing marked items
# making the currentcollector as Z-Locator
# selecting nodes using markpanel for independent and dependent nodes
# after selecting nodes, creating 1-1 rigid with z translatory and y &x rotational dofs
2. Reading nodes from a file
proc read {} {
set filename [tk_getOpenFile -title "Select File"]
set fileid [open $filename r];
while {![eof $fileid]} {
set Coordinate [gets $fileid row]
if {$Coordinate > 0} {
set row [split $row ,];
set x [lindex $row 0]
set y [lindex $row 1]
set z [lindex $row 2]
*createnode $x $y $z
*createmark nodes 1 -1
set nid [hm_getmark nodes 1]
*tagcreate nodes $nid "$nid"
}
}
close $fileid;
}
read ;
# making procedure for reading the csv file
# making the variable for opening the selected file
# make sure that keeping variable as opening and reading
# using while loop checking end of file with set name
# retrieving the first row of csv file
# if it was first , then the spliting the values with ","
# checking and creating the temp nodes in the existing opened
# marking nodes in each loop and creating tags
# after creating all rows and closing the file
3. Identical comp identifier
proc Cgeom {} {
*clearmarka11 1
*clearmarka11 2
# list of all comps
*createmark comps 1 "a11"
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]
}
# Input component
*createmarkpanel comps 2 "Select the geometric component of interest"
set target_comp [hm_getmark comp 2]
*isolateentitybymark 2
puts "Target comp id $target_comp"
*creatmark surfaces 2 "by collector" $target_comp
puts [set target_comp_surf [hm_marklength surfaces 2]]
set match_list_surf [1search -a1l $a11_comp_surf $target_comp_surf]
puts "Match list surface $match_list_surf"
foreach j $match_list_surf {
set compid [1index $a11_comp $j]
set comp_name [hm_entityinfo name components $compid]
*displaycollectorwithfilter components "on" "$comp_name" 0 1
}
}
Cgeom;


