Notifications
Clear all

[Closed] How delete a empty bitmap

I’m looking for a way to delete a bitmap just by “getClassInstances Bitmaptexture” without having to enter material by material and slot by slot.
I really want to delete the bitmap, not replace it with an empty one.

I’m trying something like:

cBit = getClassInstances Bitmaptexture
for c in cBit do
(if c.filename == undefined or c.filename == “” do
(delete c
–or c = undefined
)
)

3 Replies
fn cleanEmptyBitmapTextures = 
(
	removed = 0
	bmts = getclassinstances BitmapTexture astrackviewpick:on 
	for b in bmts where (b.anim.filename == undefined) or (trimleft b.anim.filename " " == "") do
	(
		if b.client != undefined do 
		(
			b.client[b.subnum].value = undefined
			removed += 1
		)
	)
	removed
)
cleanEmptyBitmapTextures()

Thank you so much, it helped a lot and solved 99% of the problem.

But I have another question: if I want to remove some texture from the SME without resetting the SME how do I do it? Because when you disconnect this texture is loose, I would like not to need to reset the SME to disappear. This goes for many cases where I delete textures, not just bitmaps. Is there any way to “clean up” loose textures from SME?

fn getEmptyBitmapTextures = 
(
	bmts = getclassinstances BitmapTexture
	for b in bmts where (b.filename == undefined) or (trimleft b.filename " " == "") collect b
)
fn sme_cleanNodeRerfs refnodes viewid:#all = 
(
	views = #()
	if viewid == #all then views = for k=1 to sme.getnumviews() collect k else append views viewid
	
	if not sme.IsOpen() do sme.Open() 
	
	deleted = 0
	for id in views do 
	(
		view = sme.getview id 
		view.setselectednodes refnodes
		
		num = view.getnumnodes()
		x = view.deleteselection()
		deleted += num - view.getnumnodes()
	)
	deleted
)

fn cleanEmptyBitmapTextures = 
(
	removed = #()
	bmts = getclassinstances BitmapTexture astrackviewpick:on 
	for b in bmts where (b.anim.filename == undefined) or (trimleft b.anim.filename " " == "") do
	(
		if b.client != undefined do 
		(
			refs.replaceReference b.client b.subnum undefined
			appendifunique removed b.anim
		)
	)
	removed.count
)


/*

----  do it first!
fordel = getEmptyBitmapTextures()
sme_cleanNodeRerfs fordel

---- do it after you cleaned SME 
cleanEmptyBitmapTextures()

*/