🎉Community Raffle - Win $25

An exclusive raffle opportunity for active members like you! Complete your profile, answer questions and get your first accepted badge to enter the raffle.
Join and Win

Script for Delete Empty

User: "Altair Forum User"
Altair Employee
Updated by Altair Forum User

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.

Find more posts tagged with

Sort by:
1 - 12 of 121
    User: "sandeepballiwar"
    New Altair Community Member
    Updated by sandeepballiwar

    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

     

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Thank you for your reply sir.

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    *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.

    User: "tinh"
    Altair Community Member
    Updated by tinh

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

    User: "QuyNguyenDai"
    Altair Community Member
    Updated by QuyNguyenDai

    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

     

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    Thanks for your thoughts...

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    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

    User: "llyle_20499"
    New Altair Community Member
    Updated by llyle_20499

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

     

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    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?

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    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

    User: "Altair Forum User"
    Altair Employee
    OP
    Updated by Altair Forum User

    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

     

    User: "Yesvanth R"
    New Altair Community Member
    Updated by Yesvanth R

    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