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

How can I correctly move unexpanded Compound Shapes in Illustrator using a script?

Contributor ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

When I try to move and scale selected objects in Illustrator using a script, the unexpanded Compound Shapes cannot be moved correctly, while other objects or groups (including unexpanded Compound Shapes) can be moved correctly. Can anyone guide me on how to modify the JSX script to properly move these objects?sample.pngexpand image

 

 

var doc = app.activeDocument;
var selection = doc.selection;

var moveX = 10; 
var moveY = 20;
var scaleX = 0.9;
var scaleY = 0.8;

for (var i = 0; i < selection.length; i++) {
  var item = selection[i];

  if (item.parent instanceof GroupItem) {
    continue;
  }

  item.resize(
    scaleX * 100, // x
    scaleY * 100, // y
    true, // changePositions
    true, // changeFillPatterns_value
    true, // changeFillGradients
    true, // changeStrokePattern
    1 ? Math.sqrt(scaleX * scaleY) * 100 : 100,
    Transformation.TOPLEFT
  );
  item.left += moveX;
  item.top -= moveY;
}

 

 

TOPICS
Scripting

Views

492
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 , Oct 11, 2023 Oct 11, 2023

I realized what was going on. You ran into an ExtendScript bug, and there are a lot of themIf a Compound Shape contains a Group of objects or a Compound Path (orange labels), the script skips these objects and processes only simple <Path> objects.

I would like to say that there is a workaround for this bug, which requires manual selection of only <Path> inside the Compound Shape: https://aiscripts.medium.com/compound-shape-mess-6b6c44e8c08. But your task is to process all selected objects in a

...

Votes

Translate
Adobe
Guide ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Try changing this statement

  if (item.parent instanceof GroupItem) {
    continue;
  }

to

  if (item.parent.typename == "PluginItem" || 
      item.parent.typename == "GroupItem") {
    continue;
  }

Votes

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
Contributor ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Thank you for your help! However, the code still hasn't solved this problem.

Votes

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

I'm going to take a wild guess. Inside the compound shape, you have not only individual paths, but also groups of paths? Can you show a screenshot of the contents of Compound Shape?

Votes

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
Contributor ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

 Your guess proves that you are very intelligent. This test file does indeed contain PluginItem, path, CompoundPathItem, and GroupItem, so there are always some objects that cannot be moved or scaled correctly.

4c8df107ce060bc4704ad98f73e0ea48.jpegexpand image

Votes

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 ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

I realized what was going on. You ran into an ExtendScript bug, and there are a lot of themIf a Compound Shape contains a Group of objects or a Compound Path (orange labels), the script skips these objects and processes only simple <Path> objects.

I would like to say that there is a workaround for this bug, which requires manual selection of only <Path> inside the Compound Shape: https://aiscripts.medium.com/compound-shape-mess-6b6c44e8c08. But your task is to process all selected objects in a FOR loop, so I don't see a good solution here.

Untitled-1.pngexpand image

Votes

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
Contributor ,
Oct 11, 2023 Oct 11, 2023

Copy link to clipboard

Copied

LATEST

Thank you for your reply. I'm trying to separate the GroupItem and process it separately, and there is always a solution. Also, looking forward to a master appearing.

Votes

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