Challenge

Creating macros for creating midlines and spotwelds in Hypermesh using TCL/TK

AIM: To create macros for Hypermesh using TCL/TK to create midlines between two line lists and spot welds between two node lists.

PROCEDURE:

PART A: Midlines:

To create midlines, the following code was prepared:

*clearmarkall 1; *clearmarkall 2
*createlistbypathpanel lines 1 "Select source lines by path"
set source [hm_getlist lines 1]
*createlistbypathpanel lines 2 "Select destination lines by path"
set target [hm_getlist lines 2]
*createlist nodes 1
*createlist nodes 2
set mid_list ""
foreach i $source j $target {
	*createlist lines 1 $i
	*createlist lines 2 $j
	*linescreatemidline 1 1 2 2
	*createmark lines 1 -1
	set mid [hm_getmark lines 1]
	lappend mid_list $mid}
set y [llength $mid_list]
*linecombine [lindex $mid_list 0] [lindex $mid_list 1]
*createmark lines 1 -1
set k [hm_getmark lines 1]
set x 2
while {$x<[expr $y]} {
	*linecombine [lindex $mid_list $x] $k 0
	*createmark lines 1 -1
	set k [hm_getmark lines 1]
	incr x}

The breakdown of the code is given below:

*createlistbypathpanel lines 1 "Select source lines by path"
set source [hm_getlist lines 1]
*createlistbypathpanel lines 2 "Select destination lines by path"
set target [hm_getlist lines 2]
*createlist nodes 1
*createlist nodes 2
set mid_list ""

A panel is created in which user can select lines by path. One panel is for source line and the second panel is for destination line. Each list is stored in variables "source" and "target" respectively. Two empty node lists 1 and 2 are created. Another variable "mid_list" is created which is empty but will later store the mid-lines that are generated in the foreach loop. The foreach loop is shown below:

foreach i $source j $target {
	*createlist lines 1 $i
	*createlist lines 2 $j
	*linescreatemidline 1 1 2 2
	*createmark lines 1 -1
	set mid [hm_getmark lines 1]
	lappend mid_list $mid}

For each line present in source and target, two lists are created for the respective line that is present in the loop. Then the midline is created using *linescreatemidline command. Then this line is added to a mark and set to variable "mid" which is also appended to the list "mid_list".

set y [llength $mid_list]
*linecombine [lindex $mid_list 0] [lindex $mid_list 1]
*createmark lines 1 -1
set k [hm_getmark lines 1]
set x 2

Variable "y" contains the length of the "mid_list". Then the first two lines in "mid_list" are combined which results in creating of another line. This new combined line is stored in variable "k". A variable "x" is set to 2 and will be used to manipulate in the upcoming while loop. The while loop is given below:

while {$x<[expr $y]} {
	*linecombine [lindex $mid_list $x] $k 0
	*createmark lines 1 -1
	set k [hm_getmark lines 1]
	incr x}

The condition is that "x" is lower than "y". Then the corresponding line in mid_list of index x is combined with line "k". Then the new line is stored in "k" again and updated in every while loop. Then the value of x is increased by 1 before the loop ends.

The code was used in the following component:

The lines on the side were selected for creating a mid line. The following mid line was achieved:

As can be seen from the greyish line, a suitable mid line was generated and the lines were also combined.

PART B: Spot Welds:

The code created for spot welds is shown below:

*clearmarkall 1; *clearmarkall 2
*createlistbypathpanel nodes 1 "Select source nodes by path"
set source [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select destination nodes by path"
set target [hm_getlist nodes 2]
*elementtype 5 1


proc collector {n k l} {
	*createentity comps includeid=0 name=$n
	foreach i $k j $l {
		*rigid $i $j 123456}}

set name [hm_getstring "Weld name" "Give name for the weld component"]
collector $name $source $target

The breakdown is as follows:

*clearmarkall 1; *clearmarkall 2
*createlistbypathpanel nodes 1 "Select source nodes by path"
set source [hm_getlist nodes 1]
*createlistbypathpanel nodes 2 "Select destination nodes by path"
set target [hm_getlist nodes 2]
*elementtype 5 1

Two panels are created for source and destination nodes respectively that the user can select by path. These nodes are stored in variables "source" and "target" respectively.

proc collector {n k l} {
	*createentity comps includeid=0 name=$n
	foreach i $k j $l {
		*rigid $i $j 123456}}

set name [hm_getstring "Weld name" "Give name for the weld component"]
collector $name $source $target

A procedure named "collector" is created which takes in three input variables "n", "k" and "l". It creates a new component of name "n" and a foreach loop is created for each node "i" and "j" in "k" and "l" respectively. Between the nodes, a rigid element is created.

The name for the component in which the spot welds will be stored is given by the user as a string. Then the procedure is called by giving appropriate variables as input which are the name of the weld component, the source nodes and the destination nodes.

The weld created is shown below:

CONCLUSION: The required macros for Hypermesh were successfully created using TCL/TK.

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.