-
Notifications
You must be signed in to change notification settings - Fork 26
/
Navigate.py
57 lines (44 loc) · 1.67 KB
/
Navigate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# NavigateDocument.py
# Created: 4/17/2020
__author__ = "CrudeRags"
__version__ = "1.1"
"""
Navigate a book, and its documents pagewise and storywise
"""
import win32com.client
import os
#Use your version of InDesign here
app = win32com.client.Dispatch('InDesign.Application.CC.2019')
idnPath = os.path.abspath(r"path_to_book")
bookPath = os.path.join(idnPath,'book_name.indb')
# ShowingWindow - option to show/hide what is opened.
app.Open(From = bookPath, ShowingWindow = False)
myBook = app.ActiveBook
# bookContents property gives access to bookContent object. The specific content has to opened separately
for doc in myBook.bookContents:
doc_name = doc.name
#Open document
myDoc = app.Open(From = doc.fullName, ShowingWindow=False)
#Get first story from document
doc_story = myDoc.Stories[0]
#Navigate a document page wise
for myPage in myDoc.Pages:
#Get the text frames in the page
for myFrame in myPage.TextFrames:
#Get Contents directly: Type = str
myContents = myFrame.Contents
#Get paragraphs in the text frame
for myPara in myFrame.Paragraphs:
#Get Paragraph style
print(myPara.appliedParagraphStyle)
# if str(myPara.appliedParagraphStyle) == "Basic Paragraph":
# do something
#Navigate a document storywise
for story in myDoc.Stories:
# print(story.Contents)
for para in story.Paragraphs:
#do stuff
para.Contents += "Hi there!"
#Get all the paragraph styles in the document
for style in myDoc.ParagraphStyles:
print(style)