Challenge

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

AIM: Creating the locator, writing and reading the node data using tcl/tk script

OBJECTIVE: The objective of this challenge is to:

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

2. Create a macro that asks a .csv file as input and reads nodes from the file provided and creates tags for text in the first column.

3. 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:

1. To perform the given task, open any code editor ( here we use Notepad++) and type a code as follows:

# Code to create a GUI containing 4 buttons: Component creator, weld, xloc, yloc, zloc

set a .connector

catch {destroy $a}

toplevel $a -class TopLevel

wm title $a "connectors"

wm geometry $a 250x280+50+50; update

wm resizable $a 0 0

wm deiconify $a 

This code creates a new window in hypermesh having name as “connectors” and having geometry of 250x280.

# buttons

button $a.01 -text "Collectors" -command {create} -font {times 12 bold}

place $a.01 -x 65 -y 10 -width 120 -height 40

button $a.02 -text "Welds" -command {weld} -font {times 12 bold}

place $a.02 -x 65 -y 60 -width 120 -height 40

button $a.03 -text "X Locator" -command {X_Loc} -font {times 12 bold}

place $a.03 -x 65 -y 110 -width 120 -height 40

button $a.04 -text "Y Locator" -command {Y_Loc} -font {times 12 bold}

place $a.04 -x 65 -y 160 -width 120 -height 40

button $a.05 -text "Z Locator" -command {Z_Loc} -font {times 12 bold}

place $a.05 -x 65 -y 210 -width 120 -height 40

proc create {} {

*clearmarkall 1; *clearmarkall 2;

*createmark component 1 Welds;

if {[hm_marklength components 1] == 0} {*createentity component name = Welds Color=3}

*createmark component 1 X_Loc;

if {[hm_marklength components 1] == 0} {*createentity component name = X_Loc Color=56}

*createmark component 1 Y_Loc;

if {[hm_marklength components 1] == 0} {*createentity component name = Y_Loc Color=5}

*createmark component 1 Z_Loc;

if {[hm_marklength components 1] == 0} {*createentity component name = Z_Loc Color=6}

proc weld {} {

*clearmarkall 1; *clearmarkall 2;

*currentcollector components "Welds"

*createmarkpanel nodes 2 "Select all nodes for creating spider weld"

*rigidlinkinodecalandcreate 2 0 0 123456

}

proc X_Loc {} {

*clearmarkall 1; *clearmarkall 2;

*currentcollector components "X_Loc"

*createmarkpanel nodes 1 "Select source node for spot weld"

set source_node [hm_getmark nodes 1]

*createmarkpanel nodes 2 "Select target node for spot weld"

set target_node [hm_getmark nodes 2]

*rigid $source_node $target_node 156

}

proc Y_Loc {} {

*clearmarkall 1; *clearmarkall 2;

*currentcollector components "Y_Loc"

*createmarkpanel nodes 1 "Select source node for spot weld"

set source_node [hm_getmark nodes 1]

*createmarkpanel nodes 2 "Select target node for spot weld"

set target_node [hm_getmark nodes 2]

*rigid $source_node $target_node 246

}

proc Z_Loc {} {

*clearmarkall 1; *clearmarkall 2;

*currentcollector components "Z_Loc"

*createmarkpanel nodes 1 "Select source node for spot weld"

set source_node [hm_getmark nodes 1]

*createmarkpanel nodes 2 "Select target node for spot weld"

set target_node [hm_getmark nodes 2]

*rigid $source_node $target_node 345

}

}

create;

# Code that asks a .csv file as input and reads nodes from the file provided and creates tags for text in the first column

proc read_nodes {} {

  set filename [tk_getOpenFile -title "Select node info file"]

  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;

proc write_nodes {} {

*clearmarkall 1; *clearmarkall 2;

*createlistpanel nodes 1

set nodelist [hm_getlist nodes 1];

set filechannelid [open write_nodes w]

foreach i $nodelist {

   set info [hm_nodevalue $i]

   puts $filechannelid [lindex $info 0]

   }

close $filechannelid

}

write_nodes;

# Code that accepts a geometric component as input from the user and shows potential duplicate geometries ( Geometries that match the surface count)

proc identical {} {

*clearmarkall 1; *clearmarkall 2;

#list of all components

*createmark components 1 "all"

set all_comp [hm_getmark comps 1];

*clearmarkall 1; *clearmarkall 2;

#list of all surfaces

foreach i $all_comp {

   *createmark surfaces 1 "by collector" $i

   lappend all_comp_surf [hm_marklength surfaces 1]

   }

*clearmarkall 1; *clearmarkall 2;

#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"

*clearmarkall 1; *clearmarkall 2;

*createmark surfaces 2 "by collector" $target_comp

puts [set target_comp_surf [hm_marklength surfaces 2]]

*clearmarkall 1; *clearmarkall 2;

set match_list_surf [lsearch -all $all_comp_surf $target_comp_surf]

puts "Match list surfaces $match_list_surf"

foreach j $match_list_surf {

*clearmarkall 1;

set compid [lindex $all_comp $j]

set comp_name [hm_entityinfo name components $compid]

*displaycollectorwithfilter components "on" "$comp_name" 0 1

}

}

identical; 

2. After writing the code save the file.

3. Then open any model in hypermesh and run this file in hypermesh using shortcut key assign to it.

4. After running these codes in hypermesh, following results will appear:

TCL COMMAND EXPLANATION:

1. hm_marklength: Returns the number of entities on the specified mark

2. *createentity: Create a new entity with specified data. Data names only are allowed to be set. If the data name “name” is specified when creating an entity enabled for the name pool, the command uses the provided name to define the solver name.

There are also a few limitations to this command:

I. Attributes are not supported.

II. STATUS is not supported.

3. *currentcollector: Sets the current collector

4. *createmarkpanel: Provides a panel to add entities to a mark

5. *rigidlinkinodecalandcreate: Creates a rigidlink elem by calculating the independent node based on selection of dependent nodes. Location of independent nodes will be at the geometric center of dependent nodes.

6. *rigid: Creates a rigid element between two nodes

7. *createlistpanel: Provides a panel to create an ordered list of entities for use in a subsequent command.

8. hm_getlist: Returns an ordered list of entities from an entity list

9. *isolateentitybymark: Turns on the display of a mark of entities and turns off the display of all others of the same type

10. hm_entityinfo: Returns various information on entities

11. *displaycollectorwithfilter: Changes the active state of a collector using the menu filter

CONCLUSION: After executing proper tcl/tk code,

1. We are able to build a GUI containing 4 buttons and upon pressing the buttons corresponding 1D element must be created and moved to the desired collector

2. We are able to create a macro that asks a .csv file as input and reads nodes from the file provided and creates tags for text in the first column

3. We are able to create a macro that accepts a geometric component as input from the user and shows potential duplicate geometries

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.