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

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

265

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

Enthusiast , 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
...

Votes

Translate

Translate
Adobe
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();

Votes

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

Votes

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
Enthusiast ,
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();

 

Votes

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

Votes

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