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

How to divide an image into many pieces by selecting by coordinates

New Here ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

I have a large SVG with many Pieces, i want to make a selection by position. 

 

How I can select only items width a specific position? 

 

I mean bere in my code I have a for loop, this loop give me informations about x and y position of all elment in a document. 

 

I want to save in another document, only element in a particular range.

 

 

(function () {

var doc = app.activeDocument;
for (var index = 0; index < 10; index++) {
var pos = doc.pathItems[index].position;
alert('1) X: ' + pos[0] + ', Y: ' + pos[1] ); 

}

 

 

Something like this:

 

If ( pos[0] < 10 and pos[1] > 1 and pos[0]>20 and pos[1]<10 ) {

group items 

Save to another file.

}

 

 

 

TOPICS
Scripting

Views

107

Translate

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
Adobe
Community Expert ,
Apr 02, 2021 Apr 02, 2021

Copy link to clipboard

Copied

LATEST

your sample condition doesn't make any sense. you're checking to see if pos[0] is < 10 and if it's > 20. Since you only have ands in the conditional, it can never be true, since each statement in the condition must evaluate to true. 

 

Setting that aside, this might do what you want (assuming you update the conditional to match your needs.. i just made up some numbers). You'll also need to input a path (including file name and extension) for saving the new document.

function blah()
{
	var doc = app.activeDocument;
	var newDoc = app.documents.add();
	var newGroup = newDoc.groupItems.add();
	doc.activate();
	var newDocFilePath = "/Path/To/File.ai";

	var pos,curItem,duplicateItem;
	for (var index = 0; index < 10; index++)
	{
		curItem = doc.pathItems[index];
		pos = curItem.position;

		if (pos[0] > 10 && pos[0] < 20 && pos[1] > 50 && pos[1] < 70)
		{
			duplicateItem = curItem.duplicate(newDoc);
			duplicateItem.moveToBeginning(newGroup);
		}
		
		newDoc.saveAs(File(newDocFilePath));
	}
}
blah();

  

Votes

Translate

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