VBA code to place image in AI

Explorer ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

Hi, I am trying to place objects (some img files) in an illustrator file, using VBA/excel.

filePath = ActiveWorkbook.Path
Set appRef = CreateObject("Illustrator.Application")
Set docRef = appRef.Open(filePath & "\test.AI")
Set placedItem = docRef.placedItems.Add()
'placedItem.File = File("\test.png")

 

The code up to appRef.Open(path) works - it opens the illustrator file.
But I cannot figure out how to use placeditems.Add(), or whatever necessary to place the image.

 

TOPICS
Scripting

Views

78

Likes

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

Adobe Community Professional , Feb 28, 2022 Feb 28, 2022
for svg and probably dxf, use the Group's CreateFromFile method Set igroup = docRef.GroupItems.CreateFromFile("C:/Users/Canto/full path to your file.svg")

Likes

Translate

Translate
Explorer ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

This code works:

Dim filePath As String
filePath = ActiveWorkbook.Path
Set appRef = CreateObject("Illustrator.Application")
Set docRef = appRef.Open(filePath & "\5x10_NEW.AI")
Set placedItem = docRef.placedItems.Add()
placedItem.File() = filePath & "\_QR\123.jpg"

 

Now I have a problem placing .svg graphics.

I am trying to automate a very tedious task of manually placing a lot of different .svg files.
I do that manually (file/place/.svg images), but when I use placedItems.Add(), there is an error, that the format cannot be accepted 😞

Likes

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
Explorer ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

Cannot work with .dxf as well.
It works ok when I place .dxf manually.

 

Could it be that it cannot work with vector graphics?
Mby I have to scale the graphics first to some dimensions?

Likes

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
Adobe Community Professional ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

for svg and probably dxf, use the Group's CreateFromFile method

 

Set igroup = docRef.GroupItems.CreateFromFile("C:/Users/Canto/full path to your file.svg")

Likes

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
Explorer ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

^^Thinks !!! It works !!!

Didn't read and search through the scripting manual: AI CC Scripting Reference: VBScript

- page 90

group_items_vbs.JPG
I was going to try some nasty workarounds, importing images, then trace, and so on....

Likes

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
Adobe Community Professional ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

LATEST
quoteI was going to try some nasty workarounds, importing images, then trace, and so on....

By @emosms

 

ouch!! nasty! hahaha

Likes

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