Skip to main content
Inspiring
March 24, 2015
Question

Script to dump out all the art file document's layer, path, group, asset info?

  • March 24, 2015
  • 1 reply
  • 756 views

Say we have an AI document that has layers that may or may not contain:

  • groups
  • compound paths
  • paths
  • text boxes
  • photos & other artwork assets
  • pageItems
  • pathItems

Have to account for nested mixes of item types things within groups, compound path, etc.

Has anyone written a data dumper script to dump such things out? Say for example I just want to generically see what are all the items inside the layers of the document. Telling me it's name, positions, type, etc.

As for dumping, alert() calls are ok. Or if we used something like debrouwere/Extendables · GitHub can use the logger to log to file, or just use ExtendScript toolkit's $.writeln() call to the console.

I'm working on this, specific to my organizations needs but it's taking me some time. If someone already has such a script written, or can easily write one up that would be nice, saving me time & hassle figuring out how to do this as there's so many object types that I have to iterate through. And worse, seems some types are undefined (or null) so I have to check for that before iterating or it gets stuck in (or fail) script execution.

I'm working with javascript/ExtendScript. Not sure if it's any easier in VBScript or AppleScript.

This topic has been closed for replies.

1 reply

Inspiring
March 25, 2015

What is the overall purpose/end result?

man9ar00 wrote:    I'm working on this, specific to my organizations needs but it's taking me some time.

So, what do you have so far?

You can find examples of recursion here on the forum, as for everything else you can probably search and find examples/snippets as well. The Illustrator Javascript Scripting Reference will have the information for specific needs.

man9ar00 wrote:    If someone already has such a script written, or can easily write one up that would be nice, saving me time & hassle

Easy?

There is this thread: dump obj. properties ?And this .... http://wundes.com/JS4AI/explore.js

Otherwise (as in most cases) you are gonna have to come up with a solution specific to your requirements, \most everything should able to be researched as mentioned above.


So, what do you have so far?

man9ar00Author
Inspiring
March 26, 2015

Thanks for the comment. Those existing scripts are useful, like the dump object properties one, although it doesn't seem to handle nested objects/collections. This is what I came up with so far, in case anyone has use for it. We don't likely need to deal with all the member properties, so I only dump subsets. But what I needed was to recursively dump all collections, including nested ones.


Pardon the indentation/formatting, I just copy pasted from text editor. Sadly it doesn't quite preserve the indentations. Also this code snippet I'm sure isn't optimal, but gets the job done for the basics at least.


#include "Extendables/extendables.jsx";

var log = new logging.Log("data_dump_for_" + app.activeDocument.name + ".log"); //under Extendables/log

function ConvertPtsToInches(points,decimalPlaces){

  var psPt2in = 0.0138888889; //Postscript points to inches

  return Number((points*psPt2in).toFixed(decimalPlaces));

}

function dumpItemsFromObject(obj,indentFactor){

  var indentation = "";

  for(var t = 0; t < indentFactor; t++){

  indentation = indentation + " ";

  }

  if(!(obj.variables === undefined) && !(obj.variables === null)){

  for (var variableIndex = 0; variableIndex < obj.variables.length; variableIndex++) {

  var variable = obj.variables[variableIndex];

  log.info(indentation + "Variable: "+ variable.name + "-------------------------------------------------------");

  dumpItemsFromObject(variable,indentFactor+4);

  }

  }

  if(!(obj.layers === undefined) && !(obj.layers === null)){

  for (var layerIndex = 0; layerIndex < obj.layers.length; layerIndex++) {

  var currentLayer = obj.layers[layerIndex];

  log.info(indentation + "Layer: "+ currentLayer.name + "-------------------------------------------------------");

  dumpItemsFromObject(currentLayer,indentFactor+4);

  }

  }

  if(!(obj.groupItems === undefined) && !(obj.groupItems === null)){

  for (var groupItemIndex = 0; groupItemIndex < obj.groupItems.length; groupItemIndex++) {

  var groupItem = obj.groupItems[groupItemIndex];

  log.info(indentation + "GroupItem: "+ groupItem.name + "-------------------------------------------------------");

  log.info(indentation + "width: " + ConvertPtsToInches(groupItem.width,2));

  log.info(indentation + "height: " + ConvertPtsToInches(groupItem.height,2));

  log.info(indentation + "left: " + ConvertPtsToInches(groupItem.left,2));

  log.info(indentation + "top: " + ConvertPtsToInches(groupItem.top,2));

  log.info(indentation + "position: " + ConvertPtsToInches(groupItem.position[0],2)+","+ConvertPtsToInches(groupItem.position[1],2));

  //if(!(groupItem.zOrderPosition === undefined) && !(groupItem.zOrderPosition === null))

  // log.info(indentation + "z-index: " + groupItem.zOrderPosition);

  var tags = "";

  for(var tagIndex = 0; tagIndex < groupItem.tags.length; tagIndex++){

  tags = tags + "name: " + groupItem.tags[tagIndex].name + ", value: " + groupItem.tags[tagIndex].value + "; ";

  }

  if(tags != "") log.info(indentation + "tags: " + tags);

  dumpItemsFromObject(groupItem,indentFactor+4);

  }

  }

  if(!(obj.compoundPathItems === undefined) && !(obj.compoundPathItems === null)){

  for (var compoundPathItemIndex = 0; compoundPathItemIndex < obj.compoundPathItems.length; compoundPathItemIndex++) {

  var compoundPathItem = obj.compoundPathItems[compoundPathItemIndex];

  log.info(indentation + "CompoundPathItem: "+ compoundPathItem.name + "-------------------------------------------------------");

  log.info(indentation + "width: " + ConvertPtsToInches(compoundPathItem.width,2));

  log.info(indentation + "height: " + ConvertPtsToInches(compoundPathItem.height,2));

  log.info(indentation + "left: " + ConvertPtsToInches(compoundPathItem.left,2));

  log.info(indentation + "top: " + ConvertPtsToInches(compoundPathItem.top,2));

  log.info(indentation + "position: " + ConvertPtsToInches(compoundPathItem.position[0],2)+","+ConvertPtsToInches(compoundPathItem.position[1],2));

  //if(!(compoundPathItem.zOrderPosition === undefined) && !(compoundPathItem.zOrderPosition === null))

  // log.info(indentation + "z-index: " + compoundPathItem.zOrderPosition);

  var tags = "";

  for(var tagIndex = 0; tagIndex < compoundPathItem.tags.length; tagIndex++){

  tags = tags + "name: " + compoundPathItem.tags[tagIndex].name + ", value: " + compoundPathItem.tags[tagIndex].value + "; ";

  }

  if(tags != "") log.info(indentation + "tags: " + tags);

  dumpItemsFromObject(compoundPathItem,indentFactor+4);

  }

  }

  if(!(obj.pathItems === undefined) && !(obj.pathItems === null)){

  for (var pathItemIndex = 0; pathItemIndex < obj.pathItems.length; pathItemIndex++) {

  var pathItem = obj.pathItems[pathItemIndex];

  log.info(indentation + "PathItem: "+ pathItem.name + "-------------------------------------------------------");

  log.info(indentation + "width: " + ConvertPtsToInches(pathItem.width,2));

  log.info(indentation + "height: " + ConvertPtsToInches(pathItem.height,2));

  log.info(indentation + "left: " + ConvertPtsToInches(pathItem.left,2));

  log.info(indentation + "top: " + ConvertPtsToInches(pathItem.top,2));

  log.info(indentation + "position: " + ConvertPtsToInches(pathItem.position[0],2)+","+ConvertPtsToInches(pathItem.position[1],2));

  //if(!(pathItem.zOrderPosition === null) && !(pathItem.zOrderPosition === undefined))

  // log.info(indentation + "z-index: " + pathItem.zOrderPosition);

  if(pathItem.fillColor.typename == "RGBColor"){

  log.info(indentation + "RGB Color: " + pathItem.fillColor.red + "," + pathItem.fillColor.green +"," + pathItem.fillColor.blue);

  }

  if(pathItem.fillColor.typename == "CMYKColor"){

  log.info(indentation + "CMYK Color: " + pathItem.fillColor.cyan + "," + pathItem.fillColor.yellow +"," + pathItem.fillColor.magenta + "," + pathItem.fillColor.black);

  }

  var tags = "";

  for(var tagIndex = 0; tagIndex < pathItem.tags.length; tagIndex++){

  tags = tags + "name: " + pathItem.tags[tagIndex].name + ", value: " + pathItem.tags[tagIndex].value + "; ";

  }

  if(tags != "") log.info(indentation + "tags: " + tags);

  }

  }

  if(!(obj.textFrameItems === undefined) && !(obj.textFrameItems === null)){

  for (var textFrameItemIndex = 0; textFrameItemIndex < obj.textFrameItems.length; textFrameItemIndex++) {

  var textFrameItem = obj.textFrameItems[textFrameItemIndex];

  log.info(indentation + "TextFrameItem: "+ textFrameItem.name + "-------------------------------------------------------");

  log.info(indentation + "content: " + textFrameItem.content);

  var tags = "";

  if(textFrameItem.kind == TextType.PATHTEXT){

  var txtPath = textFrameItem.textPath;

  log.info(indentation + "    TextPathItem: "+ txtPath.name + "-------------------------------------------------------");

  log.info(indentation + "    width: " + ConvertPtsToInches(txtPath.width,2));

  log.info(indentation + "    height: " + ConvertPtsToInches(txtPath.height,2));

  log.info(indentation + "    left: " + ConvertPtsToInches(txtPath.left,2));

  log.info(indentation + "    top: " + ConvertPtsToInches(txtPath.top,2));

  log.info(indentation + "    position: " + ConvertPtsToInches(txtPath.position[0],2)+","+ConvertPtsToInches(txtPath.position[1],2));

  if(txtPath.fillColor.typename == "RGBColor"){

  log.info(indentation + "    RGB Color: " + txtPath.fillColor.red + "," + txtPath.fillColor.green +"," + txtPath.fillColor.blue);

  }

  if(txtPath.fillColor.typename == "CMYKColor"){

  log.info(indentation + "    CMYK Color: " + txtPath.fillColor.cyan + "," + txtPath.fillColor.yellow +"," + txtPath.fillColor.magenta + "," + txtPath.fillColor.black);

  }

  }

  }

  }

  if(!(obj.pageItems === undefined) && !(obj.pageItems === null)){

  for (var pageItemIndex = 0; pageItemIndex < obj.pageItems.length; pageItemIndex++) {

  var pageItem = obj.pageItems[pageItemIndex];

  log.info(indentation + "PageItem: "+ pageItem.name + "-------------------------------------------------------");

  log.info(indentation + "width: " + ConvertPtsToInches(pageItem.width,2));

  log.info(indentation + "height: " + ConvertPtsToInches(pageItem.height,2));

  log.info(indentation + "left: " + ConvertPtsToInches(pageItem.left,2));

  log.info(indentation + "top: " + ConvertPtsToInches(pageItem.top,2));

  log.info(indentation + "position: " + ConvertPtsToInches(pageItem.position[0],2)+","+ConvertPtsToInches(pageItem.position[1],2));

  //if(!(pageItem.zOrderPosition === null) && !(pageItem.zOrderPosition === undefined))

  // log.info(indentation + "z-index: " + pageItem.zOrderPosition);

  var tags = "";

  for(var tagIndex = 0; tagIndex < pageItem.tags.length; tagIndex++){

  tags = tags + "name: " + pageItem.tags[tagIndex].name + ", value: " + pageItem.tags[tagIndex].value + "; ";

  }

  if(tags != "") log.info(indentation + "tags: " + tags);

  }

  }

  if(!(obj.nonNativeItems === undefined) && !(obj.nonNativeItems === null)){

  for (var nonNativeItemIndex = 0; nonNativeItemIndex < obj.nonNativeItems.length; nonNativeItemIndex++) {

  var nonNativeItem = obj.nonNativeItems[nonNativeItemIndex];

  log.info(indentation + "NonNativeItem: "+ nonNativeItem.name + "-------------------------------------------------------");

  log.info(indentation + "width: " + ConvertPtsToInches(nonNativeItem.width,2));

  log.info(indentation + "height: " + ConvertPtsToInches(nonNativeItem.height,2));

  log.info(indentation + "left: " + ConvertPtsToInches(nonNativeItem.left,2));

  log.info(indentation + "top: " + ConvertPtsToInches(nonNativeItem.top,2));

  log.info(indentation + "position: " + ConvertPtsToInches(nonNativeItem.position[0],2)+","+ConvertPtsToInches(nonNativeItem.position[1],2));

  //if(!(nonNativeItem.zOrderPosition === undefined) && !(nonNativeItem.zOrderPosition === null))

  // log.info(indentation + "z-index: " + nonNativeItem.zOrderPosition);

  var tags = "";

  for(var tagIndex = 0; tagIndex < nonNativeItem.tags.length; tagIndex++){

  tags = tags + "name: " + nonNativeItem.tags[tagIndex].name + ", value: " + nonNativeItem.tags[tagIndex].value + "; ";

  }

  if(tags != "") log.info(indentation + "tags: " + tags);

  }

  }

}

var doc = app.activeDocument;

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

  var currentLayer = doc.layers[layerIndex];

  log.info("Layer: "+ currentLayer.name + "-------------------------------------------------------");

  dumpItemsFromObject(currentLayer,4);

}

alert("done");