Copy link to clipboard
Copied
Hi forum.
I have placed some shapes on my PS canvas. Is there a way which PS can locate the X and Y positions of each object individually? I need to know the position of each object in the corner where the blue dot is. I know I can do it manually for each object, But for this example there are 7 objects, what if there were 30 or 40 and I needed to know their X and Y position.
Thank you.
Anpther script, this one creates an alert with the selected layers’ names, ID and bounds:
// 2020, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var theLayers = collectSelectedLayersBounds ();
alert (theLayers.join("\n"));
};
////// collect bounds of selected layers //////
function collectSelectedLayersBounds () {
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// get selected layers;...
Copy link to clipboard
Copied
A script that shows lay
// enable double-clicking from Mac Finder or Windows Explorer
#target photoshop // this command only works in Photoshop CS2 and higher
// bring application forward for double-click events
app.bringToFront();
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits;
// Set Photoshop to use pixels
app.preferences.rulerUnits = Units.PIXELS;
try{
var LB = activeDocument.activeLayer.bounds;
var LWidth = (LB[2].value) - (LB[0].value);
var LHeight = (LB[3].value) - (LB[1].value);
MarkX((LB[0].value + LWidth/2));
MarkX(LB[0].value);
MarkX(LB[2].value);
MarkY((LB[1].value + LHeight/2));
MarkY(LB[1].value)
MarkY(LB[3].value)
alert("'" + activeDocument.activeLayer.name + "' Layer Bounds\nTop Left " + LB[0].value + "X," + LB[1].value + "Y Bottom Right " + LB[2].value + "X," + LB[3].value
+ "Y\nWidth " + LWidth + "px Height " + LHeight +"px"
+ "\nLayer center relative to canvas " + (LB[0].value + LWidth/2) + "X," + (LB[1].value + LHeight/2) +"Y"
, "Layer Bounds Info");
}
catch(e){alert("Requires a layer targered");}
// Return the app preferences
app.preferences.rulerUnits = startRulerUnits;
function MarkX(x) {
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc61 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc62 = new ActionDescriptor();
var idPstn = charIDToTypeID( "Pstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc62.putUnitDouble( idPstn, idPxl, x);
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idVrtc = charIDToTypeID( "Vrtc" );
desc62.putEnumerated( idOrnt, idOrnt, idVrtc );
var idGd = charIDToTypeID( "Gd " );
desc61.putObject( idNw, idGd, desc62 );
executeAction( idMk, desc61, DialogModes.NO );
}
function MarkY(y) {
// =======================================================
var idMk = charIDToTypeID( "Mk " );
var desc63 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc64 = new ActionDescriptor();
var idPstn = charIDToTypeID( "Pstn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc64.putUnitDouble( idPstn, idPxl, y );
var idOrnt = charIDToTypeID( "Ornt" );
var idOrnt = charIDToTypeID( "Ornt" );
var idHrzn = charIDToTypeID( "Hrzn" );
desc64.putEnumerated( idOrnt, idOrnt, idHrzn );
var idGd = charIDToTypeID( "Gd " );
desc63.putObject( idNw, idGd, desc64 );
executeAction( idMk, desc63, DialogModes.NO );
}
er bounds
Copy link to clipboard
Copied
Thanks for this JJmack. never done this sort of thing before, i saw some tutorials on YT, dont know if it's correct though/
So I need to make a Javascript note, and then open PS> Browse, and select the Java note?
Copy link to clipboard
Copied
Some things one wants to do in Photoshop can be automated using Photoshop's automation feature. Photoshop has two features users can use to automate some processing. Photoshop Action Feature and Photoshop Scripting Feature. Photoshop Actions Palette is more or less like a tape recorder that cam record and playback Photoshop steps. These recording can also be edited using the features in the action palette. So it is a device the is relatively easy to use and understand. However it limited to what can be recorded and edited into the recorded actions. The playback is always the same sequence of Photoshop steps with the same recorded settings. Scripting also automates Photoshop steps however steps use can have the setting changed by the script and the step used can vary for the documents content. With you are programming Photoshop operation. It requires programming skills and designing skills. It is Powerful. You could write a Photoshop Script to process your document. To do what you want to automate its programming. A Script could be programmed to look at all the layers in your document note all the normals raster layers Names where their top left origin is and the stack level. This note could be put out as a message. Added as a text layer, recorder into a file you know what you want I do not. You programs want you require. You may have used some scrips for some are install by Adobe. Some are menu Items in Photoshop. Your would be in menu File>Scripts>Your Script Name. These are Adobe Names:
"ArtBoards To Files.jsx"
"ArtBoards To PDF.jsx"
"Conditional Mode Change.jsx"
"ContactSheetII.jsx"
"Delete All Empty Layers.jsx"
"Export For Aero.jsx"
"Export Layers To Files.jsx"
"ExportColorLookupTables.jsx"
"Fit Image.jsx"
"Flatten All Layer Effects.jsx"
"Flatten All Masks.jsx"
"generate.jsx"
"Image Processor.jsx"
"Layer Comps To Files.jsx"
"Layer Comps To PDF.jsx"
"Lens Correct.jsx"
"Load DICOM.jsx"
"Load Files into Stack.jsx"
"Merge To HDR.jsx"
"Photomerge.jsx"
"Script Events Manager.jsx"
"Statistics.jsx"
Copy link to clipboard
Copied
Anpther script, this one creates an alert with the selected layers’ names, ID and bounds:
// 2020, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var theLayers = collectSelectedLayersBounds ();
alert (theLayers.join("\n"));
};
////// collect bounds of selected layers //////
function collectSelectedLayersBounds () {
// set to pixels;
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
// get selected layers;
var selectedLayers = new Array;
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var desc = executeActionGet(ref);
if( desc.hasKey( stringIDToTypeID( 'targetLayers' ) ) ){
desc = desc.getList( stringIDToTypeID( 'targetLayers' ));
var c = desc.count;
var selectedLayers = new Array();
// run through selected layers;
for(var i=0;i<c;i++){
try{activeDocument.backgroundLayer;
var theIndex = desc.getReference( i ).getIndex();
}catch(e){var theIndex = desc.getReference( i ).getIndex()+1 };
// get id for solid color layers;
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID("Lyr "), theIndex );
var layerDesc = executeActionGet(ref);
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
selectedLayers.push([theName, theIdentifier, theseBounds]);
} catch (e) {};
};
// if only one:
}else{
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
try {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theIdentifier = layerDesc.getInteger(stringIDToTypeID ("layerID"));
var theBounds = layerDesc.getObjectValue(stringIDToTypeID("bounds"));
var theseBounds = [theBounds.getUnitDoubleValue(stringIDToTypeID("left")), theBounds.getUnitDoubleValue(stringIDToTypeID("top")), theBounds.getUnitDoubleValue(stringIDToTypeID("right")), theBounds.getUnitDoubleValue(stringIDToTypeID("bottom"))];
selectedLayers = [[theName, theIdentifier, theseBounds]]
} catch (e) {};
};
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return selectedLayers;
};
Should You decide to pursue Scripting »photoshop-javascript-ref-2020.pdf«, »photoshop-scripting-guide-2020.pdf« and the Sample Scripts should offer a starting point and one can always ask for advice on the Forum.
Save the code as a txt-file, change the extension to .jsx and copy it into Photoshop’s Presets/Scripts-Folder; after restarting Photoshop it should be available under File > Scripts and can be assigned a Shortcut or used in an Action.
Copy link to clipboard
Copied
I ran both scripts which inticate the X & Y value.
Im not sure if JJmack script Im doing something incorrect, as it's shwoing only one layer instead of all the layers X & Y.
I also ran c_pfaffenbichler script which lists the X & Y values of all the layers, but I cannot understand there is a number before the X & Y. what does this number symbolise?
Copy link to clipboard
Copied
The Script I posted gives the name and the identifier first.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now