13 Replies Latest reply on Jul 5, 2014 10:33 AM by CarlosCanto

    Batch creation of variables

    Brandelune

      A client works with CS4 on a map with about 2000 text boxes that need to be exported for translation.

       

      Is there a way to batch process the file so that all the text boxes are assigned a variable for export in XML ?

       

      Thank you in advance for the replies.

       

      Jean-Christophe Helary

        • 1. Re: Batch creation of variables
          CarlosCanto Adobe Community Professional & MVP

          check here, is that what you needed?

           

          http://forums.adobe.com/thread/873415

          • 2. Re: Batch creation of variables
            Brandelune Level 1

            I'll check today with the client. Thank you *very much* for the pointer.

             

            Honestly, I think such functions should be included in AI by default...

             

            Jean-Christophe Helary

            • 3. Re: Batch creation of variables
              Brandelune Level 1

              Carlos,

               

              Thank you very much for the pointer.

              Along with your datasets explanations at:

              http://forums.adobe.com/message/3067221#3067221

              I was able to process the whole document, test the translation, reimport the data and create an AI file with the translated strings that could open on the client's machine (CS4).

               

              Excellent !

               

              Jean-Christophe Helary

              • 4. Re: Batch creation of variables
                CarlosCanto Adobe Community Professional & MVP

                you're welcome, glad to hear that.

                • 5. Re: Batch creation of variables
                  Brandelune Level 1

                  It appears that once the script is run, it is not possible to run it again on the same file after text boxes are added.

                   

                  I run into a 9125 error: Page item is already bound to the same type of variable

                  line 16

                  -> itext.contentVariable = idocvar;

                   

                  I can't find a manual way to unbind all the variable at once so that I can restart the script and recreate a new variable library.

                   

                  Is there a way to do that ?

                   

                  Jean-Christophe Helary

                  • 6. Re: Batch creation of variables
                    CarlosCanto Adobe Community Professional & MVP

                    I'm not in front of the computer at the moment, try deleting all variables instead of unbiding

                    • 7. Re: Batch creation of variables
                      Brandelune Level 1

                      It is possible to delete variables one by one, but I can't find a way to delete them all at once: reinitialize the variable assignment state.

                       

                      The menu in the variable window only seems to work on single variables at a time.

                       

                      What I mean by "adding text boxes" is that the script does not seem to access text boxes that are grouped or on which a mask is applied. So, once I have ungrouped and unmasked all the relevant parts of the design, I need to run the script again to access all the data.

                       

                      Jean-Christophe Helary

                      • 8. Re: Batch creation of variables
                        CarlosCanto Adobe Community Professional & MVP

                        it is possible to delete the all, click on the first variable, Shift-Click on the last variable, click on the Trash Can Icon at the bottom of the variables panel.

                         

                        I modified the script, this version will complete adding variables a second time is run

                         

                        #target illustrator
                        
                        // script.name = makeActiveLayerTextDynamic.jsx;
                        // script.description = makes ALL text in the Active Layer Dynamic, creates Variables;
                        // script.required = one document with at leas one textFrame;
                        // script.parent = CarlosCanto // 04/17/14;
                        // script.elegant = false;
                        
                        var idoc = app.activeDocument;
                        var ilayer = idoc.activeLayer;
                        
                        
                        
                        
                        for (i=0; i<ilayer.textFrames.length; i++) {
                            var itext = ilayer.textFrames[i];
                            var idocvar = idoc.variables.add();
                            idocvar.kind = VariableKind.TEXTUAL;
                        
                            try {itext.contentVariable = idocvar}
                            catch (e) {idocvar.remove()}
                        }
                        
                        • 9. Re: Batch creation of variables
                          Brandelune Level 1

                          Back to my batch variable assignations...

                           

                          So, I work on CC trial right now (this new client used CC for his files) and I' facing the rolling issue:

                           

                          1) I open the file

                          2) Select all

                          3) Make Visibility Dynamic

                          → What I get here is a list of "Variable 1" variables, that are set to "Visibility" and not to Text String, even though a lot of them are text.

                          4) I run the script you provided

                          → I get a number of variables, all with unique names starting with "Variable 2", all of type "Text"

                          5) When I export the XML, the contents of the multiple instances of "Variable 1" created in 3) above are not in the XML...

                           

                          If there any way around that issue ?

                           

                          Jean-Christophe

                          • 10. Re: Batch creation of variables
                            Brandelune Level 1

                            I think I found a workaround.

                             

                            You provided 2 scripts (at least) one was applied to the selected text, the other to the selected layer.

                            When I use the selected text, I get all the instances of the strings found in the above "Variable 1" but each with their own variable.

                            Since Variable 1 is not of type text, it is not included in the XML, which is fine.

                             

                            I guess I'm fine with that.

                             

                            But I wish I understood better what is going on here... Is there a tutorial somewhere, of a technical documentation that explicits all that ?

                             

                            Jean-Christophe

                            • 11. Re: Batch creation of variables
                              CarlosCanto Adobe Community Professional & MVP

                              I made 3 scripts, use the first one I wrote, that one will deal with all text, grouped or masked...but regardless of which script you use, DO NOT click on "Make Visibility Dynamic"

                               

                              explanation,

                              1st script deals with all text in all layers

                              2nd script, the user didn't want all text processed, only what was on an artboard, I made it work with selection only.

                              3rd script, you wanted it modified to work only on a given layer, this version can't deal with grouped or masked text.

                              • 12. Re: Batch creation of variables
                                Brandelune Level 1

                                Thank you for your reply.

                                 

                                I finished the extraction last night before seing your mail.

                                 

                                What I did, as written above is:

                                1) Select all text

                                2) Make visibility dynamic

                                3) Create data set

                                4) Run the script for the selected text

                                5) Save the library

                                 

                                The library contains the dynamic visibility data under Variable 1 and all the other variables starting from Variable 2.

                                 

                                Now, I tested the proper way to do that, as you wrote above:

                                1) Select all text

                                2) Create data set

                                3) Run the script for the selected text

                                4) Save the library

                                 

                                And I end up with exactly the same variables, except that the extra "dynamic visibility data" is not there.

                                 

                                *if* importing the data I created with the first process fails, I'll have to redo the whole export, which is fine (it took me less than an hour for the whole file set), but if it works fine, I don't want to do that again.

                                 

                                Is there a reason why the import would not work ?

                                 

                                Jean-Christophe

                                • 13. Re: Batch creation of variables
                                  CarlosCanto Adobe Community Professional & MVP

                                  yes, the problem is the variable names, duplicates are not allowed. When you select items and create variables by hand, they will all have the same name (variable1). You can fix your finished xml by hand, eliminating the duplicates if that's easier.