Illustrator gurus: selection marquee via "Direct Selection" tool?

I have an issue where my exported PDFs from InDesign carry over a clipping mask that exists around the perimeter of the document. My goal is to remove this clipping mask. But I can not simply “select” that page item and remove it.

The problem is this selection item may be involved with a group, or an additional clipping mask, etc. Selecting it by normal means in AS and deleting it can compromise the resulting artwork.

I am attaching a link to a PDF that provides an example of what I mean. My goal is to only have the artwork in the center of the page become the only artwork on the page.

http://dl.dropbox.com/u/89164/ExportedImage.pdf.zip

However, if I were to open the file manually in Illustrator and use my “direct selection” tool (white arrow) and marquee this small corner section and hit delete twice, it will always do the trick.

So what I am wondering is if there is a way to replicate this “Direct Selection” maneuver via AS. In other words, I want to choose the direct selection tool and marquee and area that selects the object at position {0, 792}. If so, then I could easily use System Events to hit “delete” twice.

I apologize for the lengthy post, but I am sure I not the only one that has run across the need to do such a thing?

Thanks,
Jeff

Hi Jeff

This deleted the box without effecting the logo in the middle as far as i can tell:

tell application "Adobe Illustrator"
	tell document 1
		set selection to every path item whose control bounds is equal to {0.0, 792.0, 612.0, 0.0}
		set theBox to the selection
		delete theBox
	end tell
end tell

Let me know if its not doing what you want.

pidge

Those are just groups with clipping masks. Only the top/first path in a group item can have the property clipping true. Without using selections you could directly remove the path items. If you know they are masked just remove the first path if not use a whose filter to test.

tell application "Adobe Illustrator"
	tell document 1
		tell the first group item
			delete the first path item
			--delete (the first path item whose clipping is true)
			tell the first group item
				delete the first path item
				--delete (the first path item whose clipping is true)
			end tell
		end tell
	end tell
end tell

OMG!!! this appears to work. Once again Pidge, you managed to pull through with an Illustrator question!

Mark, your explanation also makes perfect sense, but I was typing this response prior to noticing your reply. And to think I was going to remove this post. live and learn :slight_smile:

Although I am very content with having the final missing part of my script NOW WORKING!, I am still curious about the logic.

For example, could I have also used:
set selection to every path item whose position is {0.0, 792.0}

How did you know to use control bounds, which also excepts the full dimensions?

FWIW, I included my complete script below. It takes a selected object (or objects) out of InDesign CS4, exports a PDF (twice actually), stores that to a folder. The Illustrator opens that file. Oddly I had to export as an RGB color space in order to fool the PDF to retaining any raster effects that Illustrator would better interpret once it opened the PDF. I have another post related to that found here.

http://macscripter.net/viewtopic.php?pid=36717#p36717

For those who attempt this script, you may find certain text with object styles applied to yield text with oversets when this PDF is opened in Illustrator. For this reason, I have assigned a keyboard shortcut ahead of time in InDesign, which I later have the script call using System Events, which will run that keyboard shortcut: break link to styles. There is a rather obvious comment section in my script that points to this.

It’s a rather esoteric script in terms of why one would need this. But in our production environment when we wish to create linked artwork files from InDesign set text, objects, and raster effects, it does come in handy

-- Try and make a new folder called FolderForGrabVectorFromInDesign in case it doesn't exist

try
	set filePath to ((path to current user folder as Unicode text) & "Library:Application Support:Adobe:Adobe Illustrator CS4:en_US:")
	set foldName to "FolderForGrabVectorFromInDesign"
	tell application "Finder"
		make new folder at folder filePath with properties {name:foldName}
	end tell
end try
tell application "Finder"
	try
		set theNewFolder to (path to current user folder as Unicode text) & "Library:Application Support:Adobe:Adobe Illustrator CS4:en_US:FolderForGrabVectorFromInDesign"
		delete entire contents of folder theNewFolder
	end try
end tell

tell application "Adobe InDesign CS4"
	activate
	try
		tell document 1
			set sel to the selection
			set myTextClasses to {text, insertion point, character, word, line, text style range, paragraph, text column}
			set theClass to class of item 1 of selection
			if class of item 1 of selection is in myTextClasses then
				tell application "SystemUIServer"
					activate
					set userResponse to display dialog "You must use your selection tool and select the text frame. Do not use the Type Tool." & return & return & "Place selected text in its own text frame and run this script again." & return buttons {" Cancel "} default button " Cancel " with icon 2
					if button returned of userResponse is " Cancel " then
						tell application "Adobe InDesign CS4"
							activate
						end tell
						return
						error number -128
					end if
					return
				end tell
			end if
		end tell
	on error
		display dialog "You must select a frame or multiple frames on your documet" buttons {"Cancel"} default button "Cancel" with icon 2
	end try
end tell
set theCont to "NO"


tell application "Adobe InDesign CS4"
	activate
	copy
	try
		tell document 1
			set sel to the selection
			set theClass to class of sel
			if theClass contains group or theClass contains list then
				set theG to item 1 of selection
				set theCount to count of page items in theG
				--display dialog theCount as string
				repeat with i from 1 to count of page items in theG
					set theOpac to opacity of blending settings of transparency settings of page item i of theG
					if theOpac is less than 100 then
						tell application "SystemUIServer"
							activate
							set userResponse to display dialog "Warning!" & return & return & "You have an item with an opacity set below 100%." & return & return & "You should make a note of the blending mode in the transparency settings." & return & return & "After creating the Illustrator logo and placing it in InDesign, makes sure it looks the way it should." buttons {" Continue "} default button " Continue " with icon 2
						end tell
						set theCont to "Yes"
						exit repeat
					end if
					set theBlend to blend mode of blending settings of transparency settings of item i of sel as text
					if theCont contains "No" then
						if theBlend is not equal to "normal" then
							tell application "SystemUIServer"
								activate
								set userResponse to display dialog "Warning!" & return & return & "You have an item with a blending mode set to something other than normal." & return & return & "You should make a note of the blending mode in the transparency settings." & return & return & "After creating the Illustrator logo and placing it in InDesign, makes sure it looks the way it should." buttons {" Continue "} default button " Continue " with icon 2
							end tell
							exit repeat
						end if
					end if
				end repeat
			else
				repeat with i from 1 to count of items in sel
					set theOpac to opacity of blending settings of transparency settings of item i of sel
					if theOpac is less than 100 then
						tell application "SystemUIServer"
							activate
							set userResponse to display dialog "Warning!" & return & return & "You have an item with an opacity set below 100%." & return & return & "You should make a note of the blending mode in the transparency settings." & return & return & "After creating the Illustrator logo and placing it in InDesign, makes sure it looks the way it should." buttons {" Continue "} default button " Continue " with icon 2
						end tell
						set theCont to "Yes"
						exit repeat
					end if
					set theBlend to blend mode of blending settings of transparency settings of item i of sel as text
					if theCont contains "No" then
						if theBlend is not equal to "normal" then
							tell application "SystemUIServer"
								activate
								set userResponse to display dialog "Warning!" & return & return & "You have an item with a blending mode set to something other than normal." & return & return & "You should make a note of the blending mode in the transparency settings." & return & return & "After creating the Illustrator logo and placing it in InDesign, makes sure it looks the way it should." buttons {" Continue "} default button " Continue " with icon 2
							end tell
							exit repeat
						end if
					end if
				end repeat
			end if
		end tell
		
		
		
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		--In this part I have I have assigned a keyboard shortcut in InDesign to to "Product area : Panel Menus" --> "Object Styles: Break Link to Style --- Default: Ctrl+Opt+Cmd+Clear", I probably don't need system, nor a keyboard shortcut to do this, but I never found an easy way to break the link to all object styles?
		tell application "System Events"
			try
				tell application process "Adobe InDesign CS4"
					set frontmost to true
					key code 71 using {command down, option down, control down}
				end tell
			end try
		end tell
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		-----------------------------------------------
		
		
		
		
		
		set theDoc to active document
		set theName to "ExportedImage"
		copy
	end try
end tell
tell application "System Events"
	try
		tell application process "Adobe InDesign CS4"
			set frontmost to true
			keystroke "a" using {command}
			key code 71 using {command down, option down, shift down}
			keystroke "g" using {command down}
		end tell
	end try
end tell



tell application "Adobe InDesign CS4"
	set theDoc to make document
	tell view preferences of theDoc
		set horizontal measurement units to points
		set vertical measurement units to points
		set ruler origin to page origin
	end tell
	tell document preferences of theDoc
		set properties to {page height:"792", page width:"612", page orientation:portrait, pages per document:1, column guide color:gray}
	end tell
	tell margin preferences of page 1 of theDoc
		set properties to {column count:1, column gutter:12, top:0, left:0, bottom:0, right:0}
	end tell
end tell

tell application "Adobe InDesign CS4"
	paste
	set theName to "ExportedImage.pdf" as text
	set myPath to ((path to current user folder as Unicode text) & "Library:Application Support:Adobe:Adobe Illustrator CS4:en_US:FolderForGrabVectorFromInDesign:")
	tell application "Adobe InDesign CS4"
		activate
		set oldProps to properties of PDF export preferences
		set theProps to properties of PDF export preset "[Smallest File Size]"
		set newProps to {view PDF:false, color bitmap sampling:none} & theProps
		set properties of PDF export preferences to newProps
		export active document format PDF type to (myPath & theName) without showing options
	end tell
	tell application "Adobe InDesign CS4"
		activate
		set oldProps to properties of PDF export preferences
		set theProps to properties of PDF export preset "[Smallest File Size]"
		set newProps to {view PDF:false, color bitmap sampling:none} & theProps
		set properties of PDF export preferences to newProps
		export active document format PDF type to (myPath & theName) without showing options
		
		set oldProps to properties of PDF export preferences
	end tell
	delay 2
	try
		if saved of active document is false then
			set theName to "TempFile"
			save document 1 to ((path to current user folder as Unicode text) & "Library:Application Support:Adobe:Adobe Illustrator CS4:en_US:FolderForGrabVectorFromInDesign:ExportedImage.pdf") & theName
		end if
	end try
end tell

tell application "Adobe Illustrator"
	activate
	open file ((path to current user folder as Unicode text) & "Library:Application Support:Adobe:Adobe Illustrator CS4:en_US:FolderForGrabVectorFromInDesign:ExportedImage.pdf")
	tell document 1
		try
			tell application "System Events"
				tell application process "Adobe Illustrator CS4"
					set frontmost to true
					tell menu bar 1
						tell menu bar item "File"
							tell menu 1
								tell menu item "Document Color Mode"
									tell menu 1
										click menu item "CMYK Color"
									end tell
								end tell
							end tell
						end tell
					end tell
				end tell
			end tell
		end try
		return
		set selection to every path item whose control bounds is equal to {0.0, 792.0, 612.0, 0.0}
		set theBox to the selection
		delete theBox
	end tell
end tell

tell application "Adobe InDesign CS4"
	tell document 1
		close saving no
	end tell
end tell

tell application "SystemUIServer"
	activate
	display dialog "Finished. " buttons {"Ok"} default button "OK" giving up after 1.5
end tell

tell application "Adobe Illustrator"
	activate
end tell

Hi Jeff

I wish i could say that i used some crazy dark art form, however the truth be told i used this:

tell application "Adobe Illustrator"
	tell document 1
		get properties of selection
	end tell
end tell

I opened your pdf in illustrator and selected the troublesome outer line and run the above script
within the properties you have control bounds, visible bounds & geometric bounds i haven’t tested but assume you could use any of these, luckily control bounds worked first time.

In all fairness i haven’t tested so give it a go, i’m on the nightshift over here in the UK and my eyes are falling out of my head :lol: , but i’m very glad it worked for you!

pidge

Jeff, I only scanned over your script so I may have missed some subtle difference. but both these apps have preferences for PDF clipboard handling. and you can simply c&p from one to the other. All Illustrator actually lacks the ability to create a new document to clipboard bounds like Photoshop can. but you don’t actually do this either. It is is very straight forward to script though. There are differences between the app text engines so some formatting can get broken or lost. ID being more advanced. There are also some JavaScripts about that will re-join these text frames that work pretty well.

Pidge, it worked like a charm!!! btw, shame on me for not checking properties of the selected Illustrator object the way you did. I do that often, but in this instance I thought it was beyond a simple approach, forcing me to use some sort of marquee maneuver :frowning:

Mark, thank you very much also. I believe you are referring to PDF vs AICS (preserve paths/preserve appearance) in Illustrator’s “File handling and Clipboard” prefs. Yes, I am aware of these controls. Pasting from Illustrator into InDesign works well, but I have yet to see a way to paste from InDesign into Illustrator?