├── .gitignore ├── HelloWorld.py ├── README.md ├── api_reference ├── illustrator_2020.py ├── illustrator_2021.py ├── illustrator_CC_2018.py └── illustrator_CC_2019.py └── interop assemblies ├── Interop.Illustrator.2020.dll ├── Interop.Illustrator.cc2019.dll └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .git 2 | .idea 3 | env 4 | pscc2018.pyc 5 | my-test.py 6 | .DS_Store 7 | 8 | # Default stuff for Github, Python 9 | # Byte-compiled / optimized / DLL files 10 | __pycache__/ 11 | *.py[cod] 12 | 13 | # C extensions 14 | *.so 15 | 16 | # Distribution / packaging 17 | .Python 18 | env/ 19 | build/ 20 | develop-eggs/ 21 | dist/ 22 | downloads/ 23 | eggs/ 24 | .eggs/ 25 | lib/ 26 | lib64/ 27 | parts/ 28 | sdist/ 29 | var/ 30 | *.egg-info/ 31 | .installed.cfg 32 | *.egg 33 | 34 | # PyInstaller 35 | # Usually these files are written by a python script from a template 36 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 37 | *.manifest 38 | *.spec 39 | 40 | # Installer logs 41 | pip-log.txt 42 | pip-delete-this-directory.txt 43 | 44 | # Unit test / coverage reports 45 | htmlcov/ 46 | .tox/ 47 | .coverage 48 | .coverage.* 49 | .cache 50 | nosetests.xml 51 | coverage.xml 52 | *,cover 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | 61 | # Sphinx documentation 62 | docs/_build/ 63 | 64 | # PyBuilder 65 | target/ -------------------------------------------------------------------------------- /HelloWorld.py: -------------------------------------------------------------------------------- 1 | # Classic Hello World example 2 | 3 | from win32com.client import Dispatch, GetActiveObject, GetObject 4 | 5 | # Start up an Illustrator application 6 | # app = Dispatch('Photoshop.Application') 7 | 8 | # Or get Reference to already running Illustrator application instance 9 | app = GetActiveObject("Illustrator.Application") 10 | 11 | docRef = app.Documents.Add() 12 | rectRef = docRef.PathItems.Rectangle(700, 50, 100, 100) 13 | areaTextRef = docRef.TextFrames.AreaText(rectRef) 14 | areaTextRef.Contents = "Hello World!" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WIP (More code snippets coming soon....!) 2 | 3 | 4 | 5 | # Illustrator Scripting in Python 6 | ![](https://i.imgur.com/1qe9LVk.png "Illustrator Python") 7 | 8 | Scripting in Illustrator is used to automate repetitive tasks and are often used as a creative tool to streamline tasks that might be too time consuming to do manually. For example, you could write a script to generate a number of localized versions of a particular image or to gather information about the various color profiles used by a collection of images. 9 | 10 | # Illustrator COM & DOM 11 | Illustrator can be scripted through COM(Component Object Model). Its DOM(Document Object Model) is the same when accessing it through either its own JavaScript engine or Python or any other scripting language it supports. The Illustrator DOM consists of a hierarchical representation of the Illustrator application, the documents used in it, and the components of the documents. The DOM allows you to programmatically access and manipulate the Artboard and its components. For example, through the DOM, you can create 12 | a new document, add a layer to an existing document, or change the background color of a layer. Most of 13 | the functionality available through the Illustrator user interface is available through the DOM. 14 | 15 | # But why Python? 16 | Illustrator scripting officially supports JavaScript, AppleScript & VBScript. However, scripting in Python is also fairly easy if not easier if you're already comfortable with Python. You may have already heard that Python is gaining in popularity, but did you know it’s now the most popular introductory programming language in U.S. universities? Python is also cross platform just like JavaScript is and lately becoming one of the fastest growing programming language according to StackOverflow [as of 2017](https://stackoverflow.blog/2017/09/06/incredible-growth-python) / [as of 2019](https://insights.stackoverflow.com/survey/2019#key-results) 17 | 18 | Python is easy to use, powerful, and versatile, making it a great choice for beginners and experts alike. Python’s readability makes it a great first programming language - it allows you to think like a programmer and not waste time understanding the mysterious syntax that other programming languages can require. 19 | 20 | # Getting Started 21 | Python allows you to access COM and it's DOM with the help of a Python extensions like "pypiwin32" or "comtypes". Install these modules and you're ready to start scripting Illustrator in Python 22 | 23 | * `pip install pypiwin32` or `pip install comtypes` 24 | 25 | # Hello World! 26 | ```python 27 | from win32com.client import GetActiveObject 28 | 29 | app = GetActiveObject("Illustrator.Application") 30 | docRef = app.Documents.Add() 31 | rectRef = docRef.PathItems.Rectangle(700, 50, 100, 100) 32 | areaTextRef = docRef.TextFrames.AreaText(rectRef) 33 | areaTextRef.Contents = "Hello World!" 34 | ``` 35 | # How to inspect scripting object properties? 36 | There's not a straight forward way, you need to read the documentation to understand what properties/attributes are available for a scripting object, or possibly a COM browser. For example, I've extracted the Python scripting object reference for Illustrator CC 2018 at [api_reference](https://github.com/lohriialo/illustrator-scripting-python/tree/master/api_reference) 37 | 38 | # Scripting on Mac? 39 | Yes, scripting on Mac is also possible, see [photoshop_mac_scripting](https://github.com/lohriialo/photoshop-scripting-python/tree/master/mac_scripting) for more details as a reference to getting started 40 | 41 | # Illustrator Scripting Resources 42 | * [Illustrator Scripting Resources](https://console.adobe.io/downloads/ai) 43 | * [Illustrator Scripting Guide](https://d1g4ig3mxc5xed.cloudfront.net/static/installers/ai/scripting/cc_2018/scripting_guide/ScriptingGuide_March2018.pdf) 44 | * [Illustrator Scripting Developer Forum](https://forums.adobe.com/community/illustrator/illustrator_scripting) 45 | * [Illustrator Scripting Javascript API Reference](https://d1g4ig3mxc5xed.cloudfront.net/installers/ai/scripting/cc_2018/web/v2/Illustrator+JavaScript+Scripting+Reference_March2018.pdf) 46 | * [Illustrator Scripting Javascript Tutorials](https://github.com/jtnimoy/scripting-for-illustrator-tutorial) 47 | 48 | # Also see 49 | * [InDesign Scripting in Python](https://github.com/lohriialo/indesign-scripting-python) 50 | * [Photoshop Scripting in Python](https://github.com/lohriialo/photoshop-scripting-python) 51 | 52 | # Contribution 53 | If you've written a useful Illustrator Python script and wants to share with the world, please create a new issue with the file as an attachment to the issue. 54 | 55 | When you submit a script, please try to include the following information at the start of your script 56 | ```python 57 | # script_file_name.py 58 | 59 | # Created: 1st January 2019 60 | __author__ = 'Your Name or Original Author Name' 61 | __version__ = '1.0' 62 | 63 | """ 64 | A short description of what the script does 65 | """ 66 | 67 | """ 68 | Instructions on how to use the script, if any 69 | """ 70 | 71 | ``` 72 | * Go to [illustrator-scripting-python/issues/new](https://github.com/lohriialo/illustrator-scripting-python/issues/new) 73 | * Add title as `Useful Script` 74 | * Drag & drop your .py script file into the description area 75 | * Click `Submit new issue` 76 | -------------------------------------------------------------------------------- /interop assemblies/Interop.Illustrator.2020.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lohriialo/illustrator-scripting-python/3295f6a5682d30f14eafd42ed3ac6f820a1b2714/interop assemblies/Interop.Illustrator.2020.dll -------------------------------------------------------------------------------- /interop assemblies/Interop.Illustrator.cc2019.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lohriialo/illustrator-scripting-python/3295f6a5682d30f14eafd42ed3ac6f820a1b2714/interop assemblies/Interop.Illustrator.cc2019.dll -------------------------------------------------------------------------------- /interop assemblies/README.md: -------------------------------------------------------------------------------- 1 | These Interop DLLs here are provided as examples for scripting in C# For more information on how to generate Interop DLLs, see https://docs.microsoft.com/en-us/dotnet/framework/interop/how-to-generate-interop-assemblies-from-type-libraries 2 | --------------------------------------------------------------------------------