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

Execute and return a value (or object) from another script

$
0
0

I would like to be able to have some of the little functions that I use often in my scripts just as seporate scripts. so I can update then in one place and not have to copy them into every script I want to use them in.

I am not sure if this is possible at all. But I would love to be able to just call them somehow and return values from them.

e.g.

Main code I need some colored swatches:

        var inCutColorCMYK = cmykColor(50, 0, 100, 0);        var intCutSPOT = makeSwatch("CutIN", inCutColorCMYK);

 

so I have these functions that I found/tweeked:

   function makeSwatch( swName, swCol) {     var doc = app.activeDocument;    var sel = doc.selection;    if (!inCollection(doc.swatches, swName)) {     var aSwatch = doc.spots.add();     aSwatch.name = swName;     aSwatch.color = swCol;     aSwatch.tint = 100;     aSwatch.colorType = ColorModel.SPOT;     var aSwatchSpot = new SpotColor();     aSwatchSpot.spot = aSwatch;     return aSwatchSpot;     }else{         return doc.swatches.getByName(swName);         }     };


function cmykColor(c, m, y, k) {     var newCMYK = new CMYKColor();     newCMYK.cyan = c;     newCMYK.magenta = m;     newCMYK.yellow = y;     newCMYK.black = k;     return newCMYK;     };




function inCollection(collection, nameString) {        var exists = false;    try{    for (var i = 0; i < collection.length; i++) {         if (collection[i].name == nameString) {             exists = true;             }         }     }catch(e){//alert("Illustrator needs drop kicked!!\nPlease restart Illustrator :/\n\n"+e)        }        return exists;              };

 

anyway! I keep finding my self using functions like this over and over in new scripts and hope there is a way to do this!

Any help is appreciated!

-Boyd


Viewing all articles
Browse latest Browse all 12845

Trending Articles



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