How to copy height to another object in illustrator script? thanks

Explorer ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

How does the script change the height of object 1 to the height of object 2? thanks22.png

TOPICS
Feature request , Scripting , Third party plugins

Views

125

Likes

Translate

Translate

Report

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

Participant , Jul 20, 2022 Jul 20, 2022

Quick modification. The clipping mask can be a group of paths or text in Adobe Illustrator. Then the code won't work. I didn't make it complicated. But in your example you have a mask from a simple path.

function resizeZero() {
  var aDoc = app.activeDocument;
  var zero = selection[0];
  var one = selection[1];
  var coeff = Math.abs(getHeight(one) / getHeight(zero) * 100);
  zero.resize(coeff, coeff);
  redraw();
}

function getHeight(item) {
  return (item.typename == 'GroupItem' && item.clipp
...

Likes

Translate

Translate
LEGEND ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

With two objects selected this script will resize the width of top object to match the width of bottom object:

function resizeZero() {
    var aDoc = app.activeDocument;
    var Zero = selection[0];
    var One = selection[1];
    Zero.width = One.width;
    redraw();
}

resizeZero();

Likes

Translate

Translate

Report

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 ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

What is required is that the height of 1 becomes the height of 2, the width is increased in the same proportion, and the clipping mask is supported.6.png

Likes

Translate

Translate

Report

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
Participant ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

Quick modification. The clipping mask can be a group of paths or text in Adobe Illustrator. Then the code won't work. I didn't make it complicated. But in your example you have a mask from a simple path.

function resizeZero() {
  var aDoc = app.activeDocument;
  var zero = selection[0];
  var one = selection[1];
  var coeff = Math.abs(getHeight(one) / getHeight(zero) * 100);
  zero.resize(coeff, coeff);
  redraw();
}

function getHeight(item) {
  return (item.typename == 'GroupItem' && item.clipped) ? getMaskPath(item).height : item.height;
}

function getMaskPath(group) {
  for (var i = 0; i < group.pageItems.length; i++) {
    var item = group.pageItems[i];
    if ((item.typename === 'CompoundPathItem' && item.pathItems[0].clipping) || item.clipping) {
      return item;
    }
  }
}

resizeZero();

 

Likes

Translate

Translate

Report

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 ,
Jul 20, 2022 Jul 20, 2022

Copy link to clipboard

Copied

LATEST

Thanks Sergey Osokin the script works perfectly

Likes

Translate

Translate

Report

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