Skip to main content
Inspiring
May 13, 2022
Answered

Is there an attribute that can determine whether an object has an "effect" or opacity applied?

  • May 13, 2022
  • 8 replies
  • 2453 views

Is there an attribute (Boolean Value) that can determine whether an object has an "effect" or opacity applied(object elements marked as "solid circle" on the layer)?

 

For the opacity, pathItem.opacity attribute only access the opacity of the whole object, not the opacity with details.

 

Set doc = app.ActiveDocument
For Each Obj In doc.pageitems
If Obj.Opacity < 100 Then
MsgBox "Have an effect applied!" & " " & TypeName(Obj) & " " & Obj.Opacity
End If
Next

 

 

This topic has been closed for replies.
Correct answer femkeblanco

@Raymond ZJH  "expandStyle" corresponds to Object > Expand Appearance in the menu bar. Expand Appearance, as the name implies, expands the appearance of a path with an appearance attribute (effect or transparency), producing a group (representing the stroke and the fill). The script tests whether or not a path's appearance is expandable.

 

The script works as follows:  You're asked to select a path. This path is duplicated. The duplicate is selected. Expand Appearance is invoked. At this point, if the item which is selected is a group, the path's appearance is expandable, i.e. there is an effect or transparency. In the end, the duplicate is removed.

 

The script has it's drawbacks. First is runtime, as @pixxxelschubser  points out. This is particularly relevant if you want to test nested items, which will add (probably unmanageable) complexity to an already sluggish script. Second, if a path has either a stroke or a fill but not both, expanding appearance will not produce a group. Odd effects will also not produce a group, giving a false negative.

 

On a positive note, a similar approach has worked for my needs in the past. 

8 replies

Kurt Gold
Community Expert
Community Expert
May 17, 2022

Raymond,

 

you may still want to share at least one or two of your rather complex files with nested instances of transparencies (and possibly other effects).

 

Otherwise it is rather difficult to think about possible solutions (or solutions which may work just partially).

 

Inspiring
May 18, 2022

Hi @Kurt Gold 

Thank you for following my post. But I'm sorry, I can't upload these files, because my network environment doesn't allow me to do so. Even when I visit this forum, I have many twists and turns, and sometimes I can't access it directly. It's inconvenient to talk about the specific reasons here.
In addition, I don't think it's good to make a direct solution to individual documents, which may be incomplete, because each document is different. As you and pixxxelschubser mentioned, there are many forms of effect and opacity. I don't know which effects are used in each file, because these files are sent to me by my customers. What I need to do is to typeset and output these files, but the output device does not support these effects and opacity, otherwise all output colors will be seriously lost, not just these elements with effects or opacity applied, so I need to deal with these elements. When I can't find all the elements, I can only rasterize the whole file and then output it, but this has a loss of quality. It's more obvious when I output a large area.

Kurt Gold
Community Expert
Community Expert
May 18, 2022

I understand.

 

The reason, however, why I'm asking for sample files is not because I (or someone else) may just want to see and create a possibly instant solution for just the specific sample files. No, the main reason is because it is almost always useful and helpful to inspect real files. This way, one can, for instance, exclude certain improbable, though possible scenarios like quadruple or quintuple nested constructions with different transparencies at different object levels. And perhaps the files do not contain as many extremely nested appearances as one may assume sometimes. Who knows?

 

As already mentioned, I can imagine some ways to solve or partially solve your task with some built-in procedures. However, if it is difficult or impossible for you to share a couple of sample Illustrator files, I'm afraid you will have to look out for some other ways to ease the issues.


I am sorry, but without sample files I will not follow up the matter.

 

Inspiring
May 14, 2022

Huh?

Kurt Gold
Community Expert
Community Expert
May 14, 2022

tomr,

 

I'm not quite sure about your "Huh?" message and don't get what the animation is actually supposed to show and mean.

 

Also, I'm not sure if you understood the possible issues in this context. At least I don't think that a (basically useful) plugin - one that you obviously do recommend - can help when it comes to nested instances of transparency inside type objects that Raymond mentioned.

 

Inspiring
May 14, 2022

The context is quite simple: that guy has issues with effects and transparencies. He can fix effects issues with the plugin. But obviously he can't fix transparencies issues with the plugin.

Kurt Gold
Community Expert
Community Expert
May 14, 2022

You may provide one of the rather complex Illustrator files for inspection.

 

Perhaps there are some other ways without using scripts.

 

pixxxelschubser
Community Expert
Community Expert
May 14, 2022

Hi @femkeblanco 

in theory this seems to be a solution.

 

I tried something similar in the past.

 

But it will only works for a small test file with only a few items. Try it with a "normal" file with thousands of paths, nested groups, clipping masks, opacity masks, gradients with ramp stops which have transparency, layers with transparency or blend modes.

 

There are so many scenarios which will fail. And on the other side: because of the high amount of paths Illustrator probably seems to freeze and if it won't crash - the execution time will be absolutely unpracticable.

femkeblanco
Legend
May 14, 2022

@pixxxelschubser  I agree.  I just thought I'd throw it out there. 

femkeblanco
Legend
May 14, 2022

This is a basic idea for a function to test whether or not a path item has an effect or transparency.

// select path item
alert(test(app.selection[0]));

function test (path1) {
    var path2 = path1.duplicate();
    app.selection = null;
    path2.selected = true;
    app.executeMenuCommand("expandStyle");
    var hypothesis = app.selection[0].typename;
    app.selection[0].remove();
    return hypothesis == "GroupItem";
}
Inspiring
May 17, 2022

Hi, @femkeblanco 

 

Where is the "expandStyle" command from illustrator menu?

Can you briefly explain the meaning of this script? Maybe it can't completely solve the problem, but maybe I can get some inspiration from it, because I'm a novice for JS. Thank you!

femkeblanco
femkeblancoCorrect answer
Legend
May 17, 2022

@Raymond ZJH  "expandStyle" corresponds to Object > Expand Appearance in the menu bar. Expand Appearance, as the name implies, expands the appearance of a path with an appearance attribute (effect or transparency), producing a group (representing the stroke and the fill). The script tests whether or not a path's appearance is expandable.

 

The script works as follows:  You're asked to select a path. This path is duplicated. The duplicate is selected. Expand Appearance is invoked. At this point, if the item which is selected is a group, the path's appearance is expandable, i.e. there is an effect or transparency. In the end, the duplicate is removed.

 

The script has it's drawbacks. First is runtime, as @pixxxelschubser  points out. This is particularly relevant if you want to test nested items, which will add (probably unmanageable) complexity to an already sluggish script. Second, if a path has either a stroke or a fill but not both, expanding appearance will not produce a group. Odd effects will also not produce a group, giving a false negative.

 

On a positive note, a similar approach has worked for my needs in the past. 

pixxxelschubser
Community Expert
Community Expert
May 14, 2022

As I wrote before: However, you cannot read these attributes.

Sorry

pixxxelschubser
Community Expert
Community Expert
May 13, 2022

After re-reading your post: do you want to set the attributes or read them?


There is a workaround for setting such attributes. Apply an existing graphic style with these attributes.

However, you cannot read these attributes.

Inspiring
May 14, 2022

Thanks  @pixxxelschubser 

 

I want to find out these object elements with effects (including opacity) applied, and then cancel these effects. If there is no script method to cancel these effects, I can move them to the same layer, and then manually execute the "clear appearance" command of the appearance panel (this is a compromise, if the script cannot be completed at one time), But the premise of doing this is to be able to identify these object elements with effects applied (the effects applied are not all the same. If they are the same, I can use the "select the same appearance" command). So I hope the script hava an attribute(Boolean Value). When the effect is applied, the value is True, otherwise it is False.
Because a file includes many, many object elements, if I manually search one by one, it is a very crazy , and the search is not comprehensive...

pixxxelschubser
Community Expert
Community Expert
May 13, 2022

No.

Unfortunately, we have no access to the appearance palette.

 

(I hope one day someone can tell us something more encouraging.)