In this example, we create n=40 random nodes, select several of them, and save their node IDs and coordinates in a csv file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
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 < $n} {incr i} { set x [RandomReal $x_min $x_max] set y [RandomReal $y_min $y_max] *createnode $x $y 0 0 0 0 } *window 0 0 0 0 0 *createmark nodes 1 "all" *numbersmark nodes 1 1 *clearmark nodes 1 set script_path [ file dirname [ file normalize [ info script ] ] ] puts $script_path cd $script_path set output_file "node_coordinates.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 "" close $file_id return } foreach node_id $selected_nodes { set x [hm_getvalue node id=$node_id dataname=x] set y [hm_getvalue node id=$node_id dataname=y] set z [hm_getvalue node id=$node_id dataname=z] puts "$node_id,$x,$y,$z" puts $file_id "$node_id,$x,$y,$z" } close $file_id *clearmark nodes 1 |
node_coordinates.csv
1 2 3 4 5 6 7 8 |
node_id,x,y,z 1,6.2778236187426,5.6907801030626,0 7,17.483855382299,5.5787051495065,0 15,16.562761429959,5.1656766632412,0 26,7.1378922309437,3.2773627356055,0 32,12.051626486728,5.8431812170163,0 38,13.621047313149,4.4710960446257,0 40,6.4036964282411,3.4629347238051,0 |
Recent Comments