Challenge

Week - 12 - Creating the locator, writing and reading the node data

Objective : 

1) To 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.

here we automate the process to connect two components with given type of connectors and and moving them to desired collector after creating them

# gui window to incorporate all buttons
set top .connector
catch {destroy $top}
toplevel $top -class Toplevel
wm geometry $top 250x300+100+100; update
wm title $top "connectors"
wm resizable $top 0 0
wm deiconify $top

# buttons to create different connectors
# create collectors button is left empty because we want to create collector if crated any type of connector
button $top.01 -text "create collectors" -command {} -font {times 12 bold}; place $top.01 -x 65 -y 10 -width 120 -height 40
button $top.02 -text "welds" -command {welds} -font {times 12 bold}; place $top.02 -x 65 -y 60 -width 120 -height 40
button $top.03 -text "X locator" -command {x_loc} -font {times 12 bold}; place $top.03 -x 65 -y 120 -width 120 -height 40
button $top.04 -text "Y locator" -command {y_loc} -font {times 12 bold}; place $top.04 -x 65 -y 170 -width 120 -height 40
button $top.05 -text "Z locator" -command {z_loc} -font {times 12 bold}; place $top.05 -x 65 -y 230 -width 120 -height 40


# procedure to create welds
proc welds {} {
*clearmarkall 1; *clearmarkall 2
*createmark comps 1 Welds
# to create collector and to move entities into it if collector already exists
if {[hm_marklength comps 1] == 0} {*createentity comps name=Welds color=3}
*currentcollector comps "Welds"; # to make it as current collector
# to select nodes for gui model
*createmarkpanel nodes 1 "select the nodes to create spider weld"
# to create spider weld with constraining al dof's
*rigidlinkinodecalandcreate 1 0 0 123456
}


proc x_loc {} {
*clearmarkall 1; *clearmarkall 2
*createmark comps 1 X_loc; if {[hm_marklength comps 1] == 0} {*createentity comp name=X_loc color=40}
*currentcollector comps "X_loc"
*createmarkpanel nodes 1 "select the source node"
set s_node [hm_getmark nodes 1]
*createmarkpanel nodes 2 "select the target node"
set t_node [hm_getmark nodes 2]
# to create rigid b/w two nodes and 156 represents constraining x-translational,(y,z) rotational dof's
*rigid $s_node $t_node 156}

proc y_loc {} {
*clearmarkall 1; *clearmarkall 2
*createmark comps 1 Y_loc; if {[hm_marklength comps 1] == 0} {*createentity comp name=Y_loc color=10}
*currentcollector comps "Y_loc"
*createmarkpanel nodes 1 "select the source node"
set s_node [hm_getmark nodes 1]
*createmarkpanel nodes 2 "select the target node"
set t_node [hm_getmark nodes 2]
*rigid $s_node $t_node 246}

proc z_loc {} {
*clearmarkall 1; *clearmarkall 2
*createmark comps 1 Z_loc; if {[hm_marklength comps 1] == 0} {*createentity comp name=Z_loc color=20}
*currentcollector comps "Z_loc"
*createmarkpanel nodes 1 "select the source node"
set s_node [hm_getmark nodes 1]
*createmarkpanel nodes 2 "select the target node"
set t_node [hm_getmark nodes 2]
*rigid $s_node $t_node 345}

2) To Create a macro that asks a text file as input and reads nodes from the file provided 

In this code we automate process of reading nodes from a txt file and to create nodes with the coordinates given from file 

proc read_nodes {} {
# tk_getOpenFile gui window to input a file
set filename [tk_getOpenFile -title "select node info file"]
set filechannelid [open $filename r]; # opened file in reading mode and its filechannelid is saved in variable
# to check if it is end of line
while {[eof $filechannelid] == 0} {
puts [set 1stnode_cord [gets $filechannelid]]
*createnode [lindex $1stnode_cord 0] [lindex $1stnode_cord 1] [lindex $1stnode_cord 2];
}
close $filechannelid
}
read_nodes

3) To Create a macro that accepts a geometric component as input from the user and shows potential duplicate geometries ( Geometries that match the surface count)

Here we write a code to automatically detect similar type components of the selected component

# to detect similar components
*clearmarkall 1 ; *clearmarkall 2
*createmark comps 1 "all"
set all_comp [hm_getmark comps 1]

# to count surfaces of each component
*clearmarkall 1; *clearmarkall 2
# unset all_comp_surf

# to count surfaces of given component and store it in list using lappend
foreach i $all_comp {
*createmark surfaces 1 "by comp id" $i
lappend all_comp_surf [hm_marklength surfaces 1]}

#to select target component
*clearmarkall 1; *clearmarkall 2
*createmarkpanel comps 1 "select the components you want to find"
set targ_comp [hm_getmark comps 1]
*isolateentitybymark 1 # to isolate a entity
*clearmarkall 1; *clearmarkall 2
*createmark surfaces 1 "by collector" $targ_comp
set targ_comp_surf [hm_marklength surfaces 1]
puts $targ_comp_surf
puts $all_comp_surf


*clearmarkall 1; *clearmarkall 2
# lsearch command used to search required data in a provided list and returns the positions of matching data
set match_list_comp [lsearch -all $all_comp_surf $targ_comp_surf]
puts "Match list componentcs are $match_list_comp"

# to display the detected components
foreach j $match_list_comp {
*clearmarkall 1; *clearmarkall 2
set comp_id [lindex $all_comp $j]
*showentity comps "by id" $comp_id; # to show entity
}

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.