Script for Delete Empty
Answers
-
Will tell the logic, try to do yourself and let us know if you still need help.
EntityPreviewEmpty will check the empty assemblies in your model. Use this API and while loop to check and delete the empty assemblies
use deletemark to delete the entities.
Check this to understand how while loop works https://www.tutorialspoint.com/tcl-tk/tcl_while_loop.htm
0 -
Thank you for your reply sir.
0 -
*EntityPreviewEmpty 1
set d [hm_getmarkentitytypes 1];
hm_createmark 1 $d;
#while loop execution
while { $d == 1 } {
puts $d
incr d
}
*deletemark $di have tried with my knowledge, please let me know your corrections.
thanks in advance.
0 -
While {*EntityPreview.. ; hm_marklength assems 1} {*deletemark assems 1}
0 -
Here's the script found on Altair site:
#-------------------------------------------------------------------------------------------- #This script deletes assemblies recursively, optionally comps will be deleted # steenbock@altair.de, 20141008 # V. 01 #-------------------------------------------------------------------------------------------- proc run {} { *clearmarkall 1 *createmarkpanel assems 1 'select assems 2 delete' #delete comps or not set answer [tk_dialog .owd 'Selected Assems: [hm_getmark assems 1]' 'Delete Components in Assems?' 'question' 0 'No' 'Yes' 'Cancel'] switch $answer { 0 {set delComps 0} 1 {set delComps 1} 2 {tk_messageBox -message 'Misson abort!' -type ok -icon warning; return;} } # loop whole assem tree foreach ass [hm_getmark assems 1] { deleteSubAssems $ass $delComps } *clearmarkall 1 } proc deleteSubAssems {assem delComps} { set output 1 if {[hm_entityinfo exist assem $assem] == 1} { set sub_ass [hm_getentityarray assemblies $assem assemblies] # part where comps will be deleted if {$delComps != 0} { set sub_comps [hm_getentityarray assemblies $assem components] if {[llength $sub_comps] > 0} { eval *createmark comps 1 $sub_comps if {$output ==1} {puts '\t\tdelete comps: $sub_comps'} *deletemark comps 1 } } # delete assem *createmark assems 1 $assem if {$output==1} {puts '\tdelete assem id=$assem ([hm_getentityvalue assemblies $assem name 1])'} *deletemark assems 1 if {[llength $sub_ass] > 0} { foreach a $sub_ass { deleteSubAssems $a $delComps } } } } #----------------------------------------------- run
0 -
Thanks for your thoughts...
0 -
Altair Forum User said:
Here's the script found on Altair site:
#-------------------------------------------------------------------------------------------- #This script deletes assemblies recursively, optionally comps will be deleted # steenbock@altair.de, 20141008 # V. 01 #-------------------------------------------------------------------------------------------- proc run {} { *clearmarkall 1 *createmarkpanel assems 1 'select assems 2 delete' #delete comps or not set answer [tk_dialog .owd 'Selected Assems: [hm_getmark assems 1]' 'Delete Components in Assems?' 'question' 0 'No' 'Yes' 'Cancel'] switch $answer { 0 {set delComps 0} 1 {set delComps 1} 2 {tk_messageBox -message 'Misson abort!' -type ok -icon warning; return;} } # loop whole assem tree foreach ass [hm_getmark assems 1] { deleteSubAssems $ass $delComps } *clearmarkall 1 } proc deleteSubAssems {assem delComps} { set output 1 if {[hm_entityinfo exist assem $assem] == 1} { set sub_ass [hm_getentityarray assemblies $assem assemblies] # part where comps will be deleted if {$delComps != 0} { set sub_comps [hm_getentityarray assemblies $assem components] if {[llength $sub_comps] > 0} { eval *createmark comps 1 $sub_comps if {$output ==1} {puts '\t\tdelete comps: $sub_comps'} *deletemark comps 1 } } # delete assem *createmark assems 1 $assem if {$output==1} {puts '\tdelete assem id=$assem ([hm_getentityvalue assemblies $assem name 1])'} *deletemark assems 1 if {[llength $sub_ass] > 0} { foreach a $sub_ass { deleteSubAssems $a $delComps } } } } #----------------------------------------------- run
this script is not working
0 -
For future reference, I was able to do using below:
set str_flag 1 while {$str_flag} { *EntityPreviewEmpty assem 1 if {[hm_marklength assem 1]} { *deletemark assems 1 } else { set str_flag 0; } }
0 -
Altair Forum User said:
For future reference, I was able to do using below:
set str_flag 1 while {$str_flag} { *EntityPreviewEmpty assem 1 if {[hm_marklength assem 1]} { *deletemark assems 1 } else { set str_flag 0; } }
I am run this script but error is entity is not found why?
0 -
Altair Forum User said:
While {*EntityPreview.. ; hm_marklength assems 1} {*deletemark assems 1}
*EntityPreviewEmpty 1
set d [hm_getmarkentitytypes 1];
hm_createmark 1 $d;
#while loop execution
While {*EntityPreview.. ; hm_marklength assems 1} {*deletemark assems 1}
}
*deletemark $dthis is also not work
0 -
Hi , If I want to delete all load collectors, load step along with empty and unused entity .which loop/command I need to use or command.
currently, I ma using below command for deleting empty comp.
proc cleanModel {n type} {
*EntityPreview$n $type 1
while {[hm_marklength $type 1] != 0} {
*deletemark $type 1
*EntityPreview$n $type 1
}
}
cleanModel Empty comps
cleanModel Unused props
cleanModel Unused mats
cleanModel Empty sets
cleanModel Empty assembly0 -
you can use the following script
to delete empty components
*createmark comps 1 "all"
hm_getunusedoremptyentities mode=empty type=comps inputmark=1 outputmark=2
*deletemark comps 2to delete unused property
*createmark prop 1 "all"
hm_getunusedoremptyentities mode=unused type=prop inputmark=1 outputmark=2
*deletemark prop 2to delete unused assemblies
createmark assy 1 "all"
hm_getunusedoremptyentities mode=empty type=assy inputmark=1 outputmark=2
*deletemark assy 20