12 Replies Latest reply on Nov 19, 2015 4:03 AM by anony17014062

    How to use CEPEngine_extensions.js ?

    mushmut Level 1

      Hi ,

       

      I currently write an extension (seriously  ?), and i need to create folder and file after some process.

      I try to use the CEPEngine_extensions.js but the debuger say

      Uncaught SyntaxError: Unexpected identifier 
      
      

       

      So i can't use the CEPEngine.

       

      There another libs needed with the CEPEngine_extensions.js ?

      Or there is a doc that explain how to use it properly?

       

      Thank you !

        • 1. Re: How to use CEPEngine_extensions.js ?
          Hallgrimur Bjornsson Level 3

          Hi,

           

          What product are you developing for (and version)?

           

          Best regards,

          Hallgrimur

          • 2. Re: How to use CEPEngine_extensions.js ?
            jun xia Adobe Employee

            Hi,

             

            CEPEngine_extensions.js is actually a CEF extension that is built in CEPHtmlEngine to expand the DOM of CEPHtmlEngine, like create/delete folder, read/write file, create/quit process, and so on. You can invoke these built-in APIs directly in your Html extension without any Javascript file reference.

             

            For example, you want to

             

            1) create a folder.

             

            var path = "/tmp/test";
            var result = window.cep.fs.makedir(path);
            if (0 == result.err) {
                 ...// success
            }
            else {
                 ...// fail
            }
            

             

            2) write a file.

             

            var data = "This is a test.";
            var path = "/tmp/test";
            var result = window.cep.fs.writeFile(path, data);
            if (0 == result.err) {
                 ...// success
            }
            else {
                 ...// fail
            }
            

             

            3) write utf8 data to file as base64 encoding.

             

            var data = "This is a test.";
            var path = "/tmp/test";
            data = cep.encoding.convertion.utf8_to_b64(data);
            
            var result = window.cep.fs.writeFile(fileName, data, cep.encoding.Base64);
            if (0 == result.err) {
                 ...// success
            }
            else {
                 ...// fail
            }
            

             

            4) read a file.

             

            var path = "/tmp/test";
            var result = window.cep.fs.readFile(path);
            if (0 == result.err) {
                  //success
                 alert(result.data); //result.data is file content
            }
            else {
                 ...// fail
            }
            

             

            5) read base64 encoding file as utf8 string.

             

            var path = "/tmp/test";
            result = window.cep.fs.readFile(path, cep.encoding.Base64);
            if (0 == result.err) {
                 //success
                 var base64Data = result.data;
                 var data = cep.encoding.convertion.b64_to_utf8(base64Data);
            }
            else {
                 ...// fail
            }
            

             

            6) Create a process and check if it's running.

             

            var result = window.cep.process.createProcess("usr/X11/bin/xterm");
                    if (0 == result.err) {
                        var pid = result.data;
                        result = window.cep.process.isRunning(pid);
                        if (true == result.data) {
                           // running                  
                        }
                    }
            
            

             

            You could use other APIs like delete folder, rename folder, set file permission, delete file, show file open dialog, quit process, etc.

             

            To answer your questions,

             

            Is there another libs needed with the CEPEngine_extensions.js?

            No, it has been built in CEPHtmlEngine. You could invoke these built-in APIs directly in your Html extension.

             

            Is there a doc that explain how to use it properly?

            I think extension builder might have provided a HTML version doc for these APIs, but it's actually comming from the comments of each API. So there is not much difference to see the comment of each API. So I suggest you to read the comment in CEPHtmlEngine_extensions.js.

             

            Hope this help and kindly let me know if you need more information.

             

            Regards,

            Jun

            1 person found this helpful
            • 3. Re: How to use CEPEngine_extensions.js ?
              mushmut Level 1

              Hi ,

               

              Thank for your answers,

               

              @Hallgrimur Bjornsson

               

              I'm currently target the Illustrator CC 17.1version.

               


              @jun xia
              thank you to provide that seem's like doc on the fly this is awesome !

               

              Thank !

              • 4. Re: How to use CEPEngine_extensions.js ?
                mushmut Level 1

                Any clue on this error with Illustrator CC 17.1 ?

                 

                Thank

                • 5. Re: How to use CEPEngine_extensions.js ?
                  jun xia Adobe Employee

                  Hi mushmut,

                   

                  Are you still ecnountering this syntax error in Illustrator 17.1? If possible, please send me your sample extension, I will take a further look at it. Thanks.

                   

                  Jun

                  • 6. Re: How to use CEPEngine_extensions.js ?
                    mushmut Level 1

                    Hi jun,

                     

                    Thank for you interest in my issue.

                    You can finc the zip of my extension here.
                    https://www.dropbox.com/s/jzj63aioytbvfbc/com.example.superstrame.zip

                    I also noticed the JSON object didn't work in JSX file.

                    • 7. Re: How to use CEPEngine_extensions.js ?
                      jun xia Adobe Employee

                      Hi Mushmut,

                       

                      Thanks.

                       

                      1) Error while using CEPEngine_extensions.js.

                      I checked you extension and found the cause is CEPEngine_extensions.js is referenced in index.html directly. Actually all functions of the js file have been built in Javacript engine, and it is not supposed to be referenced in script tag in any html/js staff.

                       

                      So remove the line

                      <script src="js/libs/CEPEngine_extensions.js"></script>

                       

                      And use windows.cep.fs.xxx in your javascript file directly, say main.js. I tried to modified your extension and it can create a folder.

                       

                      var path = "/tmp/test";
                      var result = window.cep.fs.makedir(path);
                      if (0 == result.err) {
                       ...// success
                      }
                      else {
                           ...// fail
                      }
                      

                       

                      2) JSON.parse does not work in .jsx.


                      JSON.parse is defined in extension's Javascript engine but not in host application's Javascript engine. Try to use eval to achieve the same.

                       

                      Jun

                      1 person found this helpful
                      • 8. Re: How to use CEPEngine_extensions.js ?
                        jun xia Adobe Employee
                        1 person found this helpful
                        • 9. Re: How to use CEPEngine_extensions.js ?
                          mushmut Level 1

                          Thank you Jun for your quick reply.

                           

                          Now i have a better understand of the extension ecosystem.

                           

                          But i've one more (dumb) question:

                           

                          In my main JS i do  a call to one of my JSX function such as:

                           

                          csInterface.evalScript('giveMeTheproject()',function(project){console.dir(project)});
                          

                           

                          And in my JSX

                          funtction giveMeTheproject(){
                               
                               
                               var p = new Project("new Project","Superstrong","/desktop",0,true,false); 
                              return p;
                          
                          
                          }
                          

                           

                          The console.dir in the callback function show me an empty object...
                          I try to return a string and it's work...

                          Why i can't return plain object from JSX to JS  ?

                          • 10. Re: How to use CEPEngine_extensions.js ?
                            jun xia Adobe Employee

                            Yes, that's an known issue. I suggest to workaround it by returning string in JSON format in extend script and use JSON.parse to convert back to object in Html extension.

                             

                            JSON is not available in extend script, but you could use plain javascript to achieve it, according to http://stackoverflow.com/questions/5612787/converting-an-object-to-a-string.

                            1 person found this helpful
                            • 11. Re: How to use CEPEngine_extensions.js ?
                              mushmut Level 1

                              A big Thank Jun

                               

                              I go forward in my extension development !

                              • 12. Re: How to use CEPEngine_extensions.js ?
                                anony17014062 Level 1

                                Could you post the code for deleting a folder or at least clearing it? tried the deleteFile function that didn't work , and i really don't want to go through each file and delete them one by one .