Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Get specific information from textframes

Community Beginner ,
May 06, 2016 May 06, 2016

Hi all,

So here is my issue. I need to get some information from text located inside a big layer. The layer contains images and text, and within the text is the information that I need, that looks like this:

(4) L #'s 1,2,3,4

(13) XL #'s 5,7,8,9,10,11,12,14,15,17,19,20,21

(4) XXL #'s 22,23,25,27

(1) XXXL #'s 34

I need to get three things: the count that is the number inside the parenthesis, the size that it is the next set of letters (L, XL, XXL, XXXL) and the number list (i don't need the characters "#'s"), and that information should be storage together in order to know for example that the size L has a count of 4 and the numbers are 1,2,3 and 4.

If somebody could point me on a direction to accomplish this I would truly appreciate it. I'm working on CS6.

Thank you.

TOPICS
Scripting
2.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , May 19, 2016 May 19, 2016

this isn't EXACTLY how i described it above.. but this is the one i was testing with. it doesn't have the conditional statement to figure out whether it should use asterisks or peren's and i've just hard coded the string from the textFrame. This worked for me. Perhaps this will be more helpful than that wall of text and attempts at explanations..

function getRoster()

{

    var roster = {};

    var text = "(4) AL #'s 1,2,3,4\

    (13) AXL #'s 5,7,8,9,10,11,12,14,15,17,19,20,21\

    (4) AXXL #'s 22,23,2

...
Translate
Adobe
Valorous Hero ,
May 06, 2016 May 06, 2016

Is each individual line in your example expected to occupy just one text frame? Do you plan to work off a selection, or how do you want to determine which text box should be looked at?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2016 May 09, 2016

Hi Silly-V​

All those lines are contained in one big text frame. The only thing all the AI files have in common in that text frame is the word TOTAL (It appears always after the lines I showed in my example) so I think that could be the way to select the appropriate frame to work on.

Thank you for your interest and your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 06, 2016 May 06, 2016

Hi beymig​,

like Silly-V​ said – to little informations.

A shot into the sky:

// Textstring_findStringInDocTextframesWithRegex.jsx

// https://forums.adobe.com/thread/2150605

var msg = new Array();

var hit, reg, text;

var frames = app.activeDocument.textFrames;

for (var j = 0; j < frames.length; j++) {

    text = frames.contents;

    reg = /\(\d+\)[LX ]+#\'s [\d,]+/g;

   

    while (hit = reg.exec(text)) {

    msg.push (hit[0].replace (" #'s", ''));

    }

}

alert (msg.join ("\r"));

Have fun

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2016 May 09, 2016

Hi pixxxel schubser​

Thank you for your help!

Sorry about not providing enough information, you are totally right. In my reply to Silly-V I gave some more. I'll work around I little bit with your code, and if you have another input with the new information I just provided, please feel free to add it! I will truly appreciate it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 09, 2016 May 09, 2016

Using just your example of 4 lines in a single text frame, I was able to craft this:

#target illustrator

function test(){

  function quickView(msg, title){

    if(title == undefined){

      title = '';

    }

    var w = new Window('dialog', title);

    var e = w.add('edittext', undefined, msg, {multiline:true, readonly:true});

    e.size = [700,500];

    var okbtn = w.add('button', undefined, 'Ok');

    w.show();

  };

  var doc = app.activeDocument;

  var t = doc.selection[0];

  var text = t.contents;

  var textArray = text.split(/[\r\n]/g);

  var  processedItems = [], thisObj, thisLine;

  for(var i=0; i<textArray.length; i++){

    thisLine = textArray;

    thisObj = {

      size : thisLine.match(/\s[A-Z]+\s/)[0].replace(/\s/g, ''),

      count : parseInt( thisLine.match(/\(.+\)/g)[0].replace(/(^\(|\)$)/g, '') ),

      numbers : thisLine.match(/\s\d+,?.+/)[0].replace(/\s/g, "").split(",")

    };

    processedItems.push(thisObj);

  };

  var testMessage = processedItems.toSource().replace(/}\), \({/g, "}),\n({");

  quickView(testMessage);

};

test();

It's not perfect and any deviation from your example format will throw it off. If you have some other words in that text box, please provide a really diverse case which encompasses some of the complexity you're expecting.

For this test though, make 1 text frame and paste your 4 lines in and make sure the text frame is selected (not the text inside) to get your result.

2016-05-09 17_27_11-Untitled-1_ @ 200% (RGB_Preview).png2016-05-09 17_27_23-Untitled-1_ @ 200% (RGB_Preview).png

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 10, 2016 May 10, 2016

Thank you so much Silly-V!.

I try it out and it works perfectly with the example I gave.

Now I would be working mainly with three scenarios. The first one is when I have just count and sizes only and it looks like this:

(2) AM 

(5) AL

(4) AXL

(1) AXXL

TOTAL: 12

The second one is the one I showed on the example that it has count, sizes and numbers. But it also has that TOTAL at the bottom:

(4) AL #'s 1,2,3,4

(13) AXL #'s 5,7,8,9,10,11,12,14,15,17,19,20,21

(4) AXXL #'s 22,23,25,27

(1) AXXXL #'s 34

TOTAL: 22

And the third one is with count, sizes, numbers and names:

*6* YL #’s 20,88,11,22,34 NAMES: WOLF,BLOXDORF,BEINLICH,JOCIUS,DOOLITLE

*5* YXL #’s 24,27,4,8,49 NAMES: BARRERA,LICHT,DESSART,JAMISON,LOCH

TOTAL:11

And instead of (), the count number is surrounded by **.

That´s pretty much all the diversity and complexity I would get.  Thanks again for your time and HUGE help.

Cheers!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 10, 2016 May 10, 2016

So what are you gonna use this all for? It's all looking pretty important

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 10, 2016 May 10, 2016

Actually looks exactly like what I"M trying to accomplish for my own stuff here at work.

beymig​, are you setting up some kind of full dye sublimation by any chance? Or if not full dye, you're definitely doing uniforms of some sort, yes?

Is it possible for you to provide a sample file that includes the most complex scenario so we can make sure we're covering all the bases? (i understand there could be intellectual property concerns, if so it doesn't have to include any specific data related to the job. Just a file that's formatted how you expect to receive these files.

Will there be multiple textframes in the file? Or is there only 1 text frame? If there is more than 1 text frame, is it currently (or could it be) placed on a unique layer (i.e. a layer called "Roster Info")?

Do you have any control over the formatting of the textframes? Ideally, if you could format the data into a consistent CSV format, this whole process is relatively easy.

I'd love to help you solve this issue, because it could give me insight into a project i've been avoiding for some time.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 12, 2016 May 12, 2016

Hi williamadowling​!

Sorry about the delay in my reply.

Do you have a magic ball? Because that's exactly what I'm working on hahaha. I can provide some sample files but is there a way a can send them here? I only see an option for images, not for AI files.

There are in fact multiple text frames in the files, and the information I need is all in one text frame containing the info I shared previously. Sadly I don't have control over the formatting of the text frames, I know that will be way easier.

Thank you so much for your interest and help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 12, 2016 May 12, 2016

I want to use my psychic powers and not only guess that it's dye-sub uniforms, but specifically football team kits in the UK area.

How did I do??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 13, 2016 May 13, 2016

LOL! Well is not just football, other sports as well

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 13, 2016 May 13, 2016

I'll give it a shot...football, cricket, rugby

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 13, 2016 May 13, 2016

Hahaha! I'm on the other side of the world so no cricket or rugby

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 13, 2016 May 13, 2016

Football, baseball, softball, soccer, lacrosse and basketball?

(FYI, we're going to help you, not just speculate on what your job is..

I've just been crazy busy the last few days... Basement flooded in a

storm.. Ugh.)

You can upload an AI file to Dropbox or Google drive and post the link.

That's the easiest way to share content. Then when we can look at the file

we can give a more comprehensive solution.

Do you have any code that you've written so far or are you looking for the

code written from scratch?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2016 May 16, 2016

Well williamadowling​​ you definitively have the best psychic powers lol.

And oh, I'm truly sorry about your basement, that sounds awful.

Here is the link for the files:

AIFiles

I put there the three different scenarios that the script would encounter:

- Count and Sizes

- Count, Sizes and Numbers

- Count, Sizes, Numbers and Names

This is only part of a bigger script that should open all the AI files from an specific folder and get the count, sizes, numbers, names and perform a bunch of some other stuff. I have the beginning and the rest of it figured it out, but this piece I'm starting to do it from scratch.

Thanks so much for the help! To all of you guys

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
May 16, 2016 May 16, 2016

I'd want to know, what or who puts those information lines into those text boxes to begin with?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2016 May 16, 2016

Hi @Silly-V

The Company's Artists do that. It is a standard procedure that they are not willing to change. I know for scripting it would be much simpler to do it differently, but that's how it is .

Thank you again for your interest and help

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 16, 2016 May 16, 2016

I'm starting to wonder if you work where I do and I'm being replaced! =P

Ok, give me a little bit of time and I'll look over the sample files and see what we can do.

I'm also curious about Silly's question. How are these text frames generated?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 16, 2016 May 16, 2016

Oh no williamadowling​ don't you worry, I'm flying solo here lol.

I just answered Silly-V's question.

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 19, 2016 May 19, 2016

Update.. i haven't forgotten about you, @beymig

It's just that what you're doing is way too close to what I do, so I have to be sure to do it at home. And since my home is such a mess currently, i'm not getting to it as quickly as I'd like.

One question i did have is, are you looking for the script to automatically find the correct textFrame to pull the info from? or is it acceptable to select the correct textFrame and then pull the information from the selection?

I ask because i noticed that there seems to be 2 different textFrames in each document.. one that contains onlly quantity and one that contains quantity and player data. That makes it a little trickier to determine which is the correct one, though not impossible by any stretch.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 19, 2016 May 19, 2016

Hi williamadowling​

Thank you for not forgetting me! Don't worry take your time .

Answering your question, yes I need the script to find and select the correct frame. The only thing they all have in common in the word TOTAL. So I think that may help.

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 19, 2016 May 19, 2016

indeed.. Total was the word that i was using to find the frame.. and i was surprised when my array of text frames had a length of 2.. that's when i noticed the other text frame hiding in there. Shouldn't be an issue.

Honestly i think the annoying part is that sometimes the quantity is inside (parentheses) and other times it's inside *asterisks*. Again, not a fatal issue, but an annoyance to be sure.

So I'm not sure what you have written yet, if anything. But maybe it'll help to just spell out the process i'm envisioning, perhaps you'll be able to tease out the details on your own and be better for it. (not to mention then you wouldn't have to wait on me )

before anything, define a script/function global object you can use to store the roster info you collect.

var roster = {};

1) To find the textFrame, i simply looped the app.activeDocument's textFrames and checked for an instance of "Total:" and push true results to an array. (bonus points if the desired textFrames are always on a consistent/predictable layer.. i haven't looked closely enough to see whether that was the case on your samples).

2) then compare the 2 text frames to determine which one is correct. It looks like the only time there will be 2 is when names are involved. otherwise, there seems to only be 1 textFrame that contains the string "Total:". Save the correct textFrame to a variable.

3) next you want to split the textFrame by '\n' so that you get an array of lines. at that point, you can loop the array/lines and pull out the data for each size.

per your first example of the textFrame formatting earlier in this thread, we'll assume that thus far we've done this:

var text = "(4) AL #'s 1,2,3,4\

  (13) AXL #'s 5,7,8,9,10,11,12,14,15,17,19,20,21\

  (4) AXXL #'s 22,23,25,27\

  (1) AXXXL #'s 34\

  \

  TOTAL: 22"

var lines = text.split('\n');

at this point lines[0] is equal to the string: "(4) AL #'s 1,2,3,4"

4) pull the quantity and size from the current line with substring and indexOf (someone may have a much better solution, but this is what i know and what works for me.) like so:

var thisQuantity = lines[0].substring(0,lines[0].indexOf(" "); //result: "(4)"

alternatively, you could write some logic to figure out whether the quantity is enclosed in ( ) or * * and remove those from the get go so you can push the quantity only to the desired location.

if (lines[0].indexOf("*") > -1)

{

    thisQuantity = lines[0].substring(lines[0].indexOf("*"),lines[0].indexOf("* ")

    thisSize = lines[0].substring(lines[0].indexOf("* "), lines[0].indexOf("#");

}

else

{

    thisQuantity = lines[0].substring(lines[0].indexOf("("),lines[0].indexOf(")");

    thisSize = lines[0].substring(lines[0].indexOf(") "), lines[0].indexOf("#");

}

5) next determine the beginning of the numbers

var numberSet = lines[0].substring(lines[0].indexOf("#'s "), lines[0].length-1);

numberSet = numberSet.split(","); // result = ["1","2","3","4"]

6) push the data into your "roster" object.

roster["sizes"] = {};

roster["sizes"][thisSize] = {};

roster["sizes"][thisSize]["quantity"] = thisQuantity;

roster["sizes"][thisSize]["numbers"] = numberSet;

7) last thing to do is presumably return the value of "roster" (assuming you're running this from a specific "get roster info" function) and save the returned value to a variable.

Hopefully this made some sense.. Let me know if i went astray anywhere or if there's anything that is unclear or simply outlandish.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
May 19, 2016 May 19, 2016

this isn't EXACTLY how i described it above.. but this is the one i was testing with. it doesn't have the conditional statement to figure out whether it should use asterisks or peren's and i've just hard coded the string from the textFrame. This worked for me. Perhaps this will be more helpful than that wall of text and attempts at explanations..

function getRoster()

{

    var roster = {};

    var text = "(4) AL #'s 1,2,3,4\

    (13) AXL #'s 5,7,8,9,10,11,12,14,15,17,19,20,21\

    (4) AXXL #'s 22,23,25,27\

    (1) AXXXL #'s 34\

     \

    TOTAL: 22"

    var lines = text.split('\n');

    roster["sizes"] = {};

    for(var a=0;a<lines.length;a++)

    {

        if(lines.length>5 && lines.indexOf(":") == -1)

        {

            var qty = lines.substring(lines.indexOf("(")+1, lines.indexOf(") "));

            var size = lines.substring(lines.indexOf(") ")+2, lines.indexOf(" #"));

            var nums = lines.substring(lines.indexOf("s ") + 2, lines.length);

            nums = nums.split(",");

            roster["sizes"][size] = {};

            roster["sizes"][size]["quantity"] = qty;

            roster["sizes"][size]["numbers"] = nums;

        }

    }

    return roster;

}

var theRoster = getRoster();

this script returns the following object and saves it as theRoster:

var theRoster = {

     "sizes" : {

          "AL" : {

               "numbers": ["1", "2", "3", "4"],

               "quantity" : 4

          },

          "AXL" : {

               "numbers":["5","7","8","9","10","11","12","14","15","17","19","20","21"],

               "quantity" : 13

          },

          "AXXL" : {

               "numbers": ["22","23","25","27"],

               "quantity" : 4

          },

          "AXXXL" : {

              "numbers" : ["34"],

               "quantity" : 1

          }

     }

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2016 Aug 17, 2016
LATEST

Hi williamadowling​! It's been a while. I have been working in some others projects but today I finally finished this one. Your help was the more helpful so here I am making it as the correct answer.

Thanks a lot for all your help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines