Create and open Adobe Illustrator document from PowerShell

  • 1 year ago
Comment

ChatGPTChatGPT
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:

  1. Creates an instance of Illustrator using the New-Object cmdlet.
  2. Creates a new Illustrator document using the Documents.Add() method.
  3. Adds some text to the document using the TextFrames.Add() method.
  4. Sets the document's properties using the Width and Height properties.
  5. Saves the document as an AI file using the SaveAs() method.
  6. Closes the document using the Close() method.
  7. Opens the AI file in Illustrator using the Open() method.
  8. 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.