Challenge

Week 12 Challenge

OBJECTIVE

  1. Connector :

Create a macro that builds a GUI containing 4 buttons. The window muist be having the buttons named Component creator, weld, xloc, yloc, zloc. Upon pressing the buttons corresponding 1D element must be created and moved to the desired collector.

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

  1. Identical comp identifier

Create a macro that accepts a geometric component as input from the user and shows potential duplicate geometries .We check for the surface counts of the components and thn the components with the same surface counts will be displayed after the execution of the code.

TCL CODE EXPLANATION

1) CONNECTOR

set a .window
catch { destroy $a }
toplevel $a -class Toplevel
wm title $a "Connector"
wm geometry $a 400x300+20+20
wm resizable $a 0 0
wm deiconify $a

proc comp_creation {} {
*createmark components 1 "Welds"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=Welds}
*createmark components 1 "x_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=x_loc}
*createmark components 1 "y_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=y_loc}
*createmark components 1 "Z_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=Z_loc}

}


proc weld {} {
*currentcollector components "Welds"
*elementtype 5 4
*createmarkpanel nodes 2 " Select the dependant nodes "
if { [hm_marklength nodes 2] !=0 } { *rigidlinkinodecalandcreate 2 0 1 123456 }
 }


proc x_loc {} {
*currentcollector components "x_loc"
*createmarkpanel nodes 1 "select the source nodes"
set source [hm_getmark nodes 1] 
if { [hm_marklength nodes 1 ] ==!0 } { *createmarkpanel nodes 2 "select the dest nodes" 
set dest [hm_getmark nodes 2]
*rigidlinkwithset_twonodes $dest $source 156 
} else { hm_exitpanel }
}

proc y_loc {} {
*currentcollector components "y_loc"
*createmarkpanel nodes 1 "select the source nodes"
set source [hm_getmark nodes 1]
if { [hm_marklength nodes 1 ] !=0 } { *createmarkpanel nodes 2 "select the dest nodes"
set dest [hm_getmark nodes 2]
*rigidlinkwithset_twonodes $dest $source 246
} else { hm_exitpanel }
}

proc z_loc {} {
*currentcollector components "Z_loc"
*createmarkpanel nodes 1 "select the source nodes"
set source [hm_getmark nodes 1]
if { [hm_marklength nodes 1 ] !=0 } { *createmarkpanel nodes 2 "select the dest nodes"
set dest [hm_getmark nodes 2]
*rigidlinkwithset_twonodes $dest $source 345
} else { hm_exitpanel }
}

button $a.01 -text "collector creation" -command { comp_creation } ; place $a.01 -x 25 -y 25
button $a.02 -text "Welds" -command { weld } ; place $a.02 -x 25 -y 75
button $a.03 -text "X Locator" -command { x_loc } ; place $a.03 -x 25 -y 125
button $a.04 -text "Y Locator" -command { y_loc } ; place $a.04 -x 25 -y 175
button $a.05 -text "Z Locator" -command { z_loc } ; place $a.05 -x 25 -y 225

proc comp_creation {} {
*createmark components 1 "Welds"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=Welds}
*createmark components 1 "x_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=x_loc}
*createmark components 1 "y_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=y_loc}
*createmark components 1 "Z_loc"
if {[hm_marklength components 1] == 0 } {*createentity comps cardimage=Part includeid=0 name=Z_loc}

}

This is the procedure creation of the creation of the component collectors in the model.First we ned to check for the null cases as we need to create the collectors named Welds, X_loc, Y_loc ,Z_loc we need to check whether the similarly named components are present in the model.For that we first create the mark of the component and then we check for marklength , if it is zero then we proced to create the collector using the *create entity command.

proc weld {} {
*currentcollector components "Welds"
*elementtype 5 4
*createmarkpanel nodes 2 " Select the dependant nodes "
if { [hm_marklength nodes 2] !=0 } { *rigidlinkinodecalandcreate 2 0 1 123456 }
}

This is the procedure for the creation of the weld elements which are the rigid 1 D elements. First we need to set the curent collector as the welds which we earlier created.This is done to ensure that the created elements to be created will be saved in the curent collector.

proc x_loc {} {
*currentcollector components "x_loc"
*createmarkpanel nodes 1 "select the source nodes"
set source [hm_getmark nodes 1]
if { [hm_marklength nodes 1 ] ==!0 } { *createmarkpanel nodes 2 "select the dest nodes"
set dest [hm_getmark nodes 2]
*rigidlinkwithset_twonodes $dest $source 156
} else { hm_exitpanel }

This is the procedure for creation of the X_locator which will have the degree of freedom restricted in X translation direction and the XY and XZ rotational directions. At first we made the current collector as X_loc then we need he input source nodes from the user, this is asked with the *createmarkpanel command.Then we save that nodes to a variable called source.Then if the marklength of the nodes is not zero, a set of actions needed to be which are to ask for the destination nodes,Then again that destination nodes will be saved in other variable called dest, then use the *rigidlinkwithset_twonodes $dest $source 156 command to create the 1D elements there. 156 implies the restricted degrees of freedom.If the marklength is zero then do the hm_exitpanel command which basically exits the garphics panel.

Similar code for the Y_loc and Z_loc.

button $a.01 -text "collector creation" -command { comp_creation } ; place $a.01 -x 25 -y 25
button $a.02 -text "Welds" -command { weld } ; place $a.02 -x 25 -y 75
button $a.03 -text "X Locator" -command { x_loc } ; place $a.03 -x 25 -y 125
button $a.04 -text "Y Locator" -command { y_loc } ; place $a.04 -x 25 -y 175
button $a.05 -text "Z Locator" -command { z_loc } ; place $a.05 -x 25 -y 22

Each procedure is assigned to a particular button in the GUI window and we place the buttons orderly in the window.

2) Identical Comp Identifier

proc detective {} {

*clearmarkall 1 ; *clearmarkall 2
*createmark components 1 "all"
set all_comp [hm_getmark components 1]
foreach i $all_comp {
*createmark surfaces 1 "by collector" $i
lappend all_comp_surf [hm_marklength surfaces 1]
}

*createmarkpanel components 2 "Select the components"
set target_comp [hm_getmark components 2]
*isolateentitybymark 2
puts "Target_com_id is $target_comp"

*createmark surfaces 2 "by collector" $target_comp
set target_comp_surf [hm_marklength surfaces 2 ]
set match_entity_list [ lsearch -all $all_comp_surf $target_comp_surf]

foreach j $match_entity_list {

set compid [lindex $all_comp $j]
set comp_name [hm_entityinfo name components $compid]
*displaycollectorwithfilter component "on" "$comp_name" 0 1 

}
}

detective;

Procedure with the name detective is started and inside that first created a mark for all the components and then we save the ids of all the components inside a variable named all_comp. then we need to check for surface count of all the components in the model and for this we need to create mark of the all_comp and then we need to get the marklength of the surfaces in the mark and then the surface counts need to be saved into a variable.This same thing needs to be done for each and every component in the model.

we use the lappend command to save the surface counts of each component.

*createmarkpanel components 2 "Select the components"
set target_comp [hm_getmark components 2]
*isolateentitybymark 2
puts "Target_com_id is $target_comp"

Her we ned to ask for the target component for which we need to find out the identical components.This is asked to the user through the *createmarkpanel command.Then we save the id to the variable called target_comp and then we isolate that component using the command *isolateentitybymark.

*createmark surfaces 2 "by collector" $target_comp
set target_comp_surf [hm_marklength surfaces 2 ]

By using the collector id we mark the target component and then we find out the surface count of the target component.

set match_entity_list [ lsearch -all $all_comp_surf $target_comp_surf]

with the use of lsrearch command we can find out the position of the component id in the all_com_surf list which is having the same surface count as the target component.

foreach j $match_entity_list {

set compid [lindex $all_comp $j]
set comp_name [hm_entityinfo name components $compid]
*displaycollectorwithfilter component "on" "$comp_name" 0 1

Using the lindex command on the all_comp list we can find out the ids of the component that have the same surface count as that of the target component.And then the other components need s to be display off by using the *displaycollectorwithfilter command and this is needs to be done for the entire components in the match_entity_list.So we use the foreach loop here.

3) Reading Nodes from a file

proc write_nodes {} {
*clearmarkall 1 ; *clearmarkall 2 
*createlistpanel nodes 1
set nodelist [hm_getlist nodes 1]
set filechannelid [ open write_nodes.csv w ]

foreach i $nodelist {
set info [hm_nodevalue $i]
puts $filechannelid [lindex $info 0]
}
close $filechannelid

}
write_nodes

This is the code for writing the nodes info into a file in csv fromat.First create a procedure to execute this process.

using the set filechannelid [ open write_nodes.csv w ] we open a file named write_nodes.csv and set to writting mode.And then we need to write the coordinate info of the selected nodes by the user.So we use hm_node value command for each node to set the XYZ coordinate values into a variable called info as a list.Then using the puts command and with the channelid specified we write that values into the file we opened.

proc read_nodes {} {

set filename [tk_getOpenFile ]
set filechannelid [open $filename r]

while {[eof $filechannelid] == 0} {
puts [ set 1st_nodecord [gets $filechannelid]]
*createnode [lindex $1st_nodecord 0] [lindex $1st_nodecord 1] [lindex $1st_nodecord 2]
}

close $filechannelid

}
read_nodes

This is the code for reading the nodes from the file. we first set the filename we need to open.For that the tcl/tk command tk_getOpenFile is used which will show thhe open window and dask the user to select the file having the nodes information.Then we set the file channel by opening the file in read mode.

Then we need the code to read the info in the file until its reaches the end of the file.So for that we use eof $filechhannelid , which basically gives as condition in the while loop and then the action needs to be done is puts [ set 1st_nodecord [gets $filechannelid]]

Using the gets command the file will be read by the code and the data in it will be set to the variable and thedata will be displayed in the command window.

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

This will create the nodes at the places whose cordinates given by the lindex command on the variable we just created and the 0 indicates the x file which is the first value , 1 indicates the Y value and the 2 indicates the Z value of the cordinates and these actions will be carrid out for the entire nodes info in the file until the file end reaches.

Then we closes the file .

CONCLUSION

These three codes will be having useful to be have . Placing th impactors to do the indendation test in plastic components in structural analaysis needs the placement of impactors at the certain locations .This can be done easily with the reading nodes macro.Since it can read out the file provided by the testing engineers to get the position of the nodes oat which the impactor needs tpo be placed.And the detectiv macro can find out the same similar components in the model.Even though some extra compoents may get detected by the code, it can show the similar components alos. So meshing becomes easier.since we can copy the mesh to similar components.

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.