Skip to main content
rcraighead
Legend
December 29, 2018
Answered

How to scale selection - from center - based on Selection?

  • December 29, 2018
  • 2 replies
  • 1828 views

I have a snippet that gets the width of the current selection and scales a named path by percentage or set amount. But I don't know how to make it scale from the CENTER. It only scales from the left. I also tried "resize" but could not get it to work at all. What am I doing wrong?

var aDoc = app.activeDocument

var myItem = aDoc.selection[0];

var dimensions = {"width" : myItem.width, "height" : myItem.height};

aDoc.pathItems.Divider.width = myItem.width+20 //add points

//aDoc.pathItems.Divider.width = myItem.width*1.20 //by percentage

//~ aDoc.pathItems.Divider.resize(

//~ myItem.width*1.1, //x

//~ 100.0, // y

//~ false, // changePositions

//~ false, // changeFillPatterns

//~ false, // changeFillGradients

//~ false, // changeStrokePattern

//~ false , // changeLineWidths

//~ Transformation.CENTER); // scaleAbout

This topic has been closed for replies.
Correct answer renél80416020

EDIT: The site won't let me upload an image at the moment. Here's a link: Dropbox - Screenshot 2018-12-29 11.50.52.png

The "Selection" is the text. I want to scale the "Divider" line based on the width of the Text. My original script DID allow a calculation (aDoc.pathItems.Divider.width = myItem.width*1.2) but scaled the line from the left.

Using "resize" method does not seem to allow for "Calculations". Is that correct?

Example File.


Salut !

var aDoc = app.activeDocument

var myItem = aDoc.selection[0];

var Divider = aDoc.pathItems[0];

    scale =  myItem.width/Divider.width*100;

    Divider.resize(scale,100);

2 replies

rcraighead
Legend
January 1, 2019

I realized when implementing this script that it was not actually targeting the path by name and could therefore select a path on a layer above. I've changed it slightly so it targets the specific path named "Divider".

var aDoc = app.activeDocument

var myItem = aDoc.selection[0];

var Divider = aDoc.pathItems.getByName("Divider");

scale =  myItem.width/Divider.width*100+8;

Divider.resize(scale,100);

pixxxelschubser
Community Expert
Community Expert
December 29, 2018

Try

var sel = app.activeDocument.selection[0];

sel.resize(120 /*scale x %*/,  120 /* scale y %*/, true, true, true, true, 120 /*scale strokeWidth % */, Transformation.CENTER);

resize in %

rcraighead
Legend
December 29, 2018

Thanks, pixxxel.

I'm actually trying to scale a path Item named "Divider" to the size of the current selection plus a given amount (by % or set amount).

The "Divider" line is between 2 text lines and should remain slightly longer than the text object width, which will vary.

If I understand your script it is scaling the current selection. I'll see if I can alter it to adjust the "Divider" element instead.

rcraighead
Legend
December 29, 2018

Show something (screenshot before and after) or better give an example file, please.


EDIT: The site won't let me upload an image at the moment. Here's a link: Dropbox - Screenshot 2018-12-29 11.50.52.png

The "Selection" is the text. I want to scale the "Divider" line based on the width of the Text. My original script DID allow a calculation (aDoc.pathItems.Divider.width = myItem.width*1.2) but scaled the line from the left.

Using "resize" method does not seem to allow for "Calculations". Is that correct?

Example File.