Guest User

Untitled

a guest
Oct 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. #target Illustrator
  2.  
  3. // links to classes and methods file
  4. // @include lukaszLibrary.jsx;
  5.  
  6. var doc = app.activeDocument,
  7. pageItems = doc.layers.getByName("parent").pageItems,
  8. CSV = new CSVFile("Sass vars"),
  9. inputFolder = Folder.selectDialog(),
  10. canvasWidthHeight = [doc.width, doc.height, "", "", "", "Window"],
  11. parentPattern = "[parent]", // parent = if has more than one div inside it
  12. allParents = getArrayOfItemsWithNameUnder(parentPattern, pageItems),
  13. symbolPattern = "[child]", // child but parent of symbols
  14. allParentsOfSymbols = getArrayOfItemsWithNameUnder(symbolPattern, pageItems),
  15. iCount = doc.symbolItems.length,
  16. dateTime = getTodaysDate(),
  17. dest = undefined,
  18. dest,
  19. win;
  20.  
  21. CSV.append(["width", "height", "top", "left", "name", "parent container", "type", "color", "text size(px)", "alignment", "font name", "font style", "date/time exported"]);
  22. CSV.append(canvasWidthHeight);
  23.  
  24.  
  25. //for each "div" inside of the parent
  26. for ( var i = 0; i < allParentsOfSymbols.length; i++ ) {
  27. var currentContainer = allParentsOfSymbols[i],
  28. passedSymbolsWithInfo = [];
  29.  
  30. // loop through all the symbols to check if it is in the div
  31. for(var j = 0; j < doc.symbolItems.length; j++){
  32. var currentSymbol = new MySymbol(j);
  33. if(currentSymbol.isIn(currentContainer)) {
  34. var currentContainerTopLeft = [Math.abs(currentContainer.top), currentContainer.left],
  35. symbolRelativeToParent = currentSymbol.getPosition(currentContainerTopLeft[0], currentContainerTopLeft[1]),
  36. currentSymbolName = makeWebsafe(currentSymbol.name);
  37. var symbolInfo = [currentSymbol.getWidthHeight(), symbolRelativeToParent, currentSymbolName+".png", currentContainer.name.replace(symbolPattern, ""), "image", "","","","","",getTodaysDate()+"\n"];
  38. //passedSymbolsWithInfo.push(symbolInfo+"\n");
  39. CSV.append(symbolInfo);
  40. //print(symbolInfo);
  41. }
  42. }
  43.  
  44. }
  45.  
  46.  
  47. //export text position and attributes
  48.  
  49. function getAllTextItems(){
  50. var doc = app.activeDocument;
  51. for(var j = 0; j < doc.textFrames.length; j++){
  52. var currentTextItem = doc.textFrames[j];
  53.  
  54. // loop through all the symbols to check if it is in the div
  55. for(var i = 0; i < allParentsOfSymbols.length; i++){
  56. var container = allParentsOfSymbols[i],
  57. containerVB = container.visibleBounds,
  58. containerLeft = containerVB[0],
  59. containerTop = containerVB[1],
  60. containerRight = containerVB[2],
  61. containerBottom = containerVB[3];
  62. //print("should apprend: "+["null","null",bottom, left,contents, container.name, "text", color , fontSize, alignment,font, style, getTodaysDate()+"\n"]);
  63. print(">>>> "+currentTextItem.contents+" "+container);
  64. if(textIsIn(currentTextItem, container)) {
  65. print("!!! "+currentTextItem+"passed with parent: "+container);
  66. var left = Math.abs(Math.round(currentTextItem.anchor[0])),
  67. left = left - containerLeft,
  68. bottom = Math.round(Math.round(currentTextItem.anchor[1])),
  69. bottom = bottom - containerBottom,
  70. font = currentTextItem.textRange.characterAttributes.textFont.name,
  71. style = currentTextItem.textRange.characterAttributes.textFont,
  72. alignment = currentTextItem.paragraphs[0].paragraphAttributes.justification,
  73. fontSize = alignment = currentTextItem.textRange.characterAttributes.size,
  74. contents = currentTextItem.contents,
  75. color = app.activeDocument.textFrames[0].textRange.characterAttributes.fillColor.red+" "+app.activeDocument.textFrames[0].textRange.characterAttributes.fillColor.green+" "+app.activeDocument.textFrames[0].textRange.characterAttributes.fillColor.blue;
  76. //print("child bottom: "+bottom+", left: "+left);
  77. // only write file on last itteration
  78. CSV.append(["null","null",bottom, left,contents, container.name, "text", color , fontSize, alignment,font, style, getTodaysDate()+"\n"]);
  79. }
  80. print("========end loop=======");
  81. }
  82. }
  83. }getAllTextItems();
  84.  
  85. //exportSymbolasPNG();
  86.  
  87. var doc = null,
  88. pageItems = null,
  89. CSV = null,
  90. inputFolder = null,
  91. canvasWidthHeight = null,
  92. parentPattern = null, // parent = if has more than one div inside it
  93. allParents = null,
  94. symbolPattern = null, // child but parent of symbols
  95. allParentsOfSymbols = null,
  96. iCount = null,
  97. dateTime = null,
  98. dest = null,
  99. win = null;
Add Comment
Please, Sign In to add comment