Skip to main content
Inspiring
April 4, 2025
Answered

Place SVG via script

  • April 4, 2025
  • 1 reply
  • 380 views

I have a script I have used to place Illustrator art inside of other open documents. It places them at the coordinates in the code. I have come up with the need to place dynamically created SVG files into Illustrator documents. When I try to use the script for placing SVG, it does not work (gives a bunch of errors). I can manually place the SVG file into Illustrator. However, I cannot have the position predetermined as the script can do. When I place the SVG, it is only the art, not any artboard or bounding area like the Illustrator (.ai) file. This works well for my application now. If there is any way to do it, I would like to find out. Thanks

 

var doc = app.activeDocument;

// Replace this with your actual file path 
var filePath = new File("C:/Test/data1990.svg"); 

if (filePath.exists) {
    var placedItem = doc.placedItems.add();
    placedItem.file = filePath;  // Assign file to placed item
    placedItem.position = [100, 200]; // X = 100, Y = 200 (Adjust as needed)
} else {
    alert("Error: File not found! Check the file path.");
}

 

 

Correct answer renél80416020

Il faut utiliser

var placedItem = doc.groupItems.createFromFile( filePath );

1 reply

renél80416020
renél80416020Correct answer
Inspiring
April 4, 2025

Il faut utiliser

var placedItem = doc.groupItems.createFromFile( filePath );
Inspiring
April 7, 2025

Merci beaucoup, c'était super utile 😊