Current position:  Home > Default > Help - Difficulties with transate()

Help - Difficulties with transate()

Time:December 10
Advertisement
Hi, I am having some weird difficulties with the translate method. I am trying to reposition one of layers by using X and Y values from a CSV file. I tried to access the variables various ways. One was using part[5], (with 'part' as the variable'). Then tried setting variables for each value (as shown below). The dubber doesn't report any errors. The weird thing about it is that the code is supposedly executed, but the translate function is somehow 'ignored'. When I stop the script, I can see that it exists in the history panel. I get no errors during run time either. Can someone please help. I have no idea what is going on with this strange problem.
Also: I am working two documents. In my script I have it open an image that has a dpi of 266. The script duplicates the single layer of that file into a 72 dpi document and repositions the layer according to the x and y values defined in my CSV file. I tried setting both to 72 dpi, however nothing different happens. The only time something changes is if I put a constant number for x and y. By doing that, it doesn't even move to the spot it is suppose to. It repositions, but it is placed so far off the canvas.
//Duplicate unprocessed mugshot in its proper layer level, all-in-one step
app.documents[2].layers[0].duplicate(documents[1].layerSets[0].layerSets[part[3]].layerSet s[part[4]].artLayers[0], ElementPlacement.PLACEAFTER);
//Close unprocessed mugshot after duplicating
app.documents[2].close();
//Resize mugshot layer using a percentage
app.documents[1].layerSets[0].layerSets[part[3]].layerSets[part[4]].artLayers[1].resize(70 .7, 70.7, AnchorPosition.MIDDLECENTER);
//Reposition the image according to x and y values defined in CSV file
var x = part[5];
var y = part[6];
app.preferences.rulerUnits = Units.PIXELS;
app.documents[1].layerSets[0].layerSets[part[3]].layerSets[part[4]].artLayers[1].translate (x, y);
//Create mask clipping from mugshot layer
var desc3 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'), charIDToTypeID('Trgt') );
desc3.putReference( charIDToTypeID('null'), ref2 );
executeAction( charIDToTypeID('GrpL'), desc3, DialogModes.NO );
Advertisement
I've reworked your code a bit to use intermediate variables. This makes it
easier to read (for me, at least) and also perform better.
The translate() function is really a 'moveRelative' not a 'moveAbsolute'
function. The x and y parameters are deltas from the layers current location, so
that has to be taken into account as I've done below. BTW, I may have the terms
reversed where I compute x and y. I normally make an ActionManager-type call to
Transform to do the resize and move in one step.
-X
var doc1 = app.documents[1]
var doc2 = app.documents[2];
var ls0 = doc1.layerSets[0];
var ls3 = ls0.layerSets[part[3]];
var ls4 = ls3.layerSets[part[4]];
//Duplicate unprocessed mugshot in its proper layer level, all-in-one step
doc2.layers[0].duplicate(ls4.artLayers[0], ElementPlacement.PLACEAFTER);
//Close unprocessed mugshot after duplicating
doc2.close();
var layer = ls4.artLayers[1];
//Resize mugshot layer using a percentage
layer.resize(70.7, 70.7, AnchorPosition.MIDDLECENTER);
var bnds = layer.bounds;
//Reposition the image according to x and y values defined in CSV file
var x = part[5] - bnds[0].value;
var y = part[6] - bnds[1].value;
app.preferences.rulerUnits = Units.PIXELS;
layer.translate (x, y);
//Create mask clipping from mugshot layer
var desc3 = new ActionDescriptor();
var ref2 = new ActionReference();
ref2.putEnumerated( charIDToTypeID('Lyr '), charIDToTypeID('Ordn'),
charIDToTypeID('Trgt') );
desc3.putReference( charIDToTypeID('null'), ref2 );
executeAction( charIDToTypeID('GrpL'), desc3, DialogModes.NO );