- 1 year ago
Create and open Adobe Illustrator document from PowerShell
Comment
1 / 1
To create and open an Adobe Illustrator document from PowerShell, you can use the COM interface provided by Adobe Illustrator.
Here's an example PowerShell script that creates a new Illustrator document, adds some text to it, and saves it as an AI file:
ruby# Create an instance of Illustrator
$Illustrator = New-Object -ComObject Illustrator.Application
# Create a new document
$Document = $Illustrator.Documents.Add()
# Add some text to the document
$TextFrame = $Document.TextFrames.Add()
$TextFrame.Contents = "Hello, world!"
# Set the document's properties
$Document.Width = 400
$Document.Height = 400
# Save the document as an AI file
$FilePath = "C:\MyDocuments\MyIllustratorFile.ai"
$Document.SaveAs($FilePath, [Illustrator.AiFileFormat]::aiDocument)
# Close the document
$Document.Close()
# Open the AI file in Illustrator
$Illustrator.Open($FilePath)
# Release the Illustrator COM object
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($Illustrator) | Out-Null
This script does the following:
- Creates an instance of Illustrator using the
New-Object
cmdlet. - Creates a new Illustrator document using the
Documents.Add()
method. - Adds some text to the document using the
TextFrames.Add()
method. - Sets the document's properties using the
Width
andHeight
properties. - Saves the document as an AI file using the
SaveAs()
method. - Closes the document using the
Close()
method. - Opens the AI file in Illustrator using the
Open()
method. - Releases the Illustrator COM object using the
[System.Runtime.Interopservices.Marshal]::ReleaseComObject()
method.
Note that you may need to modify the file path and format in the SaveAs()
method to suit your needs. Also, make sure that Illustrator is installed on your system and that the COM interface is enabled.