Examples¶
This section provides some general examples on how to use the priint comet Python API.
Reflection¶
Reflect all comet members and output them to the logfile¶
#!py
#pragma plain
import inspect
import sys
import comet
def reflect(obj, depth: int = 0):
#reflect an object by inspecting all attributes and returning a summarizing string
message = ''
for name in dir(obj):
if name.startswith('_'):
continue
attr = getattr(obj, name)
for i in range(depth):
message += '\t'
message += '{} - {}\n'.format(name, attr)
if inspect.isclass(attr) or inspect.ismodule(attr):
message += reflect(attr, depth + 1)
return message
def reflectComet():
#do a full reflection of all comet members and produce a nice formatted output
message = 'Comet reflection:\n'
host = comet.host.getType()
if host == 0:
message += "Running in InDesign\n"
if host == 1:
message += "Running in InDesign Server\n"
if host == 2:
message += "Running in comet_pdf\n"
if host == 3:
message += "Running in Illustrator\n"
message += reflect(comet)
comet.wlog(message)
def main():
reflectComet()
return 0