InDesign unable to apply object syle to labelled text boxes

Good morning,

I wonder if somebody could pleases assist me, either by assisting with the code or telling me it cannot be done.

We have 4 catalogues each with 1,000 stock items which need to be updated monthly or whenever we add new products to our ranges and I have been reasonably successful in building a script that can do this with a fairly basic layout. To improve the appearance I wanted to add 3 varying object styles to each product listing, drop shadow and rounded border. After adding the object style I need to use the the “fit given frame to content” command to shrink borders to the text descriptions. The shrink to bit works fine.


tell application "Adobe InDesign CC 2019"
	tell myDoc
		tell (every text frame whose label is "shadStyle")
			-->> This is where I want to put the "set object style: command <<--
			fit given frame to content
		end tell
	end tell
end tell

I also tried a bit of the code from StefanK posted back in 2006 hoping it’d point me in the right direction, and for a moment as all the text boxes shrunk I was ecstatic! I substituted the geometric bounds bit for applied object style:object style catLeft that I have used previously making text boxes…


tell application "Adobe InDesign CC 2019"
		tell myDoc
			repeat with oneFrame in (get text frames whose label is "shadStyle")				
				set {a, b, c, d} to geometric bounds of oneFrame
				set geometric bounds of oneFrame to {a, b, c, 25}
-->> This is where I want to put the "set object style: command <<--
			end repeat
		end tell
	end tell

…but this didn’t work either!

Thank you in anticipation of somebody being able to point me in the right direction.

Martin

Model: late 2013 Mac Pro
AppleScript: 2.7
Browser: Firefox 68.0
Operating System: macOS 10.14

For your task use this:


tell application "Adobe InDesign CC 2019"
	set myDoc to document 1
	
	tell myDoc
		set theTextFrames to text frames
		repeat with i from 1 to count of theTextFrames
			set theFrame to item i of theTextFrames
			if label of theFrame is "shadStyle" then
				-->> HERE put the "set object style: command <<--
			end if
		end repeat
	end tell
	
end tell

Better solution:


tell application "Adobe InDesign CC 2019"
	set myDoc to document 1
	tell myDoc
		set theTextFrames to every text frame of every spread whose label is "ShadStyle"
		repeat with i from 1 to count of theTextFrames
			set theFrame to item i of theTextFrames
			-->> HERE put the "set object style: command <<--
		end repeat
	end tell
end tell

NOTE: Your mistake is telling in whose clause to Document directly, and you should tell first to Spreads. Usefull clause whose always requires full path

Good morning Kniazidis,

Thank you for your reply and solution, not only for this particular problem, but for helping me understand the method on which I structure commands and where to address them.

I am on my way to the studio and eager to try this out and I’ll drop you a message later this morning to let you know how I get on.

Meanwhile, kindest regards
Martin

Good morning Kniazidis,

I can’t thank you enough for your help. We’ll now have catalogues that looks good a well as being functional.

Here’s the complete code that I used with the object style in place.


tell application "Adobe InDesign CC 2019"
	set myDoc to document 1
	tell myDoc
		set theTextFrames to every text frame of every spread whose label is "ShadStyle"
		repeat with i from 1 to count of theTextFrames
			set theFrame to item i of theTextFrames
			-->> below is where I put the set object style command <<--
			set myObjectStyle to object style "catRight" of myDoc
			tell theFrame to apply object style using myObjectStyle clearing overrides yes
		----------------------^^^^^^^^^^^^^^^^^^^^^^^----------------------
		end repeat
	end tell
end tell

Thank you once again.

Kindest regards
Martin

You are welcome. I’ll say one last thing: the code line set myDoc to document 1 can be removed, and you can directly tell to document 1 (I inserted this line for demonstrative purposes only, for you), if you don’t use the variable myDoc elsewhere in the larger script:


tell application "Adobe InDesign CC 2019"
	tell document 1
		set theTextFrames to every text frame of every spread whose label is "ShadStyle"
		repeat with i from 1 to count of theTextFrames
			set theFrame to item i of theTextFrames
			-->> below is where I put the set object style command <<--
			set myObjectStyle to object style "catRight"
			tell theFrame to apply object style using myObjectStyle clearing overrides yes
			----------------------^^^^^^^^^^^^^^^^^^^^^^^----------------------
		end repeat
	end tell
end tell

Hi Kniazidis,

Thank you for your follow up and additional information. With your help I’ve managed to navigate around the order in which I need to call on the variables and send the commands.

Now I think my biggest problem is going to be just how to limit the complexity of the final design and to avoid just doing things because I can! :smiley:

Kindest regards
Martin