I just downloaded the SDK and it seems like a vast amount of information for something pretty simple that I need to do.
I need to get all the sizes and coordinates/location refs of all layers (in reference to the document they are placed in) move them, and to output it all to txt/xml.
Basically I'm making an image/sprite packer plug-in similar to this but integrated will photoshop: http://homepage.ntlworld.com/config/imagepacker/
I'll probably end up using an action/scripting for the non-essential parts so all I need is the layer/movement refs for working with my packing algorithms.
Any help would be very much appreciated, even if it is just pointing out where to find this info in the SDK's PDFs, or kicking some code my way ;), it would be great.
How to get all layer coords, sizes, and...
James_Caldwell@adobeforums.com wrote:
%26gt; I need to get all the sizes and coordinates/location refs of all layers (in reference to the document they are placed in) move them, and to output it all to txt/xml.
You can do all of this easily enough with JavaScript. If you have large numbers
of layers (%26gt;%26gt;500) it may slow a bit if you code via the DOM, but you can always
drop down to lower-level code if you really need every last bit of performance
and want to stay in JS.
-X
How to get all layer coords, sizes, and...
Yes, but does javascript support FIO streams for saving/reading txt files in photoshop?
The only way I thought this would be possible was if there was some way to script custom log files, but it sounded too hackish to me.
James_Caldwell@adobeforums.com wrote:
%26gt; Yes, but does javascript support FIO streams for saving/reading txt files in photoshop?
The JavaScript in Adobe CS* products has fairly good File class supporting IO
plain ASCII, UTF, binary, and other encodings. I have libs/APIs for doing binary
IO for stuff like BE/LE words and IEEE754 floating point.
Search for the JavaScript Tools Guide for CS3 on the adobe site for docs on the
File and Folder classe. It's probably under devnet/bridge/
-X
Okay, I'm looking into scripting right now, but if I wanted this plug-in to be 7.0 compatible I would need to use C++ because Bridge was introduced with CS2, right?
James_Caldwell@adobeforums.com wrote:
%26gt; Okay, I'm looking into scripting right now, but if I wanted this plug-in to be 7.0 compatible I would need to use C++ because Bridge was introduced with CS, right?
No.
First off, scripts aren't plug-ins. It's a completely different programming model.
Second, the docs for File/Folder in CS3 are in Tools Guide which is provided
with Bridge (which is provided with PSCS3). File/Folder are available is PSCS3
with or without Bridge.
Third, you are fine going back to PS7. That's when scripting was introduced.
There are some quirks (BINARY encoding is not directly support, though I do have
a workaround), but it is easy enough to write scripts that are compatible from
PS7 through to CS3 provided you don't need any UI. If you need UI, you can only
go back to PSCS.
-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
Right C++ is for the plug-in and scripts are run in the PS 7.0 with a plug-in, but I was trying to decide which route to go.
I have the SDK, but I'll just go with javascript for now.
I don't need any UI, if worst comes to worst I can just make different scripts most likely.
BTW, I can't test this at the moment as I don't have PS here, but maybe you can let me know if I'm doing anything wrong so far:
In javascript:
//====================================================
//Retrieving Layer data:
// ref acitve doc's top layer:
var my_layer = app.activeDocument.Artlayers[0];
var my_layer_bounds = my_layer.bounds; // bounds returns an array of x, y, w, h
var my_layer_height = my_layer_bounds[3] //ref the layer height?
var my_string = '''' + my_layer_height; //put the height into a string?
//move the layer 100 pixels up and 100 pixels to the right:
my_layer.translate(100, 100);
//File Writing:
//create a new fileObj named file_name.txt:
var my_file = new fileObj(''file_name.txt'');
//write 3 strings on 3 lines:
my_file.write(my_string (''string_2'' , ''string_3''));
my_file.close();
//=====================================================
Also, doesn't Adobe have a free IDE for scripting Photoshop? Do you know where I can get/find it?
okay, ignore the above...
This is what I got now:
//====================================================
//Retrieving Layer data:
// ref acitve doc's top layer:
var my_layer = activeDocument.artLayers[0];
var my_layer_bounds = my_layer.bounds; // bounds returns an array of x, y, w, h
var my_layer_height = ''my_layer_bounds[3]''; //ref the layer height?
var my_string = '''' + my_layer_height; //put the height into a string?
//move the layer 100 pixels up and 100 pixels to the right:
my_layer.translate(0.01, -0.01);
//File Writing:
my_file = new File(path.toString() + ''my_ps7.txt'');
//write 3 strings on 3 lines:
my_file.write(''my_ps7.txt'', ''string_3'');
my_file.close();
//=====================================================
James_Caldwell@adobeforums.com wrote:
%26gt;
%26gt; //Retrieving Layer data:
%26gt;
%26gt; // ref acitve doc's top layer:
%26gt; var my_layer = app.activeDocument.Artlayers[0];
should be
var my_layer = app.activeDocument.artLayers[0];
The description in the docs sometimes seems a bit confused WRT capitalization.
Classes and constants are capitalized, methods and properties aren't.
%26gt;
%26gt; var my_layer_bounds = my_layer.bounds; // bounds returns an array of x, y, w, h
%26gt;
%26gt; var my_layer_height = my_layer_bounds[3] //ref the layer height?
Nope.
var my_layer_height = my_layer_bounds[3]-my_layer_bounds[1];
%26gt;
%26gt; var my_string = '''' + my_layer_height; //put the height into a string?
%26gt;
%26gt; //move the layer 100 pixels up and 100 pixels to the right:
%26gt; my_layer.translate(100, 100);
This goes down and to the right. The upper left corner is 0,0 in PS.
%26gt;
%26gt; //File Writing:
%26gt;
%26gt; //create a new fileObj named file_name.txt:
%26gt; var my_file = new fileObj(''file_name.txt'');
%26gt;
More like:
var my_file = new File(''/c/file_name.txt'');
You need a my_file.open(''w'');
%26gt; //write 3 strings on 3 lines:
%26gt; my_file.write(my_string (''string_2'' , ''string_3''));
my_file.writeln(my_string + ''\nstring_2\nstring_3''));
%26gt;
%26gt; my_file.close();
%26gt;
%26gt; //=====================================================
%26gt;
%26gt; Also, doesn't Adobe have a free IDE for scripting Photoshop? Do you know where I can get/find it?
It comes bundled with CS2 and CS3.
If you have any other questions, I suggest asking over on the PS scripting forum.
-X
--
for photoshop scripting solutions of all sorts
contact: xbytor@gmail.com
Hey thanks a lot, I actually got all of the file writing working because of your getter example on your PS script forum.
Do you prefer using that forum?
If so I'll just move over there.
James_Caldwell@adobeforums.com wrote:
%26gt; Do you prefer using that forum?
For JS stuff, yep.
%26gt;
%26gt; If so I'll just move over there.
I'm surprised Chris C. hasn't chased over there already :)
-X
Oh, btw I meant your execute example, not your getter.
Alright, I moved my posts over here at least until I get activated by your people.
http://www.adobeforums.com/cgi-bin/webx/.3bbf2765.3bc48105
I wrote a program (%26lt;a href=''http://www.telegraphics.com.au/sw/#psdparse''%26gt;psdparse%26lt;/a%26gt;) which extracts all this layer information from a PSD on disk, to XML if you wish (Photoshop is not required). Sample output:%26lt;br /%26gt;%26lt;br /%26gt;%26lt;pre%26gt;%26lt;br /%26gt;$ ./psdparse ../testpsd/slashtest.psd --xmlout%26lt;br /%26gt;%26lt;?xml version=''1.0''?%26gt;%26lt;br /%26gt;%26lt;PSD FILE='../testpsd/slashtest.psd' VERSION='1' CHANNELS='3' ROWS='72' COLUMNS='72' DEPTH='8' MODE='3' MODENAME='RGBColor'%26gt;%26lt;br /%26gt; %26lt;LAYER NAME='Background' TOP='0' LEFT='0' BOTTOM='72' RIGHT='72' WIDTH='72' HEIGHT='72'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;BLENDMODE OPACITY='100' CLIPPING='0'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;NORMAL /%26gt; %26lt;!-- not parsed --%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;TRANSPARENCYPROTECTED /%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;/BLENDMODE%26gt;%26lt;br /%26gt; %26lt;/LAYER%26gt;%26lt;br /%26gt;%26lt;br /%26gt; %26lt;LAYER NAME='abc/def' TOP='26' LEFT='31' BOTTOM='57' RIGHT='68' WIDTH='37' HEIGHT='31'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;BLENDMODE OPACITY='100' CLIPPING='0'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;NORMAL /%26gt; %26lt;!-- not parsed --%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;/BLENDMODE%26gt;%26lt;br /%26gt; %26lt;/LAYER%26gt;%26lt;br /%26gt;%26lt;br /%26gt; %26lt;LAYER NAME='a/b/c/de/fg' TOP='12' LEFT='7' BOTTOM='43' RIGHT='44' WIDTH='37' HEIGHT='31'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;BLENDMODE OPACITY='100' CLIPPING='0'%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;NORMAL /%26gt; %26lt;!-- not parsed --%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;TRANSPARENCYPROTECTED /%26gt;%26lt;br /%26gt; %26amp;nbsp ; %26lt;/BLENDMODE%26gt;%26lt;br /%26gt; %26lt;/LAYER%26gt;%26lt;br /%26gt;%26lt;br /%26gt; %26lt;COMPOSITE CHANNELS='3' HEIGHT='72' WIDTH='72'%26gt;%26lt;br /%26gt; %26lt;/COMPOSITE%26gt;%26lt;br /%26gt;%26lt;/PSD%26gt;%26lt;br /%26gt;%26lt;br /%26gt;%26lt;/pre%26gt;
Thanks Toby but the layer need to be manipulated using the dimension info right before they are saved so it's just more work to have another program do this.
Gotcha - I missed that bit :)
Subscribe to:
Post Comments
(Atom)
No comments:
Post a Comment