Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
3

Script to select and delete using coordinates

Community Beginner ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Let me start by saying I know next to nothing about scripting for Illustrator outside of how to run one. AI has usually helped me create the simple scripts I've needed recently, until now. What it is suggesting does nothing at all.

 

I have about 1700 PDF's I need to remove a header and footer from (they're all engineering specs and nothing is named or organized by layers). All of the headers and footers are in almost the exact same position. My thinking is using the rough coordinates of where they are I should be able to select and delete between the top-left and bottom-right coordinates of these areas. So far nothing has worked. 

 

Is this even possible? Any help is welcome.

TOPICS
Scripting

Views

767
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Nov 22, 2023 Nov 22, 2023

Based on your infos about the files, I've modified an action I once used for something different.

 

You can download a .zip file that contains a sample Illustrator file and an action set file:

 

Remover 1

 

Instructions:

 

- Download and unzip the file
- Open the sample file remover_sample_001.ai

- In the Align palette, make sure that the "Align to Artboard" option is turned on
- In the Actions palette flyout menu, load the action set remover.aia
- In the Actions palette, run the action remover_1

 

...

Votes

Translate
Adobe
Community Expert ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Can you share a couple of the .pdf files, so one can take a look?

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Due to the propietary nature of the files I can't share an actual one, but I mocked up some rectangles and text that more or less represents the organization of one of the PDFs. Hope this helps.

 

Again, I need to remove the header and the footer sections and then save the remaining "spec" section.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Thanks for the sample file.

 

Some more questions:

 

  • Do all files have the same artboard dimensions? If so, about what dimensions are we talking?
  • Are all .pdf files single page documents or multiple page documents? Or a mixture of both?
  • What kind of objects do the files contain? Only (live) type objects? Or all kind of possible objects including raster art?
  • Are there (nested) clipping masks in the files?

 

If you can provide even more infos, that would certainly be helpful.

 

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

  • Do all files have the same artboard dimensions? If so, about what dimensions are we talking?
    • Yes from what I have seen they are all the same size. They are all 612px x 792px
  • Are all .pdf files single page documents or multiple page documents? Or a mixture of both?
    • All single page
  • What kind of objects do the files contain? Only (live) type objects? Or all kind of possible objects including raster art?
    • Primarily paths, occasionally clip groups. Have yet to see any actual type objexts. No raster at all (these all come from AutoCAD output)
  • Are there (nested) clipping masks in the files?
    • Occasionally there are some clipping masks/clip group with no explanation why. Again, they're AutoCAD output and I'm not terribly familiar with its export settings.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Are the items to be removed top level items or children of top level items that are themselves to be removed?  Or could they be children of items not to be removed (e.g. the header or part of the header  grouped with spec)?  It will make a difference for a script having to iterate top level items vs. having to iterate all items in a doc, in particular if this is going to be multiplied by many docs. 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Unfortunately this is difficult to answer, almost everything is top level. But the way AutoCAD exports leaves me with hundreds of small paths for the most part. On occasion I have found some clip groups, but I don't see any rationale as to why it does that. Whether top level, or in a clip group, everything is just a fractional piece of the overall spec. Occasionally I get a full line, or a full circle. Everything else is just a sliver of something.

 

None of the PDFs were made by me, and many were made nearly a decade ago. Honestly, if I can get 80% of these files corrected then that's a win to me.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2023 Nov 22, 2023

Copy link to clipboard

Copied

Based on your infos about the files, I've modified an action I once used for something different.

 

You can download a .zip file that contains a sample Illustrator file and an action set file:

 

Remover 1

 

Instructions:

 

- Download and unzip the file
- Open the sample file remover_sample_001.ai

- In the Align palette, make sure that the "Align to Artboard" option is turned on
- In the Actions palette flyout menu, load the action set remover.aia
- In the Actions palette, run the action remover_1

 

Note that the action may be modified depending on what files you are trying to process. But one would then indeed have to take a look at some real files from you.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2023 Nov 24, 2023

Copy link to clipboard

Copied

David, I have another action that does not rely on flattening transparency. It's less destructive and moreover it is independent from the actual artboard dimensions.

 

Let me know if that is something you would rather prefer.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Kurt, sorry for the delay, I wasn't at work due to the holiday weekend. Your action worked very well, though it seems I underestimated the amount of subtle variations between files. I knew that each engineer had their own output template, but I didn't think they would vary as much as they do. I did look through several dozen to get my initial measurements and they all were the same header and footer heights (perhaps they were all from the same engineer), but as I tested your action on a batch of others I ended up with some leftover paths (primarily in the headers). Overall I think your original action is suitable to this problem, it means I won't have to edit all 1700 specs individually. Having said that, I am open to this other action you mentioned in your other post.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Can you tell the exact height of the headers and footers in your files?

 

In my sample file both header and footer are 80 pt high. Perhaps that's the reason why it sometimes didn't work as expected.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

That 80px was likely based on the sample file I sent you, which was based on a small sample size of the files I'm dealing with.

 

Our specs in some cases are were generated as far back as 2010, and we have had numerous engineers over the years. The headers are all essentially 80px high, but could be ±20px from what I'm now seeing. 

 

I think what I'm going to try and do is run your action across a large subsection of them and see how much variation I end up with. If there is any deviation from the 80px header, I'm usually left with a portion of a letter or a parenthesis, still a win in my book.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

Probably some headers and footers actually have different heights.

 

You can download the other action here:

 

Remover 2

 

Note that it is a bit slower than Remover 1, but less destructive at the same time. In the sample Illustrator file headers and footers are 82 pt high. All objects inside the header/footer areas should be deleted (including the ones which are partially touching the areas. The height is fixed whereas the width is variable.

 

Instructions:

 

- Download and unzip the file remover_002.zip
- Open the sample file remover_sample_002.ai
- In the Align palette, make sure that the "Align to Artboard" option is turned on
- In the Actions palette flyout menu, load the action set remover_2.aia
- In the Actions palette, run the action remover_2

 

In case you can tell a "safe" header/footer height area that would recognise all or most objects inside of them, the action could easily be modified.

 

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 27, 2023 Nov 27, 2023

Copy link to clipboard

Copied

LATEST

Call the script and select the folder containing the PDF.
Delete the object based on its location.
If this does not seem to work, try changing the value of [Parameters] in the script.
How does it work?

 

//Parameters
iheader_px = 80
ifooter_px = 80
iheader_margin = 20
ifooter_margin = 20
//
sFileType = "pdf"
main();

function main(){
	coordinateSystemOrg = app.coordinateSystem;
	try{
		app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
		folderRef = Folder.selectDialog("Select Folder");
		if( folderRef != false){
			fileList = folderRef.getFiles("*." + sFileType)
			if( fileList != false){
				ifl = fileList.length
				for (var i=0;i<ifl;i++){
					fileObj = new File(fileList[i].fsName);
					app.userInteractionLevel=UserInteractionLevel.DONTDISPLAYALERTS;
					open(fileObj);
					app.userInteractionLevel=UserInteractionLevel.DISPLAYALERTS;
					oDoc = app.activeDocument;
					iwidth = oDoc.artboards[0].artboardRect[2]-oDoc.artboards[0].artboardRect[0]
					iheight = oDoc.artboards[0].artboardRect[3]-oDoc.artboards[0].artboardRect[1]
					hx1 = 0;
					hy1 = 0;
					hx2 = iwidth;
					hy2 = iheader_px + iheader_margin;
					fx1 = 0
					fy1 = -(iheight + ifooter_px + ifooter_margin);
					fx2 = iwidth;
					fy2 = -iheight;
					opg = oDoc.pageItems
					ipg = opg.length
					for( j=ipg-1;j>-1;j--){
						if(checkinout(opg[j])){
							try{
								opg[j].remove()
							}catch(e){;
							};
						};
					};
					oDoc.close(SaveOptions.SAVECHANGES);
					oDoc = null
				};
			};
		};
		app.coordinateSystem = coordinateSystemOrg;
	}catch(e){;
		app.coordinateSystem = coordinateSystemOrg;
	};
}

function checkinout(obj){
	if (obj.geometricBounds){
		var x1 = obj.geometricBounds[0];
		var y1 = -obj.geometricBounds[1];
		var x2 = obj.geometricBounds[2];
		var y2 = -obj.geometricBounds[3];
		if (x1 > hx1 && x2 < hx2 && y1 > hy1 && y2 < hy2)
			return true
		else{
			if (x1 > fx1 && x2 < fx2 && y1 > fy1 && y2 < fy2)
				return true
			else{
				return false
			}
		}
	}
}

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines