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

height parameter and math.random constraint

$
0
0

I'm a scripting newbie. I'm trying to make a script that will...

  1. Grab all the objects I have selected
  2. Scale them down (in height) randomly to between 30% and 100% of their original height.

 

Here's what I have so far...

 

//get all the objects that are currently selected in the document

var selectedObjects = app.activeDocument.selection;

 

//decrease their size by a random number between 0% and 70%

for (var i=0; i<selectedObjects.length; i++){

          // gets the height of the current object

          var myHeights = selectedObjects[i].height;

          //take the height of the current object and scale it by a random percentage

          selectedObjects[i].height= Math.floor((Math.random()*myHeights)+.3);

}

 

 

And here's what it's doing, which is great...

ThisPartIsWorking.gif

But there are two problems I'm running into...

[Problem A] The height is getting scaled relative to the document instead of relative to the object. I would like to be able to rotate the objects around an axis manually before running the script and still have them scale each individual height relative to each object. So far, my script is scaling relative to the document x, y (I think).

ThisPartIsNotWorking.gif

I have set the pivot point for each of the rectangles to bottom center, but no dice. In the script, how do I tell it to use the anchor point of the object for scaling instead of the document?

 

[Problem B] I'm having trouble constraining the math.random to my values. For instance, notice here

ThisPartIsNotReallyWorking.gif

that the some of the rectangles end up teeny (smaller than 30% of the original height). How do I set constraints on the math.random so that it's easy for me to adjust the parameters? Right now I'm using math.floor but I'm obviously doing something wrong.

 

Any insight?


Viewing all articles
Browse latest Browse all 12845

Trending Articles



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