?
Solved

How do I create Illustrator Script to resize image not based on percentage?

Posted on 2011-02-18
2
Medium Priority
?
1,864 Views
Last Modified: 2012-05-11
I need a script that will resize a layer and if at all possible group all pageitems together before it resizes it. Or if there is a better way, please let me know. here is the script that I have currently. Right now it will resize the layer 50%, I need it to size based on "pt", I want the Height of all images ran through this script to be 100pt and the width to be proportionate to that.

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // now to resize based on the percentage
        layerRef.pageItems[0].resize(50,50);
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0
Comment
Question by:agosselinelt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Author Comment

by:agosselinelt
ID: 34930382
I have been able to modify my script to do what I need, but I still need to group the items before I can use it (ctrl+a then ctrl+g) then I run the script and everything is resized how I need. Is there a way I can script the grouping? Also here is my code for reference:

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // generate percentage from height
        var percRef = (100/layerRef.pageItems[0].height*100);
        // now to resize based on the percentage
        layerRef.pageItems[0].resize( percRef , percRef );
        alert( [percRef] );
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0
 

Accepted Solution

by:
agosselinelt earned 0 total points
ID: 34930580
I have been able to group the items here is the full code:

try {
	if (app.documents.length == 0 ) {
		throw new Error('There are no document open!');
        }
	else{
        var docRef = app.activeDocument;
        var layerRef = docRef.layers[0];
        // group pageItems
        layerRef.hasSelectedArtwork=true;
        docSelection = app.activeDocument.selection;
        newGroup = app.activeDocument.groupItems.add();
        for ( i = 0; i < docSelection.length; i++ ) {
            newItem = docSelection[i];
            newItem.moveToBeginning( newGroup );
        }
        // generate percentage from height
        var percRef = (100/layerRef.pageItems[0].height*100);
        // now to resize based on the percentage
        layerRef.pageItems[0].resize( percRef , percRef );
        alert( [percRef] );
    }
}
catch(e) {
	alert( e.message, "Script Alert", true);
}

Open in new window

0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I’ll explain how I make a clipping mask out of several separate vector objects by using the Compound Path option in Adobe Illustrator. A compound path in Illustrator allows grouping of separate objects into one set of vector paths t…
: Microsoft Office Collaborate for free and online versions of Microsoft  Word, Excel, Powerpoint, OneNote, Onedrive , Email, Calendar etc. In short we can say that Microsoft office is a suite of servers, applications and services developed by  Micr…
In this tutorial viewers will learn how to type text that isn't in a straight line by using the Type on a Path tool in Illustrator Open a document in Illustrator: Draw a path for the text to be typed upon. Don't worry about the fill or stroke as the…
In this Micro Tutorial viewers will learn the basic shortcuts and functions of Illustrator. The viewer will learn about the paintbrush tool, anchor points, font sizing, and more.
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question