remove node from nodelist in loop
Hi,
Using script, i am trying to renumber a set of selected nodes using shortest distance from a point.
i am using following script to do that. In which I am trying to renumber closest node one by one and once renumbering is done, I want to remove that node from the selected node list.
But it is not working as intended. Can some one help me what is wrong in the code? or is there any alternate method to do that through script?
*createlistpanel nodes 1
set nodelist [hm_getlist nodes 1]
set nodelist_num [llength $nodelist]
puts $nodelist_num
for {set i 1} {$i<=$nodelist_num} {incr i} {
*createmark nodes 1 $nodelist
set closenode [hm_measureshortestdistance2 120 120 550 nodes 1 0 0]
set cnode [lindex $closenode 4]
*createmark nodes 1 $cnode
*renumbersolverid nodes 1 [expr $i+10] 1 0 0 0 0 0
regsub $cnode $nodelist '' nodelist
set *nodelist_num [llength $nodelist]
puts $nodelist_num
*clearmark nodes 1 }
Best Answer
-
Hi,
Sorry I didn't update Coordinates of points
please use this,
*createlistpanel nodes 1
set nodelist [hm_getlist nodes 1]
set nodelist_num [llength $nodelist]
puts $nodelist_num
for {set i 1} {$i<=$nodelist_num} {incr i} {
*createmark nodes 1 $nodelist
set closenode [hm_measureshortestdistance2 120 120 550 nodes 1 0 0]
set cnode [lindex $closenode 4]
*createmark nodes 1 $cnode
*renumbersolverid nodes 1 [expr $i+10] 1 0 0 0 0 0
regsub $cnode $nodelist "" nodelist
set *nodelist_num [llength $nodelist]
puts $nodelist_num
*clearmark nodes 1 }Thanks.
0
Answers
-
Several ways to do this loop.
- Add a empty list "seen" at begin of script
- Do your loop, when the numbering is done, add the node into list "seen"
- At top of your loop, check the node: if node does not found in "seen" do the loop body; if found then skip the loop with "continue"
0 -
Hi,
You can use this code,
I have changed command regsub $cnode $nodelist '' nodelist to regsub $cnode $nodelist "" nodelist
*createlistpanel nodes 1
set nodelist [hm_getlist nodes 1]
set nodelist_num [llength $nodelist]
puts $nodelist_num
for {set i 1} {$i<=$nodelist_num} {incr i} {
*createmark nodes 1 $nodelist
set closenode [hm_measureshortestdistance2 -12.234 -126.476 -8.000 nodes 1 0 0]
set cnode [lindex $closenode 4]
*createmark nodes 1 $cnode
*renumbersolverid nodes 1 [expr $i+10] 1 0 0 0 0 0
regsub $cnode $nodelist "" nodelist
set *nodelist_num [llength $nodelist]
puts $nodelist_num
*clearmark nodes 1 }I tried this and its working below like this,
0 -
Hi,
Sorry I didn't update Coordinates of points
please use this,
*createlistpanel nodes 1
set nodelist [hm_getlist nodes 1]
set nodelist_num [llength $nodelist]
puts $nodelist_num
for {set i 1} {$i<=$nodelist_num} {incr i} {
*createmark nodes 1 $nodelist
set closenode [hm_measureshortestdistance2 120 120 550 nodes 1 0 0]
set cnode [lindex $closenode 4]
*createmark nodes 1 $cnode
*renumbersolverid nodes 1 [expr $i+10] 1 0 0 0 0 0
regsub $cnode $nodelist "" nodelist
set *nodelist_num [llength $nodelist]
puts $nodelist_num
*clearmark nodes 1 }Thanks.
0