Copy link to clipboard
Copied
Hi, I am trying to refine the RandomTools created for Scriptographer so that it suits my preference, but I can't figure it out in Javascript. Not knowing a lot of Javascript don't help me either! ![]()
Here is the script, simplified to conserv only the Delete part. What I would like to do is to enter a percentage, and then this would be the percentage of selected object removed.
If anyone would point me to a direction with that, It would be really great.
/**
* randomDelete 0.4
* Base on
* Ken Frederick
* http://cargocollective.com/kenfrederick/
* http://kenfrederick.blogspot.com/
*
* Modified by Jolin Masson
*
* this script uses stuff borrowed from keegan's "rando-color.js"
* as well as from some other things i had written in processing
*
*/
script.coordinateSystem = 'bottom-up';
script.angleUnits = 'radians';
var sel;
var values = {
b_delete: true,
val_deleteAmt: 2,
};
// gui components
var components = {
b_delete: {
onChange: function(value) {
components.val_deleteAmt.enabled = value;
}
},
val_deleteAmt: {
type: 'number',
fullSize: true,
enabled: true
},
deleteRule: {
type: 'ruler',
fullSize: true,
},
submit: {
type: 'button',
value: 'Apply',
onClick: function() {
Main();
}
}
};
// Setup
function Setup() {
// initialize the palette window
var palette = new Palette('Random Delete 0.5', components, values);
}
// Update
function Update() {
}
// Main
function Main() {
// document properties
sel = activeDocument.getItems( { type: Item, selected: true } );
//adjust delete range values based on selection number
components.val_deleteAmt.range = [0, sel.length-1];
// loop through selected items
for ( i in sel ) {
var object = sel;
if( object.isValid() ) {
// ------------------------------------
// delete
// ------------------------------------
if ( values.b_delete ) {
rand = parseInt( Math.random()*values.val_deleteAmt );
if (rand == 0) object.remove();
}
} //end isValid()
}
} //end Main()
// ------------------------------------------------------------------------
// methods
// ------------------------------------------------------------------------
function random(minr, maxr) {
return minr + Math.random() * (maxr - minr);
}
// ------------------------------------------------------------------------
// execution
// ------------------------------------------------------------------------
Setup();
Update();
Thanks
I had some help from the Scriptographer forum, and here is the final stuff!
Copy link to clipboard
Copied
you should post your question in the Scriptographer forum, you may have better chances of getting help.
Copy link to clipboard
Copied
I will do that, but I don't know if the community is still very active there…
And here is the file, if someone want to give it a try!
Right now, the script will delete a random number of items, depending of the number you give in the dialog box, and the number is somehow in relation with the quantity of items selected.
I would like it to delete a given percentage of the items, no matter how much are selected.
Copy link to clipboard
Copied
I had some help from the Scriptographer forum, and here is the final stuff!
Copy link to clipboard
Copied
Can you point out what it does (not) do that it should (not) do?
(You seem to be using val_deleteAmt as both a range and 'as is', i.e. a single number, but that may just be something of Sg.)
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more