Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #target Illustrator
- // links to classes and methods file
- // @include lukaszLibrary.jsx;
- var doc = app.activeDocument,
- pageItems = doc.layers.getByName("parent").pageItems,
- CSV = new CSVFile("Sass vars"),
- inputFolder = Folder.selectDialog(),
- canvasWidthHeight = [doc.width, doc.height, "", "", "", "Window"],
- parentPattern = "[parent]", // parent = if has more than one div inside it
- allParents = getArrayOfItemsWithNameUnder(parentPattern, pageItems),
- symbolPattern = "[child]", // child but parent of symbols
- allParentsOfSymbols = getArrayOfItemsWithNameUnder(symbolPattern, pageItems),
- iCount = doc.symbolItems.length,
- dateTime = getTodaysDate(),
- dest = undefined,
- dest,
- win;
- CSV.append(["width", "height", "top", "left", "name", "parent container", "type", "color", "text size(px)", "alignment", "font name", "font style", "date/time exported"]);
- CSV.append(canvasWidthHeight);
- //for each "div" inside of the parent
- for ( var i = 0; i < allParentsOfSymbols.length; i++ ) {
- var currentContainer = allParentsOfSymbols[i],
- passedSymbolsWithInfo = [];
- // loop through all the symbols to check if it is in the div
- for(var j = 0; j < doc.symbolItems.length; j++){
- var currentSymbol = new MySymbol(j);
- if(currentSymbol.isIn(currentContainer)) {
- var currentContainerTopLeft = [Math.abs(currentContainer.top), currentContainer.left],
- symbolRelativeToParent = currentSymbol.getPosition(currentContainerTopLeft[0], currentContainerTopLeft[1]),
- currentSymbolName = makeWebsafe(currentSymbol.name);
- var symbolInfo = [currentSymbol.getWidthHeight(), symbolRelativeToParent, currentSymbolName+".png", currentContainer.name.replace(symbolPattern, ""), "image", "","","","","",getTodaysDate()+"\n"];
- //passedSymbolsWithInfo.push(symbolInfo+"\n");
- CSV.append(symbolInfo);
- //print(symbolInfo);
- }
- }
- }
- //export text position and attributes
- function getAllTextItems(){
- var doc = app.activeDocument;
- for(var j = 0; j < doc.textFrames.length; j++){
- var currentTextItem = doc.textFrames[j];
- // loop through all the symbols to check if it is in the div
- for(var i = 0; i < allParentsOfSymbols.length; i++){
- var container = allParentsOfSymbols[i],
- containerVB = container.visibleBounds,
- containerLeft = containerVB[0],
- containerTop = containerVB[1],
- containerRight = containerVB[2],
- containerBottom = containerVB[3];
- //print("should apprend: "+["null","null",bottom, left,contents, container.name, "text", color , fontSize, alignment,font, style, getTodaysDate()+"\n"]);
- print(">>>> "+currentTextItem.contents+" "+container);
- if(textIsIn(currentTextItem, container)) {
- print("!!! "+currentTextItem+"passed with parent: "+container);
- var left = Math.abs(Math.round(currentTextItem.anchor[0])),
- left = left - containerLeft,
- bottom = Math.round(Math.round(currentTextItem.anchor[1])),
- bottom = bottom - containerBottom,
- font = currentTextItem.textRange.characterAttributes.textFont.name,
- style = currentTextItem.textRange.characterAttributes.textFont,
- alignment = currentTextItem.paragraphs[0].paragraphAttributes.justification,
- fontSize = alignment = currentTextItem.textRange.characterAttributes.size,
- contents = currentTextItem.contents,
- 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;
- //print("child bottom: "+bottom+", left: "+left);
- // only write file on last itteration
- CSV.append(["null","null",bottom, left,contents, container.name, "text", color , fontSize, alignment,font, style, getTodaysDate()+"\n"]);
- }
- print("========end loop=======");
- }
- }
- }getAllTextItems();
- //exportSymbolasPNG();
- var doc = null,
- pageItems = null,
- CSV = null,
- inputFolder = null,
- canvasWidthHeight = null,
- parentPattern = null, // parent = if has more than one div inside it
- allParents = null,
- symbolPattern = null, // child but parent of symbols
- allParentsOfSymbols = null,
- iCount = null,
- dateTime = null,
- dest = null,
- win = null;
Add Comment
Please, Sign In to add comment