Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

dynamic action does not working in palate button script

$
0
0

Hi Friend's

 

My dynamic action does not work in palette button option but it is working in dialog option. i need to know what is the issues going on my script. kindly help to complete this script

 

Button Palette script:

 

#target illustrator-21
#targetengine main

var win = new Window('palette', '');  
var tpanel = win.add ("tabbedpanel");  
tpanel.alignChildren = ["fill", "fill"];  
tpanel.preferredSize = [100,20];  
win.margins = 0;  
win.spacing = 0;  
var subtab1panel = tpanel.add ("tab", undefined, "Diadeis Script Panel");  
subtab1panel.orientation="row";  
subtab1panel.alignChildren = ["fill", "fill"];      
var t1group = subtab1panel.add("group");  
t1group.orientation = "row";  
t1group.alignChildren = ["fill", "fill"];  

var pfad = "/Applications/Diadeis Scripts/"      
var btnSelect1 = t1group.add('button', undefined, 'Ai Compare Zoom');  
var scriptToLoad1 =  function()    {        var callFunction = matchZoom +  '\rmatchZoom();';        btMessaging( 'illustrator', callFunction );    }   


function matchZoom() 
{
    var doc0= app.activeDocument;    var zoom = doc0.activeView.zoom;    var ctrPoint = doc0.activeView.centerPoint;    var idoc;        if (app.documents.length>1) {        for (var d=1; d<app.documents.length; d++) {            idoc = app.documents[d];            idoc.activeView.zoom = zoom;            idoc.activeView.centerPoint = ctrPoint;        }    }
}

function btMessaging( target, callFunction ) {
    var bt = new BridgeTalk();    bt.target = target;    bt.body = callFunction;    bt.send();
}  
var btnSelect2 = t1group.add('button', undefined, 'CTC');   
var scriptToLoad2 = new File(pfad+"CTC.jsx");     
var btnSelect3 = t1group.add('button', undefined, 'CTC (for Ferrero)');   
var scriptToLoad3 = new File(pfad+"CTC_Ferrero.jsx");

var btnSelect4 = t1group.add('button', undefined, 'CLD Automation');   
var scriptToLoad4 = new File(pfad+"VariableImporter.jsx");     
btnSelect1.onClick = scriptToLoad1;      
btnSelect2.onClick = function(){           var des = scriptToLoad2;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function      btnSelect3.onClick = function(){           var des = scriptToLoad3;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function     btnSelect4.onClick = function(){           var des = scriptToLoad4;     des.open("r");              var bt = new BridgeTalk;     bt.target = "illustrator";              var script = des.read();     des.close();                   bt.body = script;     bt.send();    
}// end function  

win.center();  
win.show();

 

Example linked script:

//////////////////////////////////////////////////////////////////////////////////////
//This script will generate a Live Ai file and CTC Ai file.                                                            //
// Display dialog events : Live Rasterize Effect Setting, Check Spelling, Launch Workflow.          //
//Cleanup Process : Unused Graphics Style, Unused Swatches,  Unsed Symbol.                           //
// Version : 1.0                                                                                                                  //
///////////////////////////////////////////////////////////////////////////////////

if ( app.documents.length == 1 )

{
// Rasterize Effect Setting 
app.executeMenuCommand('Live Rasterize Effect Setting'); 

//Unlock ("Background",  "Artwork") Layers
var aDoc = app.activeDocument;  
var myLayers = aDoc.layers;  
var actName = ("Background");  
try {      aDoc.activeLayer = myLayers.getByName (actName);      redraw();      actLayer = aDoc.activeLayer;      actLayer.locked = false;      actLayer.visible = true;      redraw();      }  
catch (e) {      alert ("Layer "+actName+" not found")      } 

var aDoc = app.activeDocument;  
var myLayers = aDoc.layers;  
var actName = ("Artwork");  
try {      aDoc.activeLayer = myLayers.getByName (actName);      redraw();      actLayer = aDoc.activeLayer;      actLayer.locked = false;      actLayer.visible = true;      redraw();      }  
catch (e) {      alert ("Layer "+actName+" not found")      } 

// Check Spelling  
app.executeMenuCommand('Check Spelling'); 

// Check Find and Replace  
app.executeMenuCommand('Find and Replace'); 

// Link Replace 
function linkReplacer() {       var orginalUIL = app.userInteractionLevel;       app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;       if (app.documents.length == 0) {            alert('Please have an "Illustrator" document open before running this script.');            return;       } else {            docRef = app.activeDocument;       }                var defaultFolder = new Folder (Folder(app.activeDocument.path + '/../040 Images/043 High Res'));       var psdFolder = defaultFolder;       if (psdFolder == null) return;              with (docRef) {            var placedFiles = new Array();            for (var i = 0; i < placedItems.length; i++) {                 placedFiles.push(placedItems[i].file.name);            }                        for (var j = 0; j < placedItems.length; j++) {                 var rePlace = new File(psdFolder.fsName + '/' + placedFiles[j]);                 if (rePlace.exists) {                      placedItems[j].file = rePlace;                 } else {                      alert('File "' + placedFiles[j] + '" is missing?');                 }            }       }       app.userInteractionLevel = orginalUIL;  
}      linkReplacer(); 

//Unlock all Layers
function unlockedSubLayers ( layers ) {      var i = layers.length;      if ( i ) {          while ( i-- ) {              layers[i].locked = false;              unlockedSubLayers( layers[i].layers );          }      }  
}  
unlockedSubLayers( activeDocument.layers );

//Empty text boxes are removed
app.executeMenuCommand('cleanup menu item');  

//Lock all Layers
function lockedSubLayers ( layers ) {      var i = layers.length;      if ( i ) {          while ( i-- ) {              layers[i].locked = true;              lockedSubLayers( layers[i].layers );          }      }  
}  
lockedSubLayers( activeDocument.layers );


//Cleanup Dynamic Action
 function createAction ( actionString, set ) {                    var fpath = Folder ( "~/Desktop/" )          var f = File ( fpath + set + '.aia' );                    f.open( 'w' );          f.write( actionString );          f.close();          app.loadAction( f );          f.remove();       } 

function runActionScript(){            var set = 'Cleanup';            var action = 'Delete Unused Panel Items';                    var actionString = [            
"/version 3",
"/name [ 7",
"    436c65616e7570",
"]",
"/isOpen 0",
"/actionCount 1",
"/action-1 {",
"    /name [ 25",
"        44656c65746520556e757365642050616e656c204974656d73",
"    ]",
"    /keyIndex 0",
"    /colorIndex 0",
"    /isOpen 1",
"    /eventCount 12",
"    /event-1 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_symbol_palette)",
"        /localizedName [ 7",
"            53796d626f6c73",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 4294967295",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 12",
"        }",
"    }",
"    /event-2 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_symbol_palette)",
"        /localizedName [ 7",
"            53796d626f6c73",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 4294967295",
"            /type (enumerated)",
"            /name [ 13",
"                44656c6574652053796d626f6c",
"            ]",
"            /value 5",
"        }",
"    }",
"    /event-3 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-4 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_styles)",
"        /localizedName [ 14",
"            47726170686963205374796c6573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 14",
"        }",
"    }",
"    /event-5 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_styles)",
"        /localizedName [ 14",
"            47726170686963205374796c6573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 12",
"                44656c657465205374796c65",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-6 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-7 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_brush)",
"        /localizedName [ 5",
"            4272757368",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 8",
"        }",
"    }",
"    /event-8 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_brush)",
"        /localizedName [ 5",
"            4272757368",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 12",
"                44656c657465204272757368",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-9 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"    /event-10 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_swatches)",
"        /localizedName [ 8",
"            5377617463686573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 17",
"                53656c65637420416c6c20556e75736564",
"            ]",
"            /value 11",
"        }",
"    }",
"    /event-11 {",
"        /useRulersIn1stQuadrant 1",
"        /internalName (ai_plugin_swatches)",
"        /localizedName [ 8",
"            5377617463686573",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 0",
"        /parameterCount 1",
"        /parameter-1 {",
"            /key 1835363957",
"            /showInPalette 1",
"            /type (enumerated)",
"            /name [ 13",
"                44656c65746520537761746368",
"            ]",
"            /value 3",
"        }",
"    }",
"    /event-12 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_stop)",
"        /localizedName [ 4",
"            53746f70",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 1",
"        /showDialog 1",
"        /parameterCount 2",
"        /parameter-1 {",
"            /key 1952807028",
"            /showInPalette 0",
"            /type (ustring)",
"            /value [ 0",
"",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1668247156",
"            /showInPalette 4294967295",
"            /type (boolean)",
"            /value 1",
"        }",
"    }",
"}"          ].join( "\n" );            createAction( actionString, set );            app.doScript( action, set );            app.unloadAction( set, "" );        }  

runActionScript();
    



//recurse Layers
function recurseLayers( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var v = objArray[i].visible;                      if ( !v ) objArray[i].visible = true;                              // Recurse the contained layer collection                      if ( objArray[i].layers.length > 0 ) {                                recurseLayers( objArray[i].layers )                      }                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].visible = v;            }  
};    
function recurseGroups( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                              // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].hidden = h;            }  
};  



// populate Live file.
for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = new File(workingDocFile.toString());           workingDoc.saveAs(aiFile);     }

// Text to Outline
function outlineDocText(  ) {              if ( app.documents.length == 0 ) return;        var docRef = app.activeDocument;                recurseLayers( docRef.layers );      
};    
outlineDocText();   



//recurse Layers
  
function recurseLayers( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var v = objArray[i].visible;                      if ( !v ) objArray[i].visible = true;                          outlineText( objArray[i].textFrames );                          // Recurse the contained layer collection                      if ( objArray[i].layers.length > 0 ) {                                recurseLayers( objArray[i].layers )                      }                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].visible = v;            }  
};    
function recurseGroups( objArray ) {                for ( var i = 0; i < objArray.length; i++ ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                          outlineText( objArray[i].textFrames );                          // Recurse the contained group collection                      if ( objArray[i].groupItems.length > 0 ) {                                recurseGroups( objArray[i].groupItems )                      }                           // Return to previous values                      objArray[i].locked = l;                      objArray[i].hidden = h;            }  
};    



function outlineText( objArray ) {                // Reverse this loop as it brakes the indexing            for ( var i = objArray.length-1; i >= 0; i-- ) {                          // Record previous value with conditional change                      var l = objArray[i].locked;                      if ( l ) objArray[i].locked = false;                          // Record previous value with conditional change                      var h = objArray[i].hidden;                      if ( h ) objArray[i].hidden = false;                          var g = objArray[i].createOutline(  );                          // Return new group to previous Text Frame values                      g.locked = l;                      g.hidden = h;                }    
}; 


// Menu Command of Find Font 
app.executeMenuCommand('Adobe Illustrator Find Font Menu Item'); 

// populate CTC file.

for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = new File(workingDocFile.toString().replace(".ai","_CTC.ai"));           workingDoc.saveAs(aiFile);     }                
for ( i = 0; i < app.documents.length; i++ ) {    var workingDoc = app.documents[i];       var workingDocFile = workingDoc.fullName;            var aiFile = Folder (File(workingDocFile.toString().replace("_CTC.ai",".ai")));           app.open (aiFile);     }

 //Launch Workflow Dynamic Action
 function createAction1 ( actionString, set ) {                    var fpath = Folder ( "~/Desktop/" )          var f = File ( fpath + set + '.aia' );                    f.open( 'w' );          f.write( actionString );          f.close();          app.loadAction( f );          f.remove();       } 

function runActionScript1(){            var set = 'diadeis';            var action = 'Launch Workflow';                    var actionString = [            
"/version 3",
"/name [ 7",
"    64696164656973",
"]",
"/isOpen 1",
"/actionCount 1",
"/action-1 {",
"    /name [ 15",
"        4c61756e636820576f726b666c6f77",
"    ]",
"    /keyIndex 0",
"    /colorIndex 0",
"    /isOpen 0",
"    /eventCount 1",
"    /event-1 {",
"        /useRulersIn1stQuadrant 0",
"        /internalName (adobe_commandManager)",
"        /localizedName [ 16",
"            416363657373204d656e75204974656d",
"        ]",
"        /isOpen 0",
"        /isOn 1",
"        /hasDialog 0",
"        /parameterCount 3",
"        /parameter-1 {",
"            /key 1769238125",
"            /showInPalette 4294967295",
"            /type (ustring)",
"            /value [ 18",
"                4c61756e636820576f726b666c6f772e2e2e",
"            ]",
"        }",
"        /parameter-2 {",
"            /key 1818455661",
"            /showInPalette 4294967295",
"            /type (ustring)",
"            /value [ 15",
"                4c61756e636820576f726b666c6f77",
"            ]",
"        }",
"        /parameter-3 {",
"            /key 1668114788",
"            /showInPalette 4294967295",
"            /type (integer)",
"            /value 2164260958",
"        }",
"    }",
"}"            ].join( "\n" );            createAction( actionString, set );            app.doScript( action, set );            app.unloadAction( set, "" );        }  

runActionScript1();

alert('Completed');
}
             else              {                               alert('Multiple Artworks are opened.\n Close all other reference files \n Expect Final artwork file');                  !  }

Thanks and regards.

Kalaimani.S


Viewing all articles
Browse latest Browse all 12845

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>