Skip to main content
Inspiring
Apr 4, 2025 5:25 AM UTC
Answered

Place SVG via script

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.");
}

 

 

renél80416020
renél80416020Correct answer
Inspiring
Apr 4, 2025 10:13 AM UTC

Il faut utiliser

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

2 replies

renél80416020
renél80416020Correct answer
Inspiring
Apr 4, 2025 10:13 AM UTC

Il faut utiliser

var placedItem = doc.groupItems.createFromFile( filePath );
Translate
Inspiring
Apr 7, 2025 12:54 PM UTC

Merci beaucoup, c'était super utile 😊

Translate