{"id":8057,"date":"2025-02-20T01:05:13","date_gmt":"2025-02-20T09:05:13","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=8057"},"modified":"2025-02-20T01:06:16","modified_gmt":"2025-02-20T09:06:16","slug":"458-hypermesh-tcl-script-to-save-selected-node-ids-and-coordinates-to-a-csv-file","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2025\/02\/458-hypermesh-tcl-script-to-save-selected-node-ids-and-coordinates-to-a-csv-file\/","title":{"rendered":"#458 HyperMesh tcl script to save selected node IDs and coordinates to a csv file"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2025\/02\/458-hypermesh-tcl-script-to-save-selected-node-ids-and-coordinates-to-a-csv-file\/2025-02-20_005944\/\" rel=\"attachment wp-att-8058\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=1080%2C584&#038;ssl=1\" alt=\"\" width=\"1080\" height=\"584\" class=\"alignnone size-full wp-image-8058\" srcset=\"https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png 1884w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944-1280x692.png 1280w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944-980x530.png 980w, https:\/\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944-480x259.png 480w\" sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) and (max-width: 980px) 980px, (min-width: 981px) and (max-width: 1280px) 1280px, (min-width: 1281px) 1884px, 100vw\" \/><\/a><\/p>\n<p>In this example, we create n=40 random nodes, select several of them, and save their node IDs and coordinates in a csv file.<\/p>\n<pre class=\"lang:python decode:true \" >proc RandomReal {min max} {\n  return [expr (rand()*($max-$min)+$min)]\n}\n\nset x_min 0.0\nset x_max 20.0\n\nset y_min 0.0\nset y_max 10.0\n\nset n 40\nfor {set i 0} {$i &lt; $n} {incr i} {\n    set x [RandomReal $x_min $x_max]\n    set y [RandomReal $y_min $y_max]\n    *createnode $x $y 0 0 0 0\n}\n\n*window 0 0 0 0 0\n*createmark nodes 1 \"all\"\n*numbersmark nodes 1 1\n*clearmark nodes 1\n\nset script_path [ file dirname [ file normalize [ info script ] ] ]\nputs $script_path\ncd $script_path\n\nset output_file \"node_coordinates.csv\"\nset file_id [open $output_file \"w\"]\nputs $file_id \"node_id,x,y,z\"\n*clearmark nodes 1\n*createmarkpanel nodes 1 \"Select nodes\"\nset selected_nodes [hm_getmark nodes 1]\nif {[llength $selected_nodes] == 0} {\n    puts \"\"\n    close $file_id\n    return\n}\nforeach node_id $selected_nodes {\n    set x [hm_getvalue node id=$node_id dataname=x]\n    set y [hm_getvalue node id=$node_id dataname=y]\n    set z [hm_getvalue node id=$node_id dataname=z]\n    puts \"$node_id,$x,$y,$z\"\n    puts $file_id \"$node_id,$x,$y,$z\"\n}\nclose $file_id\n*clearmark nodes 1<\/pre>\n<p>node_coordinates.csv<\/p>\n<pre class=\"lang:python decode:true \" >node_id,x,y,z\n1,6.2778236187426,5.6907801030626,0\n7,17.483855382299,5.5787051495065,0\n15,16.562761429959,5.1656766632412,0\n26,7.1378922309437,3.2773627356055,0\n32,12.051626486728,5.8431812170163,0\n38,13.621047313149,4.4710960446257,0\n40,6.4036964282411,3.4629347238051,0<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In this example, we create n=40 random nodes, select several of them, and save their node IDs and coordinates in a csv file. proc RandomReal {min max} { return [expr (rand()*($max-$min)+$min)] } set x_min 0.0 set x_max 20.0 set y_min 0.0 set y_max 10.0 set n 40 for {set i 0} {$i &lt; $n} {incr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","_lmt_disableupdate":"yes","_lmt_disable":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[24,27],"tags":[23,43],"class_list":["post-8057","post","type-post","status-publish","format-standard","hentry","category-hypermesh","category-tcl","tag-hypermesh","tag-tcl"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-25X","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":6260,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/11\/452-save-selected-nodes-coordinates-to-csv-file-in-tcl-for-hypermesh\/","url_meta":{"origin":8057,"position":0},"title":"#452 Save selected nodes coordinates to*.csv file in tcl for HyperMesh","author":"gantovnik","date":"2024-11-26","format":false,"excerpt":"set script_path [ file dirname [ file normalize [ info script ] ] ] puts $script_path set output_file [file join $script_path \"nodes.csv\"] set file_id [open $output_file \"w\"] puts $file_id \"node_id,x,y,z\" *clearmark nodes 1 *createmarkpanel nodes 1 \"Select Nodes\" set selected_nodes [hm_getmark nodes 1] if {[llength $selected_nodes] == 0} { puts\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2032,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/403-get-nodes-for-all-elements-in-the-fem-model-in-hypermesh-using-tcl-script\/","url_meta":{"origin":8057,"position":1},"title":"#403 Get nodes for all elements in the FEM model in HyperMesh using tcl script","author":"gantovnik","date":"2024-01-13","format":false,"excerpt":"ex403.tcl Output file: ex403.txt","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1733,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/12\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-2-4-2\/","url_meta":{"origin":8057,"position":2},"title":"#328 Add labels with node coordinates using HyperMesh Tcl","author":"gantovnik","date":"2022-12-14","format":false,"excerpt":"nodes.txt create_nodes.tcl","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex328.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex328.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex328.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":1727,"url":"https:\/\/gantovnik.com\/bio-tips\/2022\/12\/210-parametric-curve-in-3d-2-2-2-2-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-3-2-2-2-2-2-2-2-2-2-2-4\/","url_meta":{"origin":8057,"position":3},"title":"#327 Creates nodes with coordinates from text file using HyperMesh Tcl","author":"gantovnik","date":"2022-12-14","format":false,"excerpt":"nodes.txt create_nodes.tcl","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2022\/12\/ex327.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":943,"url":"https:\/\/gantovnik.com\/bio-tips\/2021\/09\/170-gets-the-distance-of-the-given-point-from-the-nearest-line-with-ids-specified-as-arguments-in-hypermesh-tcl\/","url_meta":{"origin":8057,"position":4},"title":"#170 Gets the distance of the given point from the nearest line with IDs specified as arguments in HyperMesh tcl","author":"gantovnik","date":"2021-09-01","format":false,"excerpt":"#170 Gets the distance of the given point from the nearest line with IDs specified as arguments in HyperMesh tcl. To get closest to the point with coordinates (10, 20, 30) point on the line with ID 13: To get closest line from the set with IDs 13 14 15:\u2026","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2017,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/01\/402-find-edge-nodes-of-mesh-and-create-node-sets-for-each-edge-using-tcl-script-in-hypermesh\/","url_meta":{"origin":8057,"position":5},"title":"#402 Find edge nodes of mesh and create node sets for each edge loop using tcl script in HyperMesh","author":"gantovnik","date":"2024-01-07","format":false,"excerpt":"Assume we have this model: The script will find all edges and create set of nodes for each edge:","rel":"","context":"In &quot;HyperMesh&quot;","block_context":{"text":"HyperMesh","link":"https:\/\/gantovnik.com\/bio-tips\/category\/hypermesh\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex402_3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex402_3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/01\/ex402_3.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/8057","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/comments?post=8057"}],"version-history":[{"count":2,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/8057\/revisions"}],"predecessor-version":[{"id":8060,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/8057\/revisions\/8060"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=8057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=8057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=8057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}