TCL - Checking IDs

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hello,

 

I have created this TCL script, which should check, if a certain ID for a specified entity-type is free and if not provide the next free one.


proc check_ID {entity_type target_ID} {
*createmark $entity_type 1 $target_ID
set mark_list [hm_getmark $entity_type 1]
*clearmark $entity_type 1
if {[llength $mark_list] > 0} {return 0}
return 1
}

proc next_free_ID {entity_type target_ID} {
hm_usermessage 'Finding next free ID for $entity_type $target_ID'
silentmode_start
while {![check_ID $entity_type $target_ID]} {incr target_ID}
silentmode_stop
return $target_ID
}

proc silentmode_start {} {
*entityhighlighting 0
hm_commandfilestate 0
hm_blockmessages 1
hm_blockerrormessages 1
hm_blockredraw 1
hwbrowsermanager view flush false
hm_setmouse 0
}

proc silentmode_stop {} {
*entityhighlighting 1
hm_commandfilestate 1
hm_blockmessages 0
hm_blockerrormessages 0
hm_blockredraw 0
hwbrowsermanager view flush true
hm_setmouse 1
}

puts [next_free_ID 'elems' 5000]

The problem is, this script is very slow. Already on a small model with about 10000 elements it takes a long time to run, or Hypermesh freezes completely.

Is there any way how i can make this run faster?

For example the renumber-function in Hypermesh can do basically the same thing, but in real time.

 

Thanks & Best regards

Tagged:

Answers

  • tinh
    tinh Altair Community Member
    edited May 2015

    Hi there,

    you can use hm_entityinfo exist elems $ElemId to verify ElemId is free or not

    and hm_entityinfo maxid elems to get maximum ID so incr it you will get next free id

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited May 2015

    Yes,try to use the inbuilt procedures,this way HW will be faster.