| 1 | # 02_Text.py |
| 2 | |
| 3 | # You can query text from any open tab through the Python API |
| 4 | q.loadDocument("02_Text.py") |
| 5 | text = q.getFullText() |
| 6 | |
| 7 | # This will print the number 4 on the Python Console, |
| 8 | # which is where you will see output from Python commands |
| 9 | index = text.index('_Text') |
| 10 | print('Position of "_T":', index) |
| 11 | |
| 12 | # Now we will load a csd file and look at its orchestra and score |
| 13 | # Notice that paths are relative to the python file being executed |
| 14 | # or the currently open document if only executing sections |
| 15 | q.loadDocument("basic.csd") |
| 16 | text = q.getFullText() |
| 17 | orc = q.getOrc() |
| 18 | sco = q.getSco() |
| 19 | |
| 20 | index1 = text.index('instr 1') |
| 21 | index2 = orc.index('instr 1') |
| 22 | print('"instr 1" in text and orc:', index1, index2) |
| 23 | |
| 24 | print("Score is: ", sco) |
| 25 | |
| 26 | # Make sure this is visible after running the script |
| 27 | q.loadDocument("02_Text.py") # This will switch back to this file |
| 28 | |
| 29 | # You can also call these functions for other tabs: |
| 30 | doc = q.getDocument("basic.csd") # get document index without switching to it |
| 31 | sco = q.getSco(doc) # Will get the score, even though this file is currently selected! |
| 32 | |
| 33 | print("Score from other file: ", sco) |