0

I tried to create a script that creats a rectangle of a given size, make a group and a clipping mask and after all that resize it to a diffrent size in mm.

for example I have a graphic with the name "fish400" and I clip it in a rectangle of 400 X 400 that I create with the script. So far so good. my problem is that I want to resize the clipping with all it's content to 382. when I set the height to be the rec. size-18 it gets the height of 385.1

I'm not a very skilled programmer and the script could be written better but I really don't get my mistake.

here is my code:

var doc = app.activeDocument; 
var layers = doc.layers;  
var myLayer = layers["Layer 1"]; //this defines the layer that you want to get the selection from 

var vals = 0;
var tzim = 0;
var side = 0; //width || height

//mm convertor
function mm(n) {return n * 2.83464566929134;}

doc.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want.

var found = false;
for(var a=0 ;a<doc.groupItems.length; a++)
{
    if (doc.groupItems[a].name == "fish400") {vals = mm(400); tzim = mm(18); side = 1; found = true;}
}

if (found = true)
{
    var rect = doc.pathItems.rectangle(0,0,vals,vals);

    app.executeMenuCommand("selectall");

    var groupItem = doc.groupItems.add();
    var count = selection.length;
    for(var i = 0; i < count; i++) 
    {
        var item = selection[selection.length - 1];
        item.moveToBeginning(groupItem);
    }

    groupItem.clipped = true;
    
    item.top = center_point[0] + (item.height/2);
    item.left = center_point[1] - (item.width/2);
    
    if (side == 1) {groupItem.height -= tzim;} else if (side == 0) {groupItem.width -= tzim;}
}
1
  • The height is offcourse the size including all items inside the clipping mask. Just because its hidden does not mean its not there.
    – joojaa
    Aug 26 '21 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.