lohriialo / illustrator-scripting-python Goto Github PK
View Code? Open in Web Editor NEWScripting in Illustrator is used to automate a wide variety of repetitive task or as complex as an entire new feature
Scripting in Illustrator is used to automate a wide variety of repetitive task or as complex as an entire new feature
Hey there,
first of all let me thank you for sharing this, along with ID and PS this information is extremely valuable!
I'm still a novice with Python, so maybe I'm asking something obvious and probably unrelated to this, but basically how can I inspect AI object properties and methods?
Picking from your Hello World
example:
app = GetActiveObject("Illustrator.Application")
docRef = app.Documents.Add()
Doing a basic dir
returns methods from the win32com.client.GetActiveObject
class, so how can I get the details of the app.Documents
object for example?
I don't know much (nothing probably is more appropriate) about the whole .NET/COM structure, Googling around I found that is not something easy to achieve, so I was wondering also what is your workflow and dev setup for scripting.
Thank you!
I don't understand the reference to saving the file as a multipage pdf.
How would I go about adding images using this?
Also, when I attempt to add a fillColor (on a rectangle like you made in the hello world tutorial) I get the error: TypeError: Cannot put <win32com.gen_py.None.CMYKColor> in VARIANT
would you be able to provide examples for these things?
Cheers
Hello,
First off, thank you so much for working on this project and enabling us to do so much more with Illustrator outside of its Javascript engine. I am using it to create a script to assist with sticker sheet creation and other large format printing needs.
I have had issues when trying to send certain parameters to Illustrator through a method call. Most variable types work, but when I try to send an object, I get this error:
doc.SaveAs(infotech, saveOpts)
File "c:\Users\USERDIRECTORY\Documents\PythonLearning\IllustratorLibrary21.py", line 2017, in SaveAs
return self._oleobj_.InvokeTypes(1398161747, LCID, 1, (24, 0), ((8, 1), (12, 17)),SaveIn
TypeError: Objects of type 'type' can not be converted to a COM VARIANT`
"infotech" is a variable that I have my destination path saved to. This is how I build "saveOpts":
saveOpts = ai.PDFSaveOptions
saveOpts.Compatibility = 7
saveOpts.GenerateThumbnails = False
saveOpts.PreserveEditability = False
I cannot save the document to a PDF because I cannot send the PDFSaveOptions parameter without receiving this error. I have done my own research into the error and honestly a lot of it is over my head, but I believe I understand the basics of a COM environment and how Python may need to convert variables to different types in order to work with other software.
Some things I've found:
Any object or variable created via the illustrator-scripting-python API cannot be passed to Illustrator. For instance, to add a spot color swatch to the document and save it as a variable, you cannot use the API's method Swatches.Add(), as this will give you the same error I posted above. Instead, you must do App.ActiveDocument.Spots.Add(), then set the Name attribute of that spot, then loop through ActiveDocument.Swatches to find the name and save THAT result to a variable.
Example:
if swatchExists == False:
perfCut = doc.Spots.Add()
perfCut.Name = 'PerfCutContour'
perfCut.ColorType = 2
perfCut.Color.Black = 0
perfCut.Color.Magenta = 0
perfCut.Color.Cyan = 100
perfCut.Color.Yellow = 100
for c in doc.Swatches :
if c.Name == 'PerfCutContour' :
perfCutContour = c'
Originally I was trying to use Swatches.Add(), then set the "Spot" attribute of that swatch to the spot I've created in the example code above. Trying to set the Spot attribute never worked and only gave me the same conversion error that I posted at the top.
Other notes:
I was able to work around this problem by simply running a Javascript file from my Python script. I wanted to avoid JS as much as possible with this project but I think this solution is fine and has been working great for me in a production environment for almost 3 weeks. When ready to save, I use the code:
doc = app.ActiveDocument
destination = C:/Whatever/Filename/ToSaveTo.pdf
arguments = [doc, destination]
app.DoJavaScriptFile(jsSave, arguments)
As for the "jsSave" file, that is a .js file in the same directory as my script. The JS is as follows:
doc = arguments[0]
destination = arguments[1]
function saveAndClose(doc, dest) {
var saveName = new File(dest);
saveOpts = new PDFSaveOptions();
saveOpts.compatibility = PDFCompatibility.ACROBAT8;
saveOpts.generateThumbnails = false;
saveOpts.preserveEditability = false;
doc.saveAs(saveName, saveOpts);
doc.close();
}
saveAndClose(doc, destination)
Hi there! I came across your repo and thought you might like to add my tutorial to the list. I made it a few years ago and am in the process of revisiting and updating it. Many thanks!
Hey, I stumbled upon your repo and tried to use it in a project. (https://github.com/SaadBazaz/auto-corona-graphics-generator) However, I need help in Exporting.
I'm using the direct Illustrator COM but there's no reference on how to Export.
In the API you've provided as well (illustrator_2020.py), there's a function:
Document.Export( )
But it contains an argument called "self" which I don't understand.
Any guidance would be appreciated.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.