Skip to main content
October 30, 2013
Answered

Exporting line end point coordinates?

  • October 30, 2013
  • 2 replies
  • 5881 views

Hi,

I'm in desperate need of a script to export the coordinates of lines, or paths, it doesn't really matter, into a text document.

I've set my ruler up so the 0,0 is in the center of the image, because I need both 0,0 and -0,-0 to work for what I have in mind, basically using a document as a large Cartesian grid, which you can then extract coordinates of 'edges' or end points of lines from.

A little background on why I need it, for anyone curious. I figured out a way to build new worlds/maps for a game that generates terrain based on 'boundaries', which are drawn on, in a 2d plane, but I need coordinates to map these boundaries correctly. I could do it manually, where I'd hover my mouse over every edge or end of the line point, but this would save a LOT of time.

I'd be insanely grateful if anyone can help me out. I've tried looking for scripts or other software, but haven't been successful at all for what I really need.

The way I have my document setup is, 1 pixel per cm, 16384x16384cm. It's quite large, so most 'graph' software won't work for it. The grid itself works fairly well, I just need a decent way to export the coordinates from it.

Thanks in advance!

Edit:

Here, I made an example of a rectangle to give you guys the idea of which coordinates I'd need:

http://i.imgur.com/VILOwrL.png

This topic has been closed for replies.
Correct answer Michael_L_Hale

Thanks for your reply!

I've tried several ways to switch the layer commands to path commands, but nothing is working. Ugh, I hate feeling so useless, lol. I've tried googling too, but I can't find the right thing. I seriously need to spend some time learning scripts from the ground up, when I find some free time.

But how would I switch it? I'm assuming I need to change the parts in bold:

var dataFile = new File('~/desktop/exportData.txt');

var doc = app.activeDocument;                   // Does the app.activedocument.pathItems[2] go here?

    for(var c =0; c<doc.layers.length;c++){

       doc.activeLayer= doc.layers;

        }

var pathItem = doc.pathItems[doc.pathItems.length-1];

var dataStream = "";

    dataStream = dataStream+doc.activeLayer.name+'\t';

for(var subPathIndex = 0;subPathIndex<pathItem.subPathItems.length;subPathIndex++){

    for(var pointIndex = 0;pointIndex<pathItem.subPathItems[subPathIndex].pathPoints.length;pointIndex++){ 

        dataStream = dataStream+pathItem.subPathItems[subPathIndex].pathPoints[pointIndex].anchor+'\t';

    }

}

dataFile.open('w');

dataFile.write(dataStream);

dataStream = dataStream+'\r';

dataFile.close();

And thank you so much for the comment about the 'dataStream+'\r', worked perfect when I moved it outside and the ' dataStream = dataStream+doc.activeLayer.name+'\t';' out of the for function.

Sorry that this keeps dragging on, it's near exactly what I want, also sorry for the earlier cofusion on what I wanted.


var dataFile = new File('~/desktop/exportData.txt');

var doc = app.activeDocument;

var dataStream = "";

// loop the paths in the document

for(var pathIndex =0; pathIndex<doc.pathItems.length;pathIndex++){

    var pathItem = doc.pathItems[pathIndex];

    // for every path output the name

    dataStream = dataStream+pathItem.name+'\t';

    for(var subPathIndex = 0;subPathIndex<pathItem.subPathItems.length;subPathIndex++){

        for(var pointIndex = 0;pointIndex<pathItem.subPathItems[subPathIndex].pathPoints.length;pointIndex++){

            // for every pathPoint output the anchor position

            dataStream = dataStream+pathItem.subPathItems[subPathIndex].pathPoints[pointIndex].anchor+'\t';

        }

    }

    // before starting the next loop add a line break

    dataStream = dataStream+'\r';

}

// now that all the paths have been collected write the info to the file

dataFile.open('w');

dataFile.write(dataStream);

dataFile.close();

2 replies

Inspiring
October 31, 2013

Can't yuo use

Export > Paths to Illustrator?

The image has 1000 x 1000 Pixels. The path starts and ends at 500,500.

The numerical values are not integer pixel coordinates but somewhat rounded.

The path in the image is not stroked (for clean information). It's a screenshot

of the unstroked path as shown in Photoshop.

Best regards --Gernot Hoffmann

Text file :

%!PS-Adobe-2.0
%%Creator: Adobe Photoshop(TM) Pen Path Export 7.0
%%Title: (Path.ai)
%%DocumentProcSets: Adobe_Illustrator_1.1 0 0
%%ColorUsage: Black&White
%%BoundingBox: 0 0 1000 1000
%%HiResBoundingBox: 0 0 1000 1000
%AI3_Cropmarks: 0 0 1000 1000
%%DocumentPreview: None
%%EndComments
%%EndProlog
%%BeginSetup
Adobe_Illustrator_1.1 begin
n
%%EndSetup
0.0 0.0 0.0 1.0 k
0 i 0 J 0 j 1 w 4 M []0 d
%%Note:
500.7495 499.2504 m
500.7495 899.5502 l
800.5996 899.5502 l
800.5996 100.4497 l
500.7495 499.2504 l
n
500.7495 499.2504 m
500.7495 899.5502 l
800.5996 899.5502 l
800.5996 100.4497 l
500.7495 499.2504 l
n
%%Trailer
%%EOF

October 31, 2013

I tried, sadly I get this error:

"The document is too big for the coordinate space of illustrator."

The problem is, in order to get the correct coordinates I need for the game map, I need to have a 16384x16384 sized image in photoshop with a pixel per cm of 1, which makes the document 270mb big.

Or is there another way to get coordinates of that size?

Maybe Photoshop isn't the right software for it, but I can't find anything else and I can do it manually in PS, it's just really slow, even if I could record mouse clicks based on the 16384x16384 image coordinates, that could work, but yeah.

Well even if I do it purely in pixels and not cm, including the ruler, I still have the same problem.

__________________________

@JJMack, oh wow, that did the trick, beautiful. Is there any way to not limit it to a specific layer name? So it just chooses the active layer and exports the layer name too? Of to export multiple layer coordinates accompanied with their name?

This is a longshot, but it also wouldn't be possible to either create a new .txt file every time you run the script, besides overwriting the one it made the previous time, right? I can do a workaround with a file copying script, so it's not that big of a deal. Of course the most ideal would be to ADD into the same .txt, without replacing what you previously exported, but I doubt that's possible based on the scripts I've looked at.

Thanks so much!

JJMack
Community Expert
Community Expert
October 31, 2013

Jusr read the script. Its creating a new file with a fixed name.  You can change that to whatever you desire to do.

The script is designed to process one layer by name you can change that.   You can loop through all layers looking name or types of layers or layer with path the process should be designed for your documents design.

JJMack
Inspiring
October 31, 2013

This is an example of how to export the path points of the shape layer to a tab separated value text file.

var dataFile = new File('~/desktop/exportData.txt');

var doc = app.activeDocument;

doc.activeLayer = doc.artLayers.getByName('Rectangle 1');

var pathItem = doc.pathItems[doc.pathItems.length-1];

var dataStream = "";

for(var subPathIndex = 0;subPathIndex<pathItem.subPathItems.length;subPathIndex++){

    for(var pointIndex = 0;pointIndex<pathItem.subPathItems[subPathIndex].pathPoints.length;pointIndex++){

        dataStream = dataStream+pathItem.subPathItems[subPathIndex].pathPoints[pointIndex].anchor+'\t';

    }

}

dataFile.open('w');

dataFile.write(dataStream);

dataFile.close();

October 31, 2013

Thanks for the reply!

I have a problem with that script, it's spitting out way wrong coordinates:.

-172743.763692396,-8844.11786544597

-86003.376935138,-8844.11786544597

-86003.376935138,23811.086560816

172743.763692396,23811.086560816

Even if I ignore what's after the decimal point, they go well beyond the cm coordinates I have, which range from -8192 to 8192. I've done the rectangle as a path.

Also, is it possible to export the coordinates of multiple layers, seperated by the layer name? Or to automatically grab the layer name of the selected layer that's different than 'Rectangle 1', at least?

Thanks again!

JJMack
Community Expert
Community Expert
October 31, 2013

Try changing your Photoshop current ruler units to pixels.

// save Photoshop settings local variables

var orig_ruler_units = app.preferences.rulerUnits;

 

// Set Photoshot behavior

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

var dataFile = new File('~/desktop/exportData.txt');

var doc = app.activeDocument;

doc.activeLayer = doc.artLayers.getByName('Rectangle 1');

var pathItem = doc.pathItems[doc.pathItems.length-1];

var dataStream = "";

for(var subPathIndex = 0;subPathIndex<pathItem.subPathItems.length;subPathIndex++){

    for(var pointIndex = 0;pointIndex<pathItem.subPathItems[subPathIndex].pathPoints.length;pointIndex++){

        dataStream = dataStream+pathItem.subPathItems[subPathIndex].pathPoints[pointIndex].anchor+'\t';

    }

}

dataFile.open('w');

dataFile.write(dataStream);

dataFile.close();

// restore Photoshop settings

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

JJMack