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

Resize then check collide and repeat untill max

$
0
0

I've got a trapezoid that is the guide box and artwork that needs to always be maxed size to fit it.  I've wrote a script that will place the artwork bottom center then move it up 3points so that it isn't touching.  I need the script to loop through and resize by 101% then redo the center function and check collide again.  I'm not even sure if there is a .collide or how to go about that but I went ahead and wrote the rest of the script.  The part that reads "arttouchguide.collide" on line 07 is the part that I'm having problems with and it is just a place holder as I know that it doesn't work right now.  Below the code is a .jpg of what I'm working with.

 

#target illustrator  var selecteditem = app.activeDocument.groupItems[0];     for ( arttouchguide.collide = false)  {   selecteditem.resize(101,101);   centerArt()
}

function centerArt()
   {         var thisdoc = app.activeDocument;         var selecteditem = app.activeDocument.groupItems[0];        selecteditem.selected = true;        var hasDocCoords = app.coordinateSystem == CoordinateSystem.ARTBOARDCOORDINATESYSTEM;                      var p = thisdoc.pageItems;         for (var i = 0, l = p.length; i < l; i++) {             var pID = p[i];             if (pID.guides == true) {                 var guideBox = pID             }         }          var wNum = guideBox.width;         var hNum = guideBox.height;        var swNum = selecteditem.width;        var shNum = selecteditem.height;               var sxOffset = (swNum/2);        var syOffset = (shNum);        var xOffset = (wNum/2);        var yOffset = (hNum-3);                      var xNum = guideBox.position[0]+xOffset;         var yNum = guideBox.position[1]-yOffset;               var guideXCenter = xNum-sxOffset;        var guideYCenter = yNum+(syOffset);               var sxNum = selecteditem.position[0]+sxOffset;        var syNum = selecteditem.position[1]-syOffset;               //to test your script for position un annotate the two alerts below                     // alert("GuideBox Data:\nWidth: "+wNum+"\nHeight: "+hNum+"\nX Position: "+xNum+"\nY Position: "+yNum);              // alert ("Selected object Data:\nWidth: "+swNum+"\nHeight: "+shNum+"\nX Position: "+sxNum+"\nY Position: "+syNum);                                    //changes the position of the selected artwork to the center of the guide box.        selecteditem.position = [guideXCenter, guideYCenter]              }//end centerart

 

Umbrella Resize Test.jpg

 

The red line is the guide box, the lime part is the artwork.  It will increase the size of the art, recenter it, move it up 3 points and check for overlap/collide and repeat till it is touching.  This is the only way that I can think of to max out the artwork inside a trapezoid.


Viewing all articles
Browse latest Browse all 12845

Trending Articles