Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

COM Automation Python: Creating documents for a specified unit

New Here ,
Nov 12, 2025 Nov 12, 2025


Hello everyone,

I'm currently working on automating tasks in Adobe Illustrator using Python's win32com.client library. I've successfully connected to the running Illustrator application using:

python
app = win32com.client.GetActiveObject("Illustrator.Application")

My goal is to create a new document with a specific ruler unit (e.g., Millimeters) at the time of creation using app.Documents.Add().

However, I'm facing a challenge:

1. Unknown Parameter List: I cannot find comprehensive, up-to-date documentation that clearly lists all the parameters and their corresponding values for the Add() method when using win32com. The official scripting guide primarily covers ExtendScript (JavaScript), which has different syntax.
2. Parameter Value Discrepancy: I suspect that the parameter constants used in win32com might differ from those used in JavaScript (JSX). For example, in JSX, you might use app.documents.add().rulerUnits = Units.MILLIMETERS;, but I need to know what integer value or constant name corresponds to "Millimeters" in the win32com Add() call.

Specifically, I'm trying to understand how to set the unit correctly within this call:
python
doc = app.Documents.Add(?, ?, ?, ?, ?, ?, ?, ?)

What are the correct values to pass for the Units parameter? Is it 1 for Millimeters, like some internal file data suggests? And what about the other optional parameters?

I've tried searching online and looking at the win32com.client.constants module, but haven't found a definitive answer.

Could anyone who has experience with Python COM automation for Illustrator please help clarify the exact parameters and their values for Documents.Add()? Any guidance or code examples would be greatly appreciated!

Thank you in advance for your help and expertise!

TOPICS
Draw and design , Scripting
146
Translate
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

Community Expert , Nov 19, 2025 Nov 19, 2025

good to hear you found out you can execute javascript via COM

 

go to the Developer Console to download the official vbscript reference. Sign in with your adobe id

https://developer.adobe.com/console/80148/servicesandapis/ai

Translate
Adobe
Community Expert ,
Nov 16, 2025 Nov 16, 2025

@ob_default46715138 because it's been a few days since you posted, you may want to try a 'Reddit Illustrator forum' 

Translate
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
Community Expert ,
Nov 17, 2025 Nov 17, 2025

I think the parameters should be the same as vbscript but don't quote me on this

 

however, documents.Add() doesn't take a Units paramenter, AddDocument() function does

 

AddDocument
(startupPreset as String
[, presetSettings as DocumentPreset]
[, showOptionsDialog as Boolean)

 

DocumentPreset Object has a lot of properties you can set, including DocumentUnits

aiUnitsCM = 3
aiUnitsInches = 2
aiUnitsMM = 6
aiUnitsPicas = 5
aiUnitsPoints = 4
aiUnitsQ = 7
aiUnitsPixels = 8
aiUnitsUnknown = 1

 

check the vbscript Reference for more info

 

 

 

 

Translate
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
New Here ,
Nov 19, 2025 Nov 19, 2025

Thank you for your help.  

 

create_a4_doc = """
    var preset = new DocumentPreset;
    preset.width = 210.0;
    preset.units = RulerUnits.Millimeters;
    preset.height = 297.0;
    preset.colorMode = DocumentColorSpace.RGB;
    app.documents.addDocument("A4",preset);
"""
app.DoJavaScript(create_a4_doc)
I can find the address of the ai-scripting documentation. 
The address is  
I can also achieve this using Python + Scripting.
 
Translate
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
Community Expert ,
Nov 19, 2025 Nov 19, 2025
LATEST

good to hear you found out you can execute javascript via COM

 

go to the Developer Console to download the official vbscript reference. Sign in with your adobe id

https://developer.adobe.com/console/80148/servicesandapis/ai

Translate
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