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

Script to automatically replace specific layer?

New Here ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

Hello. I work for a small company and we frequently get client AI files that we need to edit. Because of the way thay're formatted the layers always come in with the same name/structure, but they always have a layer that we need to replace. We have to go into a shared drive and manually place our desired item (a .pdf file if it's of importance) in the subset layer to continue with the file. So for example, there will be a layer in the default file named Layer 1, and in that layer is group 1 > group > Clipping Mask and Image.

I know ideally we should just fix the scripting that formats the layers, but for now that's not possible. So, what I'd like to be able to do (assuming it's even possible) is have a script that we can run that will automatically replace the 'Image' file in those subset layers I mentioned with a file from a location on a local machine (i.e. replace Layer 1>group 1>group>image.jpg with C:/example/example.pdf).

I searched online and couldn't find anything, so I figured I'd turn to the community for help. Any input, suggestions or creative workarounds would be greatly appreciated! And as always, thanks ahead of time, everyone on these forums is usually very nice and awesome, so it's always nice to come here for help.

TOPICS
Scripting

Views

1.3K

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

Engaged , Dec 13, 2013 Dec 13, 2013

Glad to see you agreed to take up the challenge.

Well, this should get you started. Keep in mind, it's written in VB.NET so you will have to translate it is you want it in Javascript. At least you'll have a template to start with. This is just a fast hack for you to start with - you may have to tweak the layer that you want the new image to appear on, if it's important. Also, it is assumed that you started with a Raster item (image.jpg) and that you wanted the new image to be embedded. You'll se

...

Votes

Translate

Translate
Adobe
Engaged ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

Hi mrbusto712,

At first glance, it sounds pretty straight forward. Do you have anything started yet in your script in particular with which you are having problems that we can help you with? A little more explicit info on exactly what the layers and sublayers look like would be helpful so that I could further qualify my first sentence.

-TT

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
New Here ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

Thanks for the response! I don't have anything started as I was actually hoping there may be a script already written that I could use somewhere but wasn't able to find. I know next to nothing about scripting though I can usually make pre-written scripts work based on my limited HTML knowledge and trial/error.

As for the layer info, the layers we deal with appear as follows (each - denotes a new layer within the layer above it):

layer 1

- group

  - group

     clipping path

     - group

        clipping path

        image.jpg

We have to manually go into these and replace the image .jpg with example.pdf each time, and though it's not a huge deal it'd just be nice to map a script to a function key and hit a button that'd tell AI to automatically replace image.jpg in those groups/layers with example.pdf from a location on a local machine.

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
Engaged ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

I'm not aware of any pre-written scripts that will do exactly what you need, although there may well be. Typically, this forum tries to assist those creating new scripts or modify existing scripts, as stated in the Forum preamble, under "Useful information and links". See http://forums.adobe.com/community/illustrator/illustrator_scripting and in the yellow box there are some excellent links to assist you. You may be surprised how quickly you'll pick it up.

Having said that, I'd be happy to help assist you if you still want to pursue this and participate in the development. A few thoughts come to my mind. 1) the image that needs to be replaced: does it have a consistent name? or is it always on a particular layer/sublayer? in other words, how do we identify it? I assume thath there are more than one image.

Once the image is identified, the fix could be something as easy as:
  item.name = "//NETMACHINE/YourNewFile.pdf"

Obviously a bit oversimplified, but it is doable.

Why not give it a go?

Hope this helps.

-TT

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
New Here ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

Thanks! I'll try to dig through the links there and see if I can make heads or tails of any of the information to get started.

In the mean time, to address your question, the image that needs to be replaced and the pdf replacing it are always named the same thing (e.g. image.jpg or example.pdf every time). The image being replaced is also always in the same sublayer as listed above (I actually listed it exactly how it looks in AI, so it shows up that way each time).

Thanks again for the help!

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
Engaged ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

Glad to see you agreed to take up the challenge.

Well, this should get you started. Keep in mind, it's written in VB.NET so you will have to translate it is you want it in Javascript. At least you'll have a template to start with. This is just a fast hack for you to start with - you may have to tweak the layer that you want the new image to appear on, if it's important. Also, it is assumed that you started with a Raster item (image.jpg) and that you wanted the new image to be embedded. You'll see the code so tweak as you like.

Dim app As Illustrator.Application = CreateObject("Illustrator.Application")

Dim aDoc As AI.Document = app.ActiveDocument

For Each item In aDoc.RasterItems

If item.Name = "image.jpg" Then

  item.Selected = True

  Dim newPlacedItem As AI.PlacedItem = aDoc.PlacedItems.Add

  newPlacedItem.File = "YourNewFilePathHere.pdf"

  newPlacedItem.Embed()

  item.Delete()

End If

Next

Hope this helps.

-TT

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
New Here ,
Dec 13, 2013 Dec 13, 2013

Copy link to clipboard

Copied

LATEST

Thanks so much! I'll take some of what I learned from that Illustrator scripting PDF and try to play around with what you have and see what I can learn and do. Thanks again for all your help, I really appreciate it.

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