@@ -65,14 +65,14 @@ function getLayerTypeWithName(layerName) {
6565
6666function getLayers ( ) {
6767 /**
68- * Get json representation of list of layers.
68+ * Get json representation of list of layers.
6969 * Much faster this way than in DOM traversal (2s vs 45s on same file)
70- *
70+ *
7171 * Format of single layer info:
7272 * id : number
7373 * name: string
7474 * group: boolean - true if layer is a group
75- * parents:array - list of ids of parent groups, useful for selection
75+ * parents:array - list of ids of parent groups, useful for selection
7676 * all children layers from parent layerSet (eg. group)
7777 * type: string - type of layer guessed from its name
7878 * visible:boolean - true if visible
@@ -81,14 +81,14 @@ function getLayers() {
8181 return '[]' ;
8282 }
8383 var ref1 = new ActionReference ( ) ;
84- ref1 . putEnumerated ( charIDToTypeID ( 'Dcmn' ) , charIDToTypeID ( 'Ordn' ) ,
84+ ref1 . putEnumerated ( charIDToTypeID ( 'Dcmn' ) , charIDToTypeID ( 'Ordn' ) ,
8585 charIDToTypeID ( 'Trgt' ) ) ;
8686 var count = executeActionGet ( ref1 ) . getInteger ( charIDToTypeID ( 'NmbL' ) ) ;
8787
8888 // get all layer names
8989 var layers = [ ] ;
9090 var layer = { } ;
91-
91+
9292 var parents = [ ] ;
9393 for ( var i = count ; i >= 1 ; i -- ) {
9494 var layer = { } ;
@@ -98,8 +98,8 @@ function getLayers() {
9898 var desc = executeActionGet ( ref2 ) ; // Access layer index #i
9999 var layerSection = typeIDToStringID ( desc . getEnumerationValue (
100100 stringIDToTypeID ( 'layerSection' ) ) ) ;
101-
102- layer . id = desc . getInteger ( stringIDToTypeID ( "layerID" ) ) ;
101+
102+ layer . id = desc . getInteger ( stringIDToTypeID ( "layerID" ) ) ;
103103 layer . name = desc . getString ( stringIDToTypeID ( "name" ) ) ;
104104 layer . color_code = typeIDToStringID ( desc . getEnumerationValue ( stringIDToTypeID ( 'color' ) ) ) ;
105105 layer . group = false ;
@@ -108,16 +108,16 @@ function getLayers() {
108108 layer . visible = desc . getBoolean ( stringIDToTypeID ( "visible" ) ) ;
109109 var blendMode = desc . getEnumerationValue ( stringIDToTypeID ( "mode" ) ) ;
110110 layer . blend_mode = typeIDToStringID ( blendMode ) ;
111- //log(" name: " + layer.name + " groupId " + layer.groupId +
111+ //log(" name: " + layer.name + " groupId " + layer.groupId +
112112 //" group " + layer.group);
113113 if ( layerSection == 'layerSectionStart' ) { // Group start and end
114- parents . push ( layer . id ) ;
115- layer . group = true ;
114+ parents . push ( layer . id ) ;
115+ layer . group = true ;
116116 }
117117 if ( layerSection == 'layerSectionEnd' ) {
118118 parents . pop ( ) ;
119119 continue ;
120- }
120+ }
121121 layers . push ( JSON . stringify ( layer ) ) ;
122122 }
123123 try {
@@ -145,10 +145,10 @@ function setVisible(layer_id, visibility){
145145 var ref = new ActionReference ( ) ;
146146 ref . putIdentifier ( stringIDToTypeID ( "layer" ) , layer_id ) ;
147147 desc . putReference ( stringIDToTypeID ( "null" ) , ref ) ;
148-
149- executeAction ( visibility ?stringIDToTypeID ( "show" ) :stringIDToTypeID ( "hide" ) ,
148+
149+ executeAction ( visibility ?stringIDToTypeID ( "show" ) :stringIDToTypeID ( "hide" ) ,
150150 desc , DialogModes . NO ) ;
151-
151+
152152}
153153
154154function setLayersVisibility ( visibilityMap ) {
@@ -166,14 +166,14 @@ function setLayersVisibility(visibilityMap) {
166166
167167function getHeadline ( ) {
168168 /**
169- * Returns headline of current document with metadata
170- *
169+ * Returns headline of current document with metadata
170+ *
171171 **/
172172 if ( documents . length == 0 ) {
173173 return '' ;
174174 }
175175 var headline = app . activeDocument . info . headline ;
176-
176+
177177 return headline ;
178178}
179179
@@ -182,7 +182,7 @@ function isSaved(){
182182}
183183
184184function save ( ) {
185- /** Saves active document **/
185+ /** Saves active document **/
186186 return app . activeDocument . save ( ) ;
187187}
188188
@@ -304,13 +304,13 @@ function getLayerBlendMode(layer_id) {
304304
305305function saveAs ( output_path , ext , as_copy ) {
306306 /** Exports scene to various formats
307- *
308- * Currently implemented: 'jpg', 'png', 'psd'
309- *
307+ *
308+ * Currently implemented: 'jpg', 'png', 'psd', 'tga', 'exr', 'psb', and 'tif'.
309+ *
310310 * output_path - escaped file path on local system
311311 * ext - extension for export
312312 * as_copy - create copy, do not overwrite
313- *
313+ *
314314 * */
315315 var saveName = output_path ;
316316 var saveOptions ;
@@ -373,7 +373,12 @@ function saveAs(output_path, ext, as_copy){
373373 if ( ext === 'psb' ) {
374374 return savePSB ( output_path ) ;
375375 }
376-
376+ // For TIF/TIFF, ensure saveOptions is properly initialized
377+ if ( ext === 'tif' || ext === 'tiff' ) {
378+ saveOptions = new TiffSaveOptions ( ) ;
379+ saveOptions . alphaChannels = true ;
380+ saveOptions . imageCompression = TIFFEncoding . TIFFLZW ;
381+ }
377382 return doc . saveAs ( new File ( saveName ) , saveOptions , as_copy ) ;
378383 }
379384 finally {
@@ -465,7 +470,7 @@ function imprint(payload){
465470 * Sets headline content of current document with metadata. Stores
466471 * information about assets created through AYON.
467472 * Content accessible in PS through File > File Info
468- *
473+ *
469474 **/
470475 app . activeDocument . info . headline = payload ;
471476}
@@ -484,7 +489,7 @@ function getSelectedLayers(doc) {
484489
485490 var selLayers = [ ] ;
486491 _grp = groupSelectedLayers ( doc ) ;
487-
492+
488493 var group = doc . activeLayer ;
489494 var layers = group . layers ;
490495
@@ -501,7 +506,7 @@ function getSelectedLayers(doc) {
501506 layer . name = layers [ i ] . name ;
502507 long_names = _get_parents_names ( group . parent , layers [ i ] . name ) ;
503508 var t = layers [ i ] . kind ;
504- if ( ( typeof t !== 'undefined' ) &&
509+ if ( ( typeof t !== 'undefined' ) &&
505510 ( layers [ i ] . kind . toString ( ) == 'LayerKind.NORMAL' ) ) {
506511 layer . group = false ;
507512 } else {
@@ -511,9 +516,9 @@ function getSelectedLayers(doc) {
511516
512517 selLayers . push ( layer ) ;
513518 }
514-
519+
515520 _undo ( ) ;
516-
521+
517522 return JSON . stringify ( selLayers ) ;
518523} ;
519524
@@ -527,7 +532,7 @@ function selectLayers(selectedLayers){
527532 var desc12 = new ActionDescriptor ( ) ;
528533 var id55 = charIDToTypeID ( "null" ) ;
529534 var ref9 = new ActionReference ( ) ;
530-
535+
531536 var existing_layers = JSON . parse ( getLayers ( ) ) ;
532537 var existing_ids = [ ] ;
533538 for ( var y = 0 ; y < existing_layers . length ; y ++ ) {
@@ -539,7 +544,7 @@ function selectLayers(selectedLayers){
539544 if ( existing_ids . toString ( ) . indexOf ( id ) >= 0 ) {
540545 layers [ i ] = charIDToTypeID ( "Lyr " ) ;
541546 ref9 . putIdentifier ( layers [ i ] , id ) ;
542- }
547+ }
543548 }
544549 desc12 . putReference ( id55 , ref9 ) ;
545550 var id58 = charIDToTypeID ( "MkVs" ) ;
@@ -551,38 +556,38 @@ function groupSelectedLayers(doc, name) {
551556 /**
552557 * Groups selected layers into new group.
553558 * Returns json representation of Layer for server to consume
554- *
559+ *
555560 * Args:
556561 * doc(activeDocument)
557562 * name (str): new name of created group
558563 **/
559564 if ( doc == null ) {
560565 doc = app . activeDocument ;
561566 }
562-
567+
563568 var desc = new ActionDescriptor ( ) ;
564569 var ref = new ActionReference ( ) ;
565570 ref . putClass ( stringIDToTypeID ( 'layerSection' ) ) ;
566571 desc . putReference ( charIDToTypeID ( 'null' ) , ref ) ;
567572 var lref = new ActionReference ( ) ;
568- lref . putEnumerated ( charIDToTypeID ( 'Lyr ' ) , charIDToTypeID ( 'Ordn' ) ,
573+ lref . putEnumerated ( charIDToTypeID ( 'Lyr ' ) , charIDToTypeID ( 'Ordn' ) ,
569574 charIDToTypeID ( 'Trgt' ) ) ;
570575 desc . putReference ( charIDToTypeID ( 'From' ) , lref ) ;
571576 executeAction ( charIDToTypeID ( 'Mk ' ) , desc , DialogModes . NO ) ;
572-
577+
573578 var group = doc . activeLayer ;
574579 if ( name ) {
575580 // Add special character to highlight group that will be published
576581 group . name = name ;
577- }
582+ }
578583 var layer = { } ;
579584 layer . id = group . id ;
580585 layer . name = name ; // keep name clean
581- layer . group = true ;
586+ layer . group = true ;
582587
583588 layer . long_name = _get_parents_names ( group , name ) ;
584589
585- return JSON . stringify ( layer ) ;
590+ return JSON . stringify ( layer ) ;
586591} ;
587592
588593/**
@@ -648,26 +653,26 @@ function mergeAllLayerSets(parentSetId) {
648653function importSmartObject ( path , name , link ) {
649654 /**
650655 * Creates new layer with an image from 'path'
651- *
656+ *
652657 * path: absolute path to loaded file
653658 * name: sets name of newly created laye
654- *
659+ *
655660 **/
656661 var desc1 = new ActionDescriptor ( ) ;
657662 desc1 . putPath ( app . charIDToTypeID ( "null" ) , new File ( path ) ) ;
658663 link = link || false ;
659664 if ( link ) {
660- desc1 . putBoolean ( app . charIDToTypeID ( 'Lnkd' ) , true ) ;
665+ desc1 . putBoolean ( app . charIDToTypeID ( 'Lnkd' ) , true ) ;
661666 }
662667
663- desc1 . putEnumerated ( app . charIDToTypeID ( "FTcs" ) , app . charIDToTypeID ( "QCSt" ) ,
664- app . charIDToTypeID ( "Qcsa" ) ) ;
668+ desc1 . putEnumerated ( app . charIDToTypeID ( "FTcs" ) , app . charIDToTypeID ( "QCSt" ) ,
669+ app . charIDToTypeID ( "Qcsa" ) ) ;
665670 var desc2 = new ActionDescriptor ( ) ;
666- desc2 . putUnitDouble ( app . charIDToTypeID ( "Hrzn" ) ,
671+ desc2 . putUnitDouble ( app . charIDToTypeID ( "Hrzn" ) ,
667672 app . charIDToTypeID ( "#Pxl" ) , 0.0 ) ;
668- desc2 . putUnitDouble ( app . charIDToTypeID ( "Vrtc" ) ,
673+ desc2 . putUnitDouble ( app . charIDToTypeID ( "Vrtc" ) ,
669674 app . charIDToTypeID ( "#Pxl" ) , 0.0 ) ;
670-
675+
671676 desc1 . putObject ( charIDToTypeID ( "Ofst" ) , charIDToTypeID ( "Ofst" ) , desc2 ) ;
672677 executeAction ( charIDToTypeID ( "Plc " ) , desc1 , DialogModes . NO ) ;
673678
@@ -678,14 +683,14 @@ function importSmartObject(path, name, link){
678683 }
679684 var layer = { }
680685 layer . id = currentActivelayer . id ;
681- layer . name = currentActivelayer . name ;
682- return JSON . stringify ( layer ) ;
686+ layer . name = currentActivelayer . name ;
687+ return JSON . stringify ( layer ) ;
683688}
684689
685690function replaceSmartObjects ( layer_id , path , name ) {
686691 /**
687692 * Updates content of 'layer' with an image from 'path'
688- *
693+ *
689694 **/
690695
691696 var desc = new ActionDescriptor ( ) ;
@@ -696,12 +701,12 @@ function replaceSmartObjects(layer_id, path, name){
696701 desc . putPath ( charIDToTypeID ( 'null' ) , new File ( path ) ) ;
697702 desc . putInteger ( charIDToTypeID ( "PgNm" ) , 1 ) ;
698703
699- executeAction ( stringIDToTypeID ( 'placedLayerReplaceContents' ) ,
700- desc , DialogModes . NO ) ;
704+ executeAction ( stringIDToTypeID ( 'placedLayerReplaceContents' ) ,
705+ desc , DialogModes . NO ) ;
701706 var currentActivelayer = app . activeDocument . activeLayer ;
702707 if ( name ) {
703708 currentActivelayer . name = name ;
704- }
709+ }
705710}
706711
707712function createGroup ( name ) {
@@ -712,14 +717,14 @@ function createGroup(name){
712717 group = app . activeDocument . layerSets . add ( ) ;
713718 // Add special character to highlight group that will be published
714719 group . name = name ;
715-
720+
716721 return group . id ; // only id available at this time :|
717722}
718723
719- function deleteLayer ( layer_id ) {
724+ function deleteLayer ( layer_id ) {
720725 /***
721726 * Deletes layer by its layer_id
722- *
727+ *
723728 * layer_id (int)
724729 **/
725730 var d = new ActionDescriptor ( ) ;
@@ -761,16 +766,16 @@ function saveEXR(savePath) {
761766function savePSB ( output_path ) {
762767 /***
763768 * Saves file as .psb to 'output_path'
764- *
769+ *
765770 * output_path (str)
766771 **/
767772 var desc1 = new ActionDescriptor ( ) ;
768773 var desc2 = new ActionDescriptor ( ) ;
769- desc2 . putBoolean ( stringIDToTypeID ( 'maximizeCompatibility' ) , true ) ;
770- desc1 . putObject ( charIDToTypeID ( 'As ' ) , charIDToTypeID ( 'Pht8' ) , desc2 ) ;
771- desc1 . putPath ( charIDToTypeID ( 'In ' ) , new File ( output_path ) ) ;
772- desc1 . putBoolean ( charIDToTypeID ( 'LwCs' ) , true ) ;
773- executeAction ( charIDToTypeID ( 'save' ) , desc1 , DialogModes . NO ) ;
774+ desc2 . putBoolean ( stringIDToTypeID ( 'maximizeCompatibility' ) , true ) ;
775+ desc1 . putObject ( charIDToTypeID ( 'As ' ) , charIDToTypeID ( 'Pht8' ) , desc2 ) ;
776+ desc1 . putPath ( charIDToTypeID ( 'In ' ) , new File ( output_path ) ) ;
777+ desc1 . putBoolean ( charIDToTypeID ( 'LwCs' ) , true ) ;
778+ executeAction ( charIDToTypeID ( 'save' ) , desc1 , DialogModes . NO ) ;
774779}
775780
776781function close ( ) {
@@ -780,13 +785,13 @@ function close(){
780785function renameLayer ( layer_id , new_name ) {
781786 /***
782787 * Renames 'layer_id' to 'new_name'
783- *
788+ *
784789 * Via Action (fast)
785- *
790+ *
786791 * Args:
787792 * layer_id(int)
788793 * new_name(str)
789- *
794+ *
790795 * output_path (str)
791796 **/
792797 doc = app . activeDocument ;
0 commit comments