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

Clipping Mask Object handling from Script vs. C++ Plugin

New Here ,
Apr 16, 2019 Apr 16, 2019

Hi

I have a situation in Illustrator as shown in the Image below. Here "Layer 1" is the top most parent layer group. Inside "Layer 1" there is a <Clip Group> (Clipping Mask operation done on a "path art" and "Image 1") and an item "Image 2". And <Clip Group> is the currently selected entity.

1. I am executing the following Script command

var SelectedEntities = activeDocument.selection;

Here I am getting only one object in SelectedEntities, which is [ GroupItem ]

2. Now I am executing following C++ Plugin code on the same selection

AIArtHandle **matches;

ai::int32 nCount = 0;

result = sAIMatchingArt->GetSelectedArt(&matches, &nCount);

Here I'm getting 4 item inside "matches"

     i. kGroupArt for Layer 1

     ii. kGroupArt for <Clip Group>

     iii. kPathArt for <Clipping Path>

     iv. kRasterArt for Image 1

Can anyone please explain

1. Why there are two different behaviour for the same task or how these APIs differs?

2. How can I achieve similar behaviour in C++ Plugin as in Script?

3. How can I achieve similar behaviour in Script as in C++ Plugin?

Thanks in advance for your appreciable response.

Screenshot_1.png

TOPICS
SDK
1.5K
Translate
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
Adobe
Explorer ,
Apr 16, 2019 Apr 16, 2019

2. How can I achieve similar behaviour in C++ Plugin as in Script?

You need to use one of the methods, that use specs to specify which type of items exactly you want to select. It's either sAIArtSet->MatchingArtSet(&specs, numSpecs, artSet) or sAIMatchingArt->GetMatchingArt(specs, numSpecs, &artHandle, &numMatches);

Defining spec for each method has differences, but basically, it looks like { type, whichAttr, attr }, where type is AIArtType constant, while whichAttr and attr are AIArtUserAttr constants.

For example, GetSelectedArt() method is just an equivalent of GetMatchingArt with this spec:

AIMatchingArtSpec specs[1] = { {kAnyArt, kFullySelected, kFullySelected} };

To achieve similar behavior as in scripting API, the suitable spec is { kAnyArt, kArtTargeted, kArtTargeted };

3. How can I achieve similar behaviour in Script as in C++ Plugin?

Write a recursive function that will iterate through activeDocument.selection and append pageItems of every container to a target array.

Translate
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
New Here ,
Apr 17, 2019 Apr 17, 2019

2. How can I achieve similar behaviour in C++ Plugin as in Script?

Hi nillmolen

Thanks for this information. Yes, it is helpful, but doesn't match the behaviour in every case.

I tried your code and tested with the same file. But when I changed the selection by clicking on target selection of Layer 1 (as shown in image below), I addressed the following behaviour:

1. Script command:

var SelectedEntities = activeDocument.selection;

Here I'm getting two objects in SelectedEntities, [GroupItem ] and [PlacedItem Image2].

2. C++ Plugin code:

AIArtHandle **matches;

AIMatchingArtSpec spec = { kAnyArt, kArtTargeted, kArtTargeted };

sAIMatchingArt->GetMatchingArt(&spec, 1, &matches, &nCount);

Here I'm getting only one item inside "matches"

    i. kGroupArt for Layer 1

I couldn't understand how strange activeDocument.selection behaves!

Can anyone please help?

Screenshot_7.png

Translate
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 ,
Apr 17, 2019 Apr 17, 2019

Well, I understand why you are trying to find similarities, but why are you expecting that two separate API should act the exact same way?

Most probably they were created by different teams for different purposes, so they just have differences, that's it.

Scripting API, unlike plugin API, doesn't "see" invisible groups that actually attached to every layer and pluginItem. So when you are targeting on a layer, activeDocument.selection returns the content of that invisible group, while the GetMatchingArt returns the group itself. And neither returns the proper layer handle.

I'm afraid, the only way to achieve the exact same behavior is to write for the plugin the custom method, which would handle all possible conditions and exceptions. At the same time, this is just not possible to achieve 100% same result in a script as in a plugin since script API has constraints relatively plugin API.

Translate
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
New Here ,
Apr 17, 2019 Apr 17, 2019

Thanks nillmolen​.

Actually I have a script which is doing some work based on the selection in the document. And script is identifying the selection with the API activeDocument.selection. So, my purpose is to implement the same work in C++ Plugin as done by the script.

Alternatively, I also need to clarify one behaviour, which is a part of C++ Plugin current implementation. If I use sAIMatchingArt->GetSelectedArt, then will I always get items in AIArtHandle **matches in the same order, as we can see from top to bottom in Layers panel after expanding all its layers, groups and subgroups?

For example, Layer 1 -> <Clip Group> -> <Clipping Path> -> Image1 -> Image2. Though this is simpler one, nesting can be more complex.

Translate
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 ,
Apr 18, 2019 Apr 18, 2019
LATEST
If I use sAIMatchingArt->GetSelectedArt, then will I always get items in AIArtHandle **matches in the same order, as we can see from top to bottom in Layers panel after expanding all its layers, groups and subgroups?

Yes, that's exactly how it works. Order of items in any of selection arrays will always be from top to bottom like it is in the layers panel. By the way, that is common for both APIs.

Translate
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