5 Replies Latest reply: Jun 12, 2012 7:03 AM by Muppet Mark RSS

    script pulling over another file

    hilukasz Community Member

      anyone have a problem where a script will open another script file? I am thinking ES is storing a function somehow across files in a global variable and is trying to run another file to get it rolling. never had this happen really.

       

      any ideas?

        • 1. Re: script pulling over another file
          Muppet Mark Community Member

          Is the other script file one of your includes? Does it have any $.write() or $.writeln() that have not been commented out? Have you set any $.level options?

          • 2. Re: script pulling over another file
            CarlosCanto CommunityMVP

            no idea, it just happens randomly?

            • 3. Re: script pulling over another file
              hilukasz Community Member

              its not an includes file, I have a feeling it has to do with varaibles, thats why I was trying to clear the variables. Still a bit new to programming, so learning about encapsilation and all that fun stuff. I have set some $.writes they are only level $. i have. it seems to fix it if I restart, but no idea why it is happening in first place.

               

              I mean it is not totally random, always on same file. but random, as in, it has never happened before.

              • 4. Re: script pulling over another file
                hilukasz Community Member

                update: I started learning javascript legitimately and have learned (as you guys probably know) that you should contain all your variables within functions. I was thinking when you suggested wrapping my script in a function you meant all my functions so wrapping functions in function and all that mess, which seams bad practice and dirty. but now I am breaking them up into smaller funcitons and containing the variable within their scope, seems to solve the problem. I think what was happening was I was somehow storing global variables, then it was trying to acccess those variables (which were first defined in the other document) via the other document.

                 

                creating scope for all variables definitely solves the problem.

                • 5. Re: script pulling over another file
                  Muppet Mark Community Member

                  From the Illustrator scripting read me

                   

                  "An Illustrator error occurred: 1346458189 ('PARM')" alert (1459349)

                   

                    Affects: JavaScript

                   

                    Problem:

                      This alert may appear when carelessly written scripts are repeatedly

                      run in Illustrator from the ExtendScript Toolkit.

                   

                      Each script run is executed within the same persistent ExtendScript

                      engine within Illustrator. The net effect is that the state of

                      the ExtendScript engine is cumulative across all scripts that

                      ran previously.

                   

                      The following issues with script code can cause this problem:

                   

                        - Reading uninitialized variables.

                        - Global namespace conflicts, as when two globals from different

                          scripts have the same name.

                   

                    Workaround:

                      Be very careful about variable initialization and namespace conflict

                      when repeatedly pushing a batch of Illustrator scripts

                      for execution in Illustrator via the ExtendScript Toolkit (ESTK) in a

                      single Illustrator session.

                   

                      Initialize variables before using them, and consider the scope of

                      your variables carefully. For example, isolate your variables by

                      wrapping them within systematically named functions. Instead of:

                   

                        var myDoc = app.documents.add();

                        // Add code to process myDoc

                   

                      Wrap myDoc in a function that follows a systematic naming scheme:

                   

                        function myFeatureNameProcessDoc() {

                          var myDoc = app.documents.add();

                          // Add code to process myDoc

                        }

                            myFeatureNameProcessDoc();