Jump to content

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

 

Livil Lyle and MEIYARASU19 like this

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
On 2/27/2019 at 3:01 PM, Q.Nguyen-Dai 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

Share this post


Link to post
Share on other sites

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

 

Share this post


Link to post
Share on other sites
On 3/28/2019 at 10:08 PM, Livil Lyle 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?

Share this post


Link to post
Share on other sites
On 2/27/2019 at 8:18 AM, tinh 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 $d

 

this is also not work

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...