Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Random Delete tool with Scriptographer

Explorer ,
Feb 10, 2013 Feb 10, 2013

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

ken.frederick@gmx.de

http://cargocollective.com/kenfrederick/

http://kenfrederick.blogspot.com/

*

*  Modified by Jolin Masson

http://jolinmasson.com/

*

*          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

TOPICS
Scripting
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Feb 21, 2013 Feb 21, 2013

I had some help from the Scriptographer forum, and here is the final stuff!

http://cl.ly/code/3y1u1q311T1x

Translate
Adobe
Community Expert ,
Feb 10, 2013 Feb 10, 2013

you should post your question in the Scriptographer forum, you may have better chances of getting help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 11, 2013 Feb 11, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Feb 21, 2013 Feb 21, 2013
LATEST

I had some help from the Scriptographer forum, and here is the final stuff!

http://cl.ly/code/3y1u1q311T1x

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 11, 2013 Feb 11, 2013

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.)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines