Quantcast
Channel: Adobe Community: Message List - Photoshop Scripting
Viewing all articles
Browse latest Browse all 27456

Re: prompt() dialog box

$
0
0

Here is a script I wrote to generate a random noise pattern. It is customizable and the settings can be saved and reused. It's nothing fancy, but it has some elements in it that I think will be helpful to you. From what I gather, you can modify scripts well enough so you should have no problem getting this to work with yours.

 

#target photoshop

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

var startTypeUnits = app.preferences.typeUnits;

var startDisplayDialogs = app.displayDialogs;

//Set preferences to use pixels

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

app.displayDialogs = DialogModes.NO;

 

function readini() {

    var SCRIPTS_FOLDER = new Folder(app.path + '/' + localize("$$$/ScriptingSupport/InstalledScripts=Presets/Scripts"));

    ini=new File([SCRIPTS_FOLDER + "/NoiseGen.ini"]);

    if (ini.created) {

        $.evalFile(ini);

        return true;

    };

    ini.close();

};

 

var ng= new Window("dialog{text:'Noise Generator',bounds:[100,100,500,600],\

        start:Scrollbar{bounds:[50,50,330,60] , minvalue:5,maxvalue:50,value:5},\

        stText:EditText{bounds:[340,45,370,65] , text:'5' ,properties:{multiline:false,noecho:false,readonly:false}}\

        startText:EditText{bounds:[140,70,240,90] , text:'START SIZE' ,properties:{multiline:false,noecho:false,readonly:true}}\

        scale:Scrollbar{bounds:[50,130,330,140] , minvalue:1,maxvalue:25,value:17},\

        scText:EditText{bounds:[340,125,370,145] , text:'17' ,properties:{multiline:false,noecho:false,readonly:false}}\

        scaleText:EditText{bounds:[140,150,240,170] , text:'SCALE AMT' ,properties:{multiline:false,noecho:false,readonly:true}}\

        noise:Scrollbar{bounds:[50,210,330,220] , minvalue:1,maxvalue:100,value:15},\

        nText:EditText{bounds:[340,205,370,225] , text:'15' ,properties:{multiline:false,noecho:false,readonly:false}}\

        noiseText:EditText{bounds:[140,230,240,250] , text:'NOISE AMT' ,properties:{multiline:false,noecho:false,readonly:true}}\

        loops:Scrollbar{bounds:[50,290,330,300] , minvalue:5,maxvalue:50,value:40},\

        lText:EditText{bounds:[340,285,370,305] , text:'40' ,properties:{multiline:false,noecho:false,readonly:false}}\

        loopText:EditText{bounds:[140,300,240,320] , text:'LOOP TIMES' ,properties:{multiline:false,noecho:false,readonly:true}}\

        pixelText:EditText{bounds:[80,360,245,376] , text:'Number of pixels per side:' ,properties:{multiline:false,noecho:false,readonly:true}}\

        sizeText:EditText{bounds:[250,360,320,376] , text:'2802' ,properties:{multiline:false,noecho:false,readonly:true}}\

        checkbox0:Checkbox{bounds:[60,385,181,406] , text:'Colorize?' }\

        save:Button{bounds:[60,410,160,430] , text:'Save as default' },\

        clear:Button{bounds:[210,410,310,430] , text:'Reset defaults' },\

        buttonOK:Button{bounds:[60,450,160,470] , text:'OK' },\

        buttonC:Button{bounds:[210,450,310,470] , text:'Cancel' },\

}");

function getSize() {

    grBy=(ng.scale.value+100)/100;

    var i=ng.loops.value;

    var s=ng.start.value;

    while (i>1) {

        s=Math.round(s*grBy);

        i--;

    }

    return s;

};

   

ng.stText.onChange = function() {

    this.parent.start.value = this.parent.stText.text;

    this.parent.sizeText.text = getSize();

};

ng.scText.onChange = function() {

    this.parent.scale.value = this.parent.scText.text;

    this.parent.sizeText.text = getSize();

};

ng.nText.onChange = function() {

    this.parent.noise.value = this.parent.nText.text;

};

ng.lText.onChange = function() {

    this.parent.loops.value = this.parent.lText.text;

    this.parent.sizeText.text = getSize();

};

ng.start.onChanging = function() {

    var st =  Math.floor(this.value);

    this.parent.stText.text = st;

};

ng.scale.onChanging = function() {

    var sc =  Math.floor(this.value);

    this.parent.scText.text = sc;

};

ng.noise.onChanging = function() {

    var n =  Math.floor(this.value);

    this.parent.nText.text = n;

};

ng.loops.onChanging = function() {

    var l =  Math.floor(this.value);

    this.parent.lText.text = l;

};

ng.start.onChange = function() {

    var st =  Math.floor(this.value);

    this.parent.sizeText.text = getSize();

};

ng.scale.onChange = function() {

    var sc =  Math.floor(this.value);

    this.parent.sizeText.text = getSize();

};

ng.loops.onChange = function() {

    var l =  Math.floor(this.value);

    this.parent.sizeText.text = getSize();

};

ng.buttonOK.onClick = function(){

    noiseOK=true;

    ng.close();

};

ng.save.onClick = function(){

    ini.open('w');

    ini.writeln("startSize=" ,Math.floor(ng.start.value));

    ini.writeln("scaleSize=",Math.floor(ng.scale.value));

    ini.writeln("noiseAmt=",Math.floor(ng.noise.value));

    ini.writeln("loopNum=",Math.floor(ng.loops.value));

    ini.close();

};

ng.clear.onClick = function(){

    ini.remove();

    ng.start.value=5;

    ng.stText.text=5;

    ng.scale.value=17;

    ng.scText.text=17;

    ng.noise.value=15;

    ng.nText.text=15;

    ng.loops.value=40;

    ng.lText.text=40;

    ng.sizeText.text=2802;

}

   

if (readini()) {

    if (startSize) {

        ng.start.value=startSize;

        ng.stText.text=startSize;

    };

    if (scaleSize) {

        ng.scale.value=scaleSize;

        ng.scText.text=scaleSize;

    };

    if (noiseAmt) {

        ng.noise.value=noiseAmt;

        ng.nText.text=noiseAmt;

    };

    if (loopNum) {

        ng.loops.value=loopNum;

        ng.lText.text=loopNum;

    };

    ng.sizeText.text = getSize();

};

 

noiseOK=false;

ng.center();

ng.show();

 

if (noiseOK) {

    var docRef = app.documents.add(Math.floor(ng.start.value),Math.floor(ng.start.valu e),72,"Noise");

    var layerRef = docRef.artLayers.add();

    var colorRef = new SolidColor;

    colorRef.rgb.red = 127.5;

    colorRef.rgb.green = 127.5;

    colorRef.rgb.blue = 127.5;

 

    docRef.selection.selectAll();

    docRef.selection.fill(colorRef);

    layerRef.applyAddNoise (Math.floor(ng.noise.value), NoiseDistribution.UNIFORM, true);

 

    grBy=UnitValue ((Math.floor(ng.scale.value)+100), '%');

    var i=Math.floor(ng.loops.value);

    while (i>0) {

        if (ng.checkbox0.value) {

            colorRef.rgb.red=Math.round(Math.random()*255);

            colorRef.rgb.green=Math.round(Math.random()*255);

            colorRef.rgb.blue=Math.round(Math.random()*255);

        }

        docRef.resizeImage (grBy, grBy);

        layerRef = docRef.artLayers.add();

        docRef.selection.selectAll();

        docRef.selection.fill(colorRef);

        layerRef.blendMode = BlendMode.SOFTLIGHT;

        layerRef.applyAddNoise (Math.floor(ng.noise.value), NoiseDistribution.UNIFORM, true);

        layerRef = layerRef.merge();

        i--;

    };

    docRef.selection.deselect();

    docRef = null;

    layerRef = null;

};

ini.close();

//Set preferences back to before

app.preferences.rulerUnits = startRulerUnits;

app.preferences.typeUnits = startTypeUnits;

app.displayDialogs = startDisplayDialogs;


Viewing all articles
Browse latest Browse all 27456


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