Script for Delete Empty

Altair Forum User
Altair Forum User
Altair Employee
edited December 2023 in Community Q&A

hello,

 

i am new to make scripts. i am trying to do a script to delete empty assemblies and sub assemblies in one action. i need a loop format of script to do this. but i dont know the structure. please help me out.

Tagged:

Answers

  • sandeepballiwar
    sandeepballiwar New Altair Community Member
    edited February 2019

    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

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2019

    Thank you for your reply sir.

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2019

    *EntityPreviewEmpty 1
    set d [hm_getmarkentitytypes 1];
    hm_createmark 1 $d;
    #while loop execution 
    while { $d == 1 } {
       puts $d
       incr d
    }
    *deletemark $d

     

    i have tried with my knowledge, please let me know your corrections.

     

    thanks in advance.

  • tinh
    tinh Altair Community Member
    edited February 2019

    While {*EntityPreview.. ; hm_marklength assems 1}  {*deletemark assems 1}

  • Q.Nguyen-Dai
    Q.Nguyen-Dai Altair Community Member
    edited February 2019

    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

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2019

    Thanks for your thoughts...

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited February 2019

    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

  • llyle_20499
    llyle_20499 New Altair Community Member
    edited March 2019

    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; 		} 	}

     

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2019

    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?

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited June 2019

    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 $d

     

    this is also not work

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited July 2019

    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 assembly

     

  • Yesvanth R
    Yesvanth R New Altair Community Member
    edited December 2023

    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 2

    to delete unused property

    *createmark prop 1 "all"
    hm_getunusedoremptyentities mode=unused type=prop inputmark=1 outputmark=2
    *deletemark prop 2

    to delete unused assemblies

    createmark assy 1 "all"

    hm_getunusedoremptyentities mode=empty type=assy inputmark=1 outputmark=2
    *deletemark assy 2