Challenge

Tcl macro for cleaning up the meshed model

OBJECTIVE

We have the fully completed meshed model with us and before the delivery of the model we need to cleanup the model.Since we need to take the model to a solver for anlysis, we need to get rid of the empty entities , unused materials amd properties etc from the model. So manually doing this is a tedious tak, So a way to automate is really needed. We will be creating the codes for deleting the geometrical entities like points,lines,surfaces,solids,components etc.. Then also we need a reordering and renumbering of the ntities in the actual model at last according to the industry requirement.These activities are something which is doing the same thing again and again. So this can be automized by writing a general code and use it for every model.

At the end we will be creating a master button which will execute these series of activities in proper order.This button click will do all these activities.At the same time if we need to do all these activities individually , for that we will be setting the buttons for each step seperately.

PROBLEM STATEMENT

Entire Code

*clearmarkall 1
proc delete { a } {
*createmark $a 1 "displayed"
if {[ hm_marklength $a 1 ] != 0 } { *deletemark $a 1 }
}

proc deleteempty { a } {
*EntityPreviewEmpty $a 1 
if {[ hm_marklength $a 1 ] != 0 } {*deletemark $a 1 }
}

proc renumber_and_reorder {} {
*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } { *collectormarkmove components 1 0 1 }

*createmark elements 1 "all"
if {[ hm_marklength assemblies 1 ] != 0 } { *collectormarkmove assemblies 1 0 1 }

*createmark nodes 1 "all"
if {[ hm_marklength nodes 1 ] != 0 } {*renumbersolverid nodes 1 1 1 0 0 0 0 0 }

*createmark elements 1 "all"
if {[ hm_marklength elements 1 ] != 0 } {*renumbersolverid elements 1 1 1 0 0 0 0 0 }

*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } {*renumbersolverid components 1 1 1 0 0 0 0 0 }

*createmark materials 1 "all"
if {[ hm_marklength materials 1 ] != 0 } {*renumbersolverid materials 1 1 1 0 0 0 0 0 }

*createmark properties 1 "all"
if {[ hm_marklength properties 1 ] != 0 } {*renumbersolverid properties 1 1 1 0 0 0 0 0 }

}


proc master {} {
delete points
delete lines
delete surfaces
delete solids
delete components
deleteempty components
deleteempty assemblies
deleteempty loadcols
renumber_and_reorder

}

set a .window
catch { destroy $a }
toplevel $a -class Toplevel
wm title $a "Clean Up"
wm geometry $a 500x500+20+20 ; update
wm resizable $a 0 0
wm deiconify $a

button $a.01 -text "points" -command { delete points }; 					place $a.01 -x 30 -y 40
button $a.02 -text "lines" -command { delete lines }; 						place $a.02 -x 110 -y 40
button $a.03 -text "surfaces" -command { delete surfaces }; 				place $a.03 -x 190 -y 40
button $a.04 -text "solids" -command { delete solids }; 					place $a.04 -x 270 -y 40
button $a.05 -text "components" -command { delete components }; 			place $a.05 -x 340 -y 40

button $a.06 -text "Component" -command { deleteempty components } ;		place $a.06 -x 60 -y 150
button $a.07 -text "assemblies" -command { deleteempty assemblies } ; 		place $a.07 -x 170 -y 150
button $a.08 -text "Load collectors" -command { deleteempty loadcols } ; 	place $a.08 -x 280 -y 150

button $a.09 -text " reorder & renumber" -command {renumber_and_reorder} ; 	place $a.09 -x 40 -y 230

button $a.10 -text "Master Clean Up" -command {master}; 							place $a.10 -x 200 -y 400

*clearmarkall 1

This is to clear off any mark created in mark ID 1

proc delete { a } {
*createmark $a 1 "displayed"
if {[ hm_marklength $a 1 ] != 0 } { *deletemark $a 1 }
}

We need the geometric entities needs to be deleted and also for each geometric entity we need to create buttons for it also.So we create a procedure with name delete with a single input argument "a".Then in the body of the procedure we first create mark of the input entity which is displayed.After that we need to perform the deletemark operation.But since in case if the entity we asking is not in the display, then we nee to take care of the null case. For that we set the if condition in which the marklength of the the entity is not equal to zero ,then only we need the dletemark operation, otherwise this deletemark operation will niot be done.

proc deleteempty { a } {
*EntityPreviewEmpty $a 1
if {[ hm_marklength $a 1 ] != 0 } {*deletemark $a 1 }

This procedure is set to delete the entity which are empty in the model like empty componenets, empty assmbluies, empty loadcollectors etc..*EntityPreviewEmpty willl lokk for empty entity in the model and set it into the mark ID. Then like above we set the null case and delete that entity.

Then we need to create another procedure for reordering and renumbering.So for reordering the command *collectormarkmove is used and the syntax for it is *collectormarkmove entity_type mark_id move_to_front sort. So the entity type needs to be first defined and then the mak id and the sort = 1 means the marked entities are sorted by name .

Similarly same command setup for componenets too with the null case set up using the hm_,marklength not equal to zero, only then the delete operation needs to be done.

This taken care of the reordering of the entities, And then we ned to do the renumbering. For that the command used for that is *renumbersolverid .the syntax for this is *renumbersolverid entity_type mark_id start_id incr_val offset_val offset_flag reserved_1 reserved_2 reserved_3.

Everytime we need to create the mark of "all" entities in the model..Then use the *renumbersolverid and set the start_ID and Increment value as 1.

proc renumber_and_reorder {} {
*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } { *collectormarkmove components 1 0 1 }

*createmark assemblies 1 "all"
if {[ hm_marklength assemblies 1 ] != 0 } { *collectormarkmove assemblies 1 0 1 }

*createmark nodes 1 "all"
if {[ hm_marklength nodes 1 ] != 0 } {*renumbersolverid nodes 1 1 1 0 0 0 0 0 }

*createmark elements 1 "all"
if {[ hm_marklength elements 1 ] != 0 } {*renumbersolverid elements 1 1 1 0 0 0 0 0 }

*createmark components 1 "all"
if {[ hm_marklength components 1 ] != 0 } {*renumbersolverid components 1 1 1 0 0 0 0 0 }

*createmark materials 1 "all"
if {[ hm_marklength materials 1 ] != 0 } {*renumbersolverid materials 1 1 1 0 0 0 0 0 }

*createmark properties 1 "all"
if {[ hm_marklength properties 1 ] != 0 } {*renumbersolverid properties 1 1 1 0 0 0 0 0 }

}

Then for master key we need to create a new procedure master with no inputs required and inside the body call in the other procedures with the differant inputs like component,elements,nodes ,assemblies etc for delete and the componenets, assemblies etcc for deleteempty function and then call the renumber and reorder function.This master procedure should be call in the button command area.

set a .window
catch { destroy $a }
toplevel $a -class Toplevel
wm title $a "Clean Up"
wm geometry $a 500x500+20+20 ; update
wm resizable $a 0 0
wm deiconify $a

This code is usual for evry command window creation with the Clean Up as the title and nonresizable window.

button $a.01 -text "points" -command { delete points }; place $a.01 -x 30 -y 40
button $a.02 -text "lines" -command { delete lines }; place $a.02 -x 110 -y 40
button $a.03 -text "surfaces" -command { delete surfaces }; place $a.03 -x 190 -y 40
button $a.04 -text "solids" -command { delete solids }; place $a.04 -x 270 -y 40
button $a.05 -text "components" -command { delete components }; place $a.05 -x 340 -y 40

button $a.06 -text "Component" -command { deleteempty components } ; place $a.06 -x 60 -y 150
button $a.07 -text "assemblies" -command { deleteempty assemblies } ; place $a.07 -x 170 -y 150
button $a.08 -text "Load collectors" -command { deleteempty loadcols } ; place $a.08 -x 280 -y 150

button $a.09 -text " reorder & renumber" -command {renumber_and_reorder} ; place $a.09 -x 40 -y 230

button $a.10 -text "Master Clean Up" -command {master}; place $a.10 -x 200 -y 400

Button command is used to create the button inside the window and with the command as various procedure with differant inputs.We are creating seperate buttons for deleting points, lines,surfaces,solids and componenets. Also we are creating another set of buttons for delete the empty componenets,assemblies,loadcollector etcc.. And finally a button for reorder and renumber. And then the Master button also created.Place command allows us to set the button at differant area inside the window by varying the x and y cordinates.

Fig 1 Clean Up Window with the required Buttons

Conclusion

After the meshing is done , deleting the geometrical entities such as points,lines,surfaces,solids etc.. required quite an amount of time .And this process is quite tedious too.And also we ned to delete the empty collector , assemblies etc..This needs an automation.this is possible with the tcl code for hypermesh.And her we use tk to create the window and we use the tcl scripting to automize this proces and we create the buttons in the window to do the task we need to do in a single click of a button.

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.