layer resize and move script error problem

New Here ,
Jan 07, 2021

Copy link to clipboard

Copied

i made  this script

size change is good

but  i postion is error

i would like to make same posion ?

 

pls  can you say porblem?

 

 

var doc = activeDocument;

var t = doc.artLayers.getByName("or");

var a = doc.artLayers.getByName("de");

var textHeight = t.bounds[3].value - t.bounds[1].value;

var artHeight = a.bounds[3].value - a.bounds[1].value;

var textwidth = t.bounds[2].value - t.bounds[0].value;

var artwidth = a.bounds[2].value - a.bounds[0].value;


a.resize(textwidth/artwidth*100, textHeight/artHeight*100, AnchorPosition.MIDDLECENTER);


var width = t.bounds[3]-a.bounds[3];
var length = t.bounds[2]-a.bounds[2];

a.translate( width, length )

TOPICS
How to

Views

33

Likes

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

layer resize and move script error problem

New Here ,
Jan 07, 2021

Copy link to clipboard

Copied

i made  this script

size change is good

but  i postion is error

i would like to make same posion ?

 

pls  can you say porblem?

 

 

var doc = activeDocument;

var t = doc.artLayers.getByName("or");

var a = doc.artLayers.getByName("de");

var textHeight = t.bounds[3].value - t.bounds[1].value;

var artHeight = a.bounds[3].value - a.bounds[1].value;

var textwidth = t.bounds[2].value - t.bounds[0].value;

var artwidth = a.bounds[2].value - a.bounds[0].value;


a.resize(textwidth/artwidth*100, textHeight/artHeight*100, AnchorPosition.MIDDLECENTER);


var width = t.bounds[3]-a.bounds[3];
var length = t.bounds[2]-a.bounds[2];

a.translate( width, length )

TOPICS
How to

Views

34

Likes

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
Jan 07, 2021 0
Most Valuable Participant ,
Jan 07, 2021

Copy link to clipboard

Copied

var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;	// Set the ruler units to PIXELS


var doc = activeDocument;
var t = doc.artLayers.getByName("or");
var a = doc.artLayers.getByName("de");
var textHeight = t.bounds[3].value - t.bounds[1].value;
var artHeight = a.bounds[3].value - a.bounds[1].value;
var textwidth = t.bounds[2].value - t.bounds[0].value;
var artwidth = a.bounds[2].value - a.bounds[0].value;
a.resize(textwidth/artwidth*100, textHeight/artHeight*100, AnchorPosition.MIDDLECENTER);
var width = t.bounds[3]-a.bounds[3];
var length = t.bounds[2]-a.bounds[2];
//a.translate( width, length )

activeDocument.activeLayer=t;
var LB = activeDocument.activeLayer.bounds;
var selectedRegion = Array(Array(LB[0].value,LB[1].value), Array(LB[2].value,LB[1].value), Array(LB[2].value,LB[3].value), Array(LB[0].value,LB[3].value));
doc.selection.select(selectedRegion);
activeDocument.activeLayer=a;
align('AdCH'); 
align('AdCV');
doc.selection.deselect();

app.preferences.rulerUnits = orig_ruler_units;	// Reset units to original settings


function align(method) {
	var desc = new ActionDescriptor();
	var ref = new ActionReference();
	ref.putEnumerated( charIDToTypeID( "Lyr " ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
	desc.putReference( charIDToTypeID( "null" ), ref );
	desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );
	try{
		executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );
	}catch(e){}
}
JJMack

Likes

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
Reply
Loading...
Jan 07, 2021 0
Adobe Community Professional ,
Jan 07, 2021

Copy link to clipboard

Copied

Are you actually getting an error or is it not lining up how you want it? You are lining up the bottom right corner. Also, you might want to put in .value on the calculations for moving.

Likes

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
Reply
Loading...
Jan 07, 2021 0
JJMack LATEST
Most Valuable Participant ,
Jan 07, 2021

Copy link to clipboard

Copied

They made the calculation for moving the layer based on the layers originals bounds. They changed the layer bounds when they resized the layer so the move they made was incorrect for the layers change size  the calculations used the top left corners in the calculation not the layers centers. I think   It look like the used the bound after the resize. still the  move was off and  adding  the .value did not solve the issue so I just aligned the layer to the text layer since the size was right. They switch x and y values

 

 

Taken a closer look I assumed they used top left corner look closer I was wrong changed their code to the top left works.

 

 

 

var orig_ruler_units = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;	// Set the ruler units to PIXELS

var doc = activeDocument;
var t = doc.artLayers.getByName("or");
var a = doc.artLayers.getByName("de");
var textHeight = t.bounds[3].value - t.bounds[1].value;
var artHeight = a.bounds[3].value - a.bounds[1].value;
var textwidth = t.bounds[2].value - t.bounds[0].value;
var artwidth = a.bounds[2].value - a.bounds[0].value;
a.resize(textwidth/artwidth*100, textHeight/artHeight*100, AnchorPosition.MIDDLECENTER);

var width = t.bounds[0].value-a.bounds[0].value;
var length = t.bounds[1].value-a.bounds[1].value;
a.translate( width, length )

app.preferences.rulerUnits = orig_ruler_units;	// Reset units to original settings

 

 

JJMack

Likes

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
Reply
Loading...
Jan 07, 2021 0