Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to inspect AI object properties? #1

Closed
GlassGruber opened this issue Aug 18, 2018 · 2 comments
Closed

How to inspect AI object properties? #1

GlassGruber opened this issue Aug 18, 2018 · 2 comments
Labels
question Further information is requested

Comments

@GlassGruber
Copy link

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!

@lohriialo
Copy link
Owner

There's not a straight forward way, have 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 doc_reference

Example: app.Documents object has properties like Add AddDocument AddDocumentWithDialogOption Arrange Index Item

@lohriialo lohriialo added the question Further information is requested label Aug 23, 2018
@GlassGruber
Copy link
Author

GlassGruber commented Aug 30, 2018

Thanks a lot for your answer and sorry for the very late reply.

I've searched a bit and found that basically what you say is true, but there are margin of improvements based on the working setup. For example this definition will ensure that the client object will generate a library file that will be used as a reference:

import win32com.client
# Get the Application object and ensure there is a library file generated 
# via makepy.py from win32com with COM class definitions and methods
APP = win32com.client.gencache.EnsureDispatch("InDesign.Application")

This way the autocomplete mechanism should find the methods available for the object.

Unfortunately normal autocomplete mechanisms won't display the properties of the object, buried inside the _prop_map_get_ dict.

Related to this, I found a nice addition for IPython allowing auto complete for objects too.

# from https://stackoverflow.com/a/47613008/1262357
from IPython.utils.generics import complete_object

@complete_object.when_type(win32com.client.DispatchBaseClass)
def complete_dispatch_base_class(obj, prev_completions):
    try:
        ole_props = set(obj._prop_map_get_).union(set(obj._prop_map_put_))
        return list(ole_props) + prev_completions
    except AttributeError:
        pass

Hope this can be useful, and that some one can improve and suggest more on this matter!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants