{"id":2219,"date":"2024-06-24T02:20:35","date_gmt":"2024-06-24T09:20:35","guid":{"rendered":"https:\/\/gantovnik.com\/bio-tips\/?p=2219"},"modified":"2024-06-26T14:24:59","modified_gmt":"2024-06-26T21:24:59","slug":"431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file","status":"publish","type":"post","link":"https:\/\/gantovnik.com\/bio-tips\/2024\/06\/431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file\/","title":{"rendered":"#431 HyperMesh python script to create nodes using coordinates from csv file"},"content":{"rendered":"<p><a href=\"https:\/\/gantovnik.com\/bio-tips\/2024\/06\/431-hypermesh-python-script-to-create-nodes-using-coordinates-from-csv-file\/ex431\/\" rel=\"attachment wp-att-2220\"><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=338%2C487&#038;ssl=1\" alt=\"\" width=\"338\" height=\"487\" class=\"alignnone size-full wp-image-2220\" srcset=\"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?w=338&amp;ssl=1 338w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=208%2C300&amp;ssl=1 208w, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2024\/06\/ex431.png?resize=104%2C150&amp;ssl=1 104w\" sizes=\"(max-width: 338px) 100vw, 338px\" \/><\/a><\/p>\n<a href='https:\/\/community.altair.com\/csm\/en?id=altair_file_exchange_article_view&#038;sysparm_article=KB0124704' class='small-button smallgreen'>This example in Altair Exchange<\/a>\n<p>Finally, I read how to write a script for HyperMesh in python. In this example, the script reads the coordinates of points from a cvs file.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport os\r\nimport hm\r\nimport hm.entities as e\r\nfrom hwx import gui\r\nimport csv\r\nmodel=hm.Model()\r\nos.chdir(r&quot;D:\\projects\\wordpress\\ex431&quot;)\r\nwith open(&#039;ex431_coordinates.csv&#039;, mode =&#039;r&#039;) as file:\r\n  lines = csv.reader(file, quoting = csv.QUOTE_NONNUMERIC)\r\n  for line in lines:\r\n      nodeNew=e.Node(model)\r\n      nodeNew.localcoordinates = line\r\n<\/pre>\n<p>It feels like the python code is translated into a tcl script and then executed in HyperMesh. Because HyperMesh continues to record executed commands in this form.<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\n*createentity nodes\r\n*setvalue nodes user_ids={3} 100217={10 0 0}\r\n*createentity nodes\r\n*setvalue nodes user_ids={4} 100217={9.98744 0.50104 0.10025}\r\n*createentity nodes\r\n*setvalue nodes user_ids={5} 100217={9.94979 1.00083 0.2005}\r\n*createentity nodes\r\n*setvalue nodes user_ids={6} 100217={9.88715 1.4981 0.30075}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Finally, I read how to write a script for HyperMesh in python. In this example, the script reads the coordinates of points from a cvs file. import os import hm import hm.entities as e from hwx import gui import csv model=hm.Model() os.chdir(r&quot;D:\\projects\\wordpress\\ex431&quot;) with open(&#039;ex431_coordinates.csv&#039;, mode =&#039;r&#039;) as file: lines = csv.reader(file, quoting = csv.QUOTE_NONNUMERIC) for [&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_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":"","jetpack_post_was_ever_published":false},"categories":[24,2],"tags":[119,23,3],"class_list":["post-2219","post","type-post","status-publish","format-standard","hentry","category-hypermesh","category-python","tag-altair-exchange","tag-hypermesh","tag-python"],"modified_by":"gantovnik","jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8bH0k-zN","jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":3616,"url":"https:\/\/gantovnik.com\/bio-tips\/2024\/08\/445-hypermesh-python-script-for-renumbering-the-elements-and-nodes\/","url_meta":{"origin":2219,"position":0},"title":"#445 HyperMesh python script for renumbering the elements and nodes","author":"gantovnik","date":"2024-08-13","format":false,"excerpt":"import hm import hm.entities as ent elems = hm.Collection(model,ent.Element) model.renumbersolverid(collection=elems,start_id=1,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0) nodes = hm.Collection(model,ent.Node) model.renumbersolverid(collection=nodes,start_id=1000,incr_val=1,offset_val=1,offset_flag=0,reserved_1=0,reserved_2=0,reserved_3=0)","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":8057,"url":"https:\/\/gantovnik.com\/bio-tips\/2025\/02\/458-hypermesh-tcl-script-to-save-selected-node-ids-and-coordinates-to-a-csv-file\/","url_meta":{"origin":2219,"position":1},"title":"#458 HyperMesh tcl script to save selected node IDs and coordinates to a csv file","author":"gantovnik","date":"2025-02-20","format":false,"excerpt":"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\u2026","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\/2025\/02\/2025-02-20_005944.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/gantovnik.com\/bio-tips\/wp-content\/uploads\/2025\/02\/2025-02-20_005944.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"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":2219,"position":2},"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":10734,"url":"https:\/\/gantovnik.com\/bio-tips\/2026\/04\/get-current-hypermesh-model-name-using-tcl\/","url_meta":{"origin":2219,"position":3},"title":"#468 How to Get the Name of the Current Model Opened in HyperMesh Using Tcl","author":"gantovnik","date":"2026-04-30","format":false,"excerpt":"When working with Tcl scripts in HyperMesh, it is often useful to get the name of the currently opened model file. For example, you may want to automatically create output files, reports, or logs using the same name as the active HyperMesh model. HyperMesh provides the command hm_info currentfile, which\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":489,"url":"https:\/\/gantovnik.com\/bio-tips\/2020\/04\/how-to-find-working-directory-in-altair-hypermesh\/","url_meta":{"origin":2219,"position":4},"title":"#71 How to find working directory in Altair HyperMesh?","author":"gantovnik","date":"2020-04-02","format":false,"excerpt":"Q: How to find working directory in Altair HyperMesh? A: Pull up command window and type in command \"pwd\" press Enter. \u00a0","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":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":2219,"position":5},"title":"#327 Creates nodes with coordinates from text file using HyperMesh Tcl","author":"gantovnik","date":"2022-12-14","format":false,"excerpt":"nodes.txt [code language=\"python\"] 3 10 3 1 6 0 2 7 4 8 10 9 0 2 2 6 6 10 1 5 7 5 3 3 0 8 9 1 0 6 [\/code] create_nodes.tcl [code language=\"python\"] set script_path [ file dirname [ file normalize [ info script ] ]\u2026","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":[]}],"_links":{"self":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2219","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=2219"}],"version-history":[{"count":5,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2219\/revisions"}],"predecessor-version":[{"id":2232,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/posts\/2219\/revisions\/2232"}],"wp:attachment":[{"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/media?parent=2219"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/categories?post=2219"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gantovnik.com\/bio-tips\/wp-json\/wp\/v2\/tags?post=2219"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}