Indesign - Deleting Empty Text Frames CS2

Hi Folks-

Some of you may know Olivier Berquin’s free scripts online. I’ve been trying to modify a script he created for InDesign v2 for CS2. His script asked if the text frame has no content, no stroke, no fill and no text flowing into it.

No content still works, but I had to assign the null stroke color of ID swatch 14 (no color?), and instead of text wrap, I used the frame ID versus the text start frame id. I haven’t gotten this similar approach to work correctly. Also, could someone explain the “if” structure with the ‘bracket’ returns, and lack of ‘end if’ statement?


tell application "Adobe InDesign CS2"
	set allFrames to all page items of active document
	tell document 1
		repeat with aFrame in allFrames
			if (class of aFrame is text frame) and ¬
				(contents of aFrame is "") and ¬
				(id of stroke color = 14) and ¬
				(id of fill color = 14) and ¬
				id of aFrame = id of start text frame of aFrame ¬
				then delete aFrame
		end repeat
	end tell
end tell

thanks,

Ralph

Hi Ralph,

the if-line is actually an one-liner, the return brackets are only an optical line break, not a real one

tell application "Adobe InDesign CS2"
	set allFrames to all page items of active document
	tell document 1
		repeat with aFrame in allFrames
			if (class of aFrame is text frame) and (contents of aFrame is "") and (id of stroke color = 14) and (id of fill color = 14) and id of aFrame = id of start text frame of aFrame then delete aFrame
		end repeat
	end tell
end tell

Thanks Stefan-

Now I figured out how to make the script work, but I’m a bit confused. It appears that asking InDesign whether a text frame is blank yields a different answer than asking the document.

here’s the script that works:


tell application "Adobe InDesign CS2"
	set allFrames to (every text frame whose contents = "") of active document
	tell document 1
		repeat with aFrame in allFrames
			if (id of stroke color of aFrame = 14) and ¬
				(id of fill color of aFrame = 14) and ¬
				id of aFrame = id of start text frame of aFrame ¬
				then delete aFrame
		end repeat
	end tell
end tell

yet this doesn’t:


tell application "Adobe InDesign CS2"
	set allFrames to all page items of active document
	tell document 1
		repeat with aFrame in allFrames
			if (class of aFrame is text frame) and ¬
				(contents of aFrame is "") and ¬
				(name of fill color of aFrame is "None") and ¬
				(name of stroke color of aFrame is "None") and ¬
				id of aFrame = id of start text frame of aFrame ¬
				then delete aFrame
		end repeat
	end tell
end tell

thanks,

Ralph

I tested the second one that you said was non-working. If you follow the event history, you will see that the only value being returned from the compound “if” statement is the class; I found that this is due to how “aframe” is referencing the document. You can fix that by editing the if statements.


		if class of aFrame is text frame and text of aFrame is {""} and ¬
			the name of the fill color of aFrame is "None" then delete aFrame

The sample script is too inefficient anyway; it has to iterate through everything in the entire document, not just frames. The goal seems to be to delete something and never call it again, so don’t bother with variable creation and iteration; just tell the active document to delete with your criteria.

Hi all,
Can I delete a text frame which have table with text “MyPoo” in cell 1.

Regards,
Poo

Problem with this code is it deletes those text frame which has table.