Page 1 of 1

Request: Please add on a "remove all instances of image

Posted: Sun Sep 19, 2004 8:58 pm
by Doogs
I think the method of ridding an excess image/texture file from the blender data image menu is really in need of repair. To get "rid" of an image, you have to erase all instances manually and then save, close, load, and repeat at times, until the reference to that image is gone. Please improve this?

RonC

Posted: Sun Sep 19, 2004 10:29 pm
by z3r0_d
one could pretty easily make a script to do that

I think I shall

Posted: Sun Sep 19, 2004 11:18 pm
by z3r0_d
peculair, you can't seem to assign None to a nmface.image

Code: Select all

TypeError: expected image object
oh well, I guess you're only going to get to replace images

Code: Select all

#!BPY
"""
Name: 'Replace Images'
Blender: 233
Group: 'Object'
Tooltip: 'Replace an image in all selected objects with another'
"""
import Blender

"""
this script's goal is to delete an image from all selected objects

it probably could be rather trivially modified to replace that image with another
"""
images = []
for obj in Blender.Object.GetSelected():
	if obj.getType() != "Mesh": continue
	for face in obj.getData().faces:
		if images.count(face.image) == 0:
			images.append(face.image)

# prompt the user which image to delete
# I probably want to sort them....
def cmpfn(x,y):
	ax = x
	ay = y
	if not ax: ax = "~~~~None"
	else: ax = ax.name
	if not ay: ay = "~~~~None"
	else: ay = ay.name
	if ax < ay: return -1
	if ax == ay: return 0
	return 1
images.sort(cmpfn)

promptst = "Select Image to Replace%t"
for i in range(len(images)):
	if not images[i]:
		promptst += "|None%x"+str(i)
	else:
		promptst += "|" + images[i].name + "%x"+str(i)

choice = Blender.Draw.PupMenu(promptst,24)

srcimg = images[choice]
if choice != -1:
	# prompt user for image to replace with
	promptst = "Select Image to Replace With%t"
	
	images = Blender.Image.Get()
	images.sort(cmpfn)
	
	for i in range(len(images)):
		if not images[i]: # doubt this will be used
			promptst += "|None%x"+str(i)
		else:
			promptst += "|" + images[i].name + "%x"+str(i)
	
	choice = Blender.Draw.PupMenu(promptst,24)
	
	if choice != -1:
		destimg = images[choice]
		for obj in Blender.Object.GetSelected():
			if obj.getType() != "Mesh": continue
			mesh = obj.getData()
			for face in mesh.faces:
				if face.image == srcimg:
					face.image = destimg
			mesh.update()
		print "###replaced images successfully"

Posted: Mon Sep 20, 2004 12:07 am
by Monkeyboi
I agree Doogs, this is a huge frustration! Should be able to do this from the OOPS Schematic by selecting the image node and simply deleting it, which would remove the image completely from the file.

Posted: Mon Sep 20, 2004 4:12 am
by fligh
LOL Doogs! X the texture, Ctrl-W, Ctrl-O. But I know what you mean. Personally, I prefer it the way it is but with the new Fake option the O-user has become a bit redundant.

%<

Posted: Mon Sep 20, 2004 9:13 am
by joeri
It gets a bit more complicated with the 'packed' feature on.

Posted: Tue Sep 21, 2004 3:01 am
by Doogs
Okay but does that in any way give a proper excuse to not code in "remove all instances"?

RonC

Posted: Tue Sep 21, 2004 9:29 am
by joeri
In my opinion there is no proper excuse to not have a "empty trash".
And then I consider all 0 user datablocks to be in "the trashcan".
That is, the excuse I have are my poor programming skills.

I'd also favour a "hee, thats the same image file on disk, why do I have that thing 3 times in memory" removal button, although it's might need a different name to fit in the button. Specialy for packed files on the web it's a pain to dl the same image more then once.

Posted: Tue Sep 21, 2004 8:54 pm
by Doogs
Do coders even look at these requests?

:(

RonC