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

import a Graphic Style Library in Adobe Illustrator using Javascript?

Explorer ,
Jul 10, 2018 Jul 10, 2018

I am creating a script to distribute to users.

The package contains 1 script and a graphic style library that is required to apply a 3d effect in the script.

Is there a way to open the graphic style library from the script?

The script and library will both be located in the Adobe Illustrator Presets.

I am trying to reduce the amount of actions required by the user so that they only need to run the script without having to open the graphic style library first.

Below code occurs error: target layer cannot be modified

But no unvisible or locked layer

var style = app.activeDocument.graphicStyles.getByName("Jive_GS");

style.applyTo(myvector);

TOPICS
Scripting
2.0K
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
Valorous Hero ,
Jul 10, 2018 Jul 10, 2018

Unfortunately a script cannot simply import a graphic style library. As a work-around, take advantage of the Illustrator art handling abilities by keeping all your graphic styles attached to at least one art shape (each) in one .ai file. Then have your script open the file and duplicate the art into the user's previously-active document and close your new document. This will populate all of the graphic styles into the user document.

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 ,
Jul 10, 2018 Jul 10, 2018

Thanks for the help, very much appreciate it !

But can you provide real world code example for that please ? When I execute it, nothing happens.

var style = app.activeDocument.graphicStyles.getByName("Jive_GS");

style.applyTo(myvector);

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
Valorous Hero ,
Jul 10, 2018 Jul 10, 2018

What does your document structure look like when you are executing this? What is "myvector"? Your example looks like it should work just fine, provided there are necessary pre-conditions in place such as an open Ai document, a graphic style called "Jive_GS" inside it as well as some art in the document which would have the 'myvector' reference in the script somewhere above the snippet you pasted.

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 ,
Jul 10, 2018 Jul 10, 2018

thisPlacedItem = doc.groupItems.createFromFile(f);
var style = app.documents[1].graphicStyles.getByName("test22");

style.applyTo(thisPlacedItem);

This error happens: Error: Target layer cannot be modified

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
Valorous Hero ,
Jul 10, 2018 Jul 10, 2018

Not sure, but if your 'doc' isn't documents[1], and you are trying to put a style which exists in app.documents[1] into doc, first duplicate an art item with the style into the doc document. I think you have to duplicate it into a document's container, so use doc.layers[0] as the destination. Now that your item is in the document, the graphic style should be usable by the script next.


If that's not the solution, maybe check to make sure your top-most layer in your doc isn't hidden or locked. Perhaps the doc.groupItems.createFromFile is running into a problem due to hidden or locked layer where it is trying to create the item.

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 ,
Oct 12, 2018 Oct 12, 2018

Hello,

I'm really interresting with this features.

Can Illustrator team can add support for creating/editing/deleting graphic styles and/or aspect.

I need to apply a set of graphic styles on different layers. After applying styles, I want have possibility to update or change grphic styles in one click...

Please integrate this features.

Thanks

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
Community Expert ,
Oct 12, 2018 Oct 12, 2018
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 ,
Oct 18, 2018 Oct 18, 2018
LATEST

Thanks

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