3 Replies Latest reply on Jan 29, 2018 4:43 AM by JJMack

    Resizing an image and then closing the document will occur an error.

    명선김96293951

      Hello.

       

      My code is as like below.

       

      test.jsx

       

      ...

      sourceDoc.resizeImage(scaledW, scaledH);

      ...

      [using the sourceDoc]

      ...

      sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

      ...

       

       

      Normally, the code is work perfectly. However,  if i turn on 'Preference - > Plugin -> Generator', the code occur an error.

       

       

      I could find a log.

       

      ------------------------------------------------------------------------------------------ -----------------------------

      "C:\Users\Morgan\AppData\Roaming\Adobe\Adobe Photoshop CC 2018\Generator\logs"

       

       

      [0m[warning:core 04:02:11.487 C:\Program Files\Adobe\Adobe Photoshop CC 2018\Required\Generator-builtin\lib\generator.js:129:25] Photoshop error { id: 24, body: 'Unknown JavaScript error' }

      [1;31mUncaught exception on Mon Jan 29 2018 04:02:11 GMT+0900 (대한민국 표준시):

      Error object: "Unknown JavaScript error"

       

       

       

       

      [0m [1;31mUnknown JavaScript error

      [0m [1;31mExiting with code -1: Uncaught exception: undefined

      [0m

      ------------------------------------------------------------------------------------------ -----------------------------

       

      In conjecture, Generator will try to use the document for applying resulting of resizing on the background (thread or..).  But, no more available the document.

       

      If i do not close the document. the error is not occurred. However, i need to close the source document. Because, the source is not necessary anymore after processing.

       

      Seriously, it is driving me crazy.

       

      Dose someone know how to avoid the error or disable Generator by javascript?

        • 1. Re: Resizing an image and then closing the document will occur an error.
          JJMack Most Valuable Participant

          Seriously, ... ... ...

          No Photoshop version

          no OS version

          no actual script

          What kind of response do you think you will get.

           

          Supply pertinent information for quicker answers

          • The more information you supply about your situation, the better equipped other community members will be to answer. Consider including the following in your question:
          • Adobe product and version number
          • Operating system and version number
          • The full text of any error message(s)
          • What you were doing when the problem occurred
          • Screenshots of the problem
          • Computer hardware, such as CPU; GPU; amount of RAM; etc.
          • 2. Re: Resizing an image and then closing the document will occur an error.
            명선김96293951 Level 1

            Adobe product :

                - Photoshop  CC 2018

             

            Version Number :

                - 19.1.0

             

            Operating System :

                - Windows 10 Pro ver 10.0.16299.192

             

            The full text of any error message(s) :

                - There is a problem with Generator. Please quit Photoshop and try again. If the problem persists, remove any third-party plug-ins or try to reinstalling Photoshop

             

            What you where doing when the problem occurred :

                -  When i call a .jsx (attached below) with Generator option. Randomly, error dialog is showing with above message.

              

                 After debugging i realize it is related with 2 functionality.

             

                 1. sourceDoc.resizeImage(scaledW, scaledH);

                 2. sourceDoc.close(SaveOptions.DONOTSAVECHANGES);

             

                 It is not happened if i remove one of both.

              

                 In my guess, 'resizeImage' might call Generator and then the Generator works own job on background. (or thread.. Because it is happened randomly)

                 However, i removed the document immediately after resizing. When the Generator try to access the document for own job, the document which made the call is not exists. It might be a reason of the error.

             

                 The document is just a source image. Therefore, i need to close the document after processing.

             

                 I checked log of Generator.  There is an exception as like below.

             

                 [info:core 17:52:57.412 C:\Program Files\Adobe\Adobe Photoshop CC 2018\Required\Generator-builtin\lib\photoshop.js:488:26] 28ms to receive 2.2 kB (79.9 kB/s)
                 [warning:core 17:53:00.432 C:\Program Files\Adobe\Adobe Photoshop CC 2018\Required\Generator-builtin\lib\generator.js:129:25] Photoshop error { id: 80, body:      'Unknown JavaScript error' }
                  [1;31mUncaught exception on Mon Jan 29 2018 17:53:00 GMT+0900 (대한민국 표준시):
                 Error object: "Unknown JavaScript error"
            
            
            
            
                  [0m [1;31mUnknown JavaScript error
                  [0m [1;31mExiting with code -1: Uncaught exception: undefined
                  [0m
            

             

              

                 It is full source of the .jsx file which i called.

             

             $._ext_Merge =
                 {   
                     run : function(_centerX, _centerY, _width, _height,  _zoom, _originW, _originH)
                     {       
                         _centerX    = parseFloat(_centerX);
                         _centerY    = parseFloat(_centerY);
                         _width       = parseFloat(_width);
                         _height   = parseFloat(_height);
                         _zoom    = parseFloat(_zoom);
                         _originW = parseFloat(_originW);
                         _originH  = parseFloat(_originH);
                   
                         // 옮기기 시작         
                         var startRulerUnits = app.preferences.rulerUnits;
                         var startTypeUnits = app.preferences.typeUnits;
                         var startDisplayDialogs = app.displayDialogs; 
                         app.preferences.rulerUnits = Units.PIXELS;
                         app.preferences.typeUnits = TypeUnits.PIXELS;
                         app.displayDialogs = DialogModes.NO;
                       
                         try
                         { 
                             var sourceDoc       = this.findElement(app.documents, "source");
                             var templateDoc    = this.findElement(app.documents, "template");
                       
                             if (sourceDoc == null)
                             {
                                 app.preferences.rulerUnits = startRulerUnits;
                                 app.preferences.typeUnits = startTypeUnits;
                                 app.displayDialogs = startDisplayDialogs;          
                                 return "Source image is closed";
                             }
                   
                             if (templateDoc ==null)
                             {
                                 app.preferences.rulerUnits = startRulerUnits;
                                 app.preferences.typeUnits = startTypeUnits;
                                 app.displayDialogs = startDisplayDialogs;                  
                                 return "Template Image is closed";
                             }
                       
                             var cxGroup = this.findElement(templateDoc.layers, "cx");       
                             if (cxGroup == null)
                             {
                                 app.preferences.rulerUnits = startRulerUnits;
                                 app.preferences.typeUnits = startTypeUnits;
                                 app.displayDialogs = startDisplayDialogs;          
                                 return "There is no cx group in template image";
                             }
                   
                             // 샘플 이미지 숨기기 처리
                             var sampleLayer = this.findElement(cxGroup.layers, "cx");       
                             if (sampleLayer != null)
                             {
                                 sampleLayer.visible = false;               
                             }
                       
                             // 신규 레이어 생성
                             var layerRef = cxGroup.artLayers.add()
                             layerRef.name = "cx-img";       
                             app.activeDocument = sourceDoc;
                       
                             if (app.activeDocument.layers.length > 1)
                             {
                                 app.activeDocument.mergeVisibleLayers();
                             }
                   
                             // 박스 좌표 정보 복원 처리
                             var centerX = 0.0;
                             var centerY = 0.0;
                             if (_originW > 0.0 && _originH > 0.0)
                             {
                                 var scaleW = templateDoc.width.value / _originW;
                                 var scaleH  = templateDoc.height.value / _originH;               
                                 _centerX = _centerX * scaleW;                            
                                 _centerY = _centerY * scaleH;                               
                                 _width  = _width * scaleW;           
                                 _height = _height * scaleH;               
                             }
                   
                             // 머지를 하기위해 원본의 사이즈 조정, 박스 높이에 맞춤
                             var ratio = (_height / sourceDoc.height.value) * _zoom;
                             var scaledW = sourceDoc.width.value  * ratio;
                             var scaledH = sourceDoc.height.value  * ratio;           
                             sourceDoc.resizeImage(scaledW, scaledH);
                       
                             // 복사 처리
                             app.activeDocument.selection.selectAll();
                             app.activeDocument.selection.copy();
                   
                             // 붙여넣기
                             app.activeDocument = templateDoc;       
                             app.activeDocument.activeLayer = layerRef;
                        
                             var selRegion = Array(  Array(0,                  0),
                                                            Array(0 + scaledW,    0),
                                                            Array(0 + scaledW,    0 + scaledH),
                                                            Array(0,                  0 + scaledH),
                                                            Array(0,                  0));            
                                     
                             app.activeDocument.selection.select(selRegion);
                             app.activeDocument.paste();
                             app.activeDocument.activeLayer.translate(_centerX - (scaledW * 0.5), _centerY - (scaledH * 0.5));
                       
                             // 필요한 작업이 완료되고 더이상 원본은 필요하지 않기에  여기서 닫아준다.
                             sourceDoc.close(SaveOptions.DONOTSAVECHANGES);           
                         }
                         catch(_e)
                         {
                             // 복원
                             app.preferences.rulerUnits = startRulerUnits;
                             app.preferences.typeUnits = startTypeUnits;
                             app.displayDialogs = startDisplayDialogs;
                   
                             return _e;
                         }
                  
                         // 복원
                         app.preferences.rulerUnits = startRulerUnits;
                         app.preferences.typeUnits = startTypeUnits;
                         app.displayDialogs = startDisplayDialogs;       
                        
                         return "ok";
                     },
                     findElement : function (_container, _name)
                     {
                         var result = null;
                   
                         for (var i = 0; i < _container.length; ++i)
                         {
                             if ( _container[i].name == _name)
                             {
                                 return _container[i];
                             }
                         }
                    
                         return result;       
                     },   
                 };
            

             

            Screentshots of the problem :

             

                            a.png

                 In translate in English :

              

                 There is a problem with Generator. Please quit Photoshop and try again. If the problem persists, remove any third-party plug-ins or try to reinstalling Photoshop

             

            Computer hardware :

                 cpu : Intel i7 skylake.

                 ram : 16 gb

                 gpu : gforce 1060

            • 3. Re: Resizing an image and then closing the document will occur an error.
              JJMack Most Valuable Participant

              I hope now someone can help you.  I have never use Photoshop generator plug-in or tried to script it.  I uncheck generator in my preferences. There are thing in your script the are unknown to me like  this.findElement(cxGroup.layers, "cx")