Link in Zwischenablage kopieren
Kopiert
I am not very clear about the current selection object and its hierarchical relationships, especially the representation of the parent level. Could someone clarify these relationships?
For example:
Situation 1: When the cursor is outside the table
A. When the cursor is in a paragraph with no selection, sel[j] is the entire paragraph.
B. If part of the text is selected, sel[j] is the selected text. (This includes selecting all text within the text box.)
C. If the text box is selected, sel[j] is all content within the text box (including images, text, and tables).
Situation 2: When the cursor is inside a table
D. If the cursor is within a cell, sel[j] is the current cell.
E. If multiple cells are selected via drag, sel[j] is the selected cells.
F. If the entire table is selected, sel[j] is the entire table.
Thank you very much.
You can get the parents of a selection like this— a selected word in a table cell
var sp = app.documents[0].selection[0]
alert("\n" + sp.constructor.name + "\n" + sp.parent.constructor.name+ "\n" + sp.parent.parent.constructor.name+ "\n" + sp.parent.parent.parent.constructor.name+ "\n" + sp.parent.parent.parent.parent.constructor.name)
If you have multiple cells selected the following will give you text of the cells
app.selection[0].cells.everyItem().contents
If you have some text selected which is outside the table and have the table selected as well. then the following will get you contents of all the cells in the selected table
app.selection[0].tables.everyItem().cells.everyItem().contents
If the extire frame is selected then the following would work
app.selection[0].tables.everyItem().cells.everyItem().contents
-Manan
Link in Zwischenablage kopieren
Kopiert
When the cursor is in a text within or outside the table without any selection then it is insertionPoint. What you can do is make different selections with whatever use case you want and then run the following code
alert(app.selection[0].constructor.name)
-Manan
Link in Zwischenablage kopieren
Kopiert
For example, how do you indicate the entire paragraph where the cursor is located?
Link in Zwischenablage kopieren
Kopiert
app.selection[0].paragraphs[0].contents
Should give you the paragraph where the current cursor is placed
-Manan
Link in Zwischenablage kopieren
Kopiert
What you mentioned above should be selecting some text.
When I want to indicate the entire paragraph, the cursor is only on the line and nothing is selected.
Link in Zwischenablage kopieren
Kopiert
cursor is only on the line and nothing is selected
If you want to change the selection to the paragraph containing an insersion point it would be this:
//a selected insertion point
var sel = app.documents[0].selection[0];
//select the insertion point’s paragraph
app.select(sel.paragraphs[0], SelectionOptions.replaceWith)
Link in Zwischenablage kopieren
Kopiert
It really became selected.
Perhaps so, but I just wanted to convert the target to the entire segment, and I thought I had to use parent to indicate that.
I actually wanted to clear the preferred options based on different situations.
I'm starting to doubt my idea...
Link in Zwischenablage kopieren
Kopiert
This changes the properties of the insertion point’s paragraph
//the paragraph the insertion point is in
var sp = app.documents[0].selection[0].paragraphs[0];
//change the properties of the selection’s paragraph
sp.properties = {pointSize:15, leading:20, fillTint:40}
Link in Zwischenablage kopieren
Kopiert
I mainly want to use a script to implement multiple functions.
Determine the operation object based on the cursor status.
So I want to know how to determine the cursor status and how to convert to the target.
Take clearing overtype as an example.
If the cursor is in a cell, clear the overtype of the current cell.
If I select some cells, clear the overtype of those cells.
If I select the entire text box, clear all text in the text box and all overtype in all tables.
Is it like setting a shortcut key to clear overtype?
It seems that this is not entirely the case.
I don't have to worry about whether the current selection matches.
Any possible selection target has the corresponding operation ready.
Link in Zwischenablage kopieren
Kopiert
You can get the parents of a selection like this— a selected word in a table cell
var sp = app.documents[0].selection[0]
alert("\n" + sp.constructor.name + "\n" + sp.parent.constructor.name+ "\n" + sp.parent.parent.constructor.name+ "\n" + sp.parent.parent.parent.constructor.name+ "\n" + sp.parent.parent.parent.parent.constructor.name)
Link in Zwischenablage kopieren
Kopiert
If I drag and select several cells, how do I get the text content?
If I select text and tables outside the table, how do I get the text in the cells?
Sunil Yadav wrote this before, and it is also invincible.
I don't know why there are two text[0].text[0]
Occasionally, it may fail.
obj.texts[0].tables.everyItem().cells.everyItem().texts[0].texts[0].appliedParagraphStyle = "myTabBodyPar";
If I select the entire text Frame, how can I retrieve the text in the cell?
Link in Zwischenablage kopieren
Kopiert
If you have multiple cells selected the following will give you text of the cells
app.selection[0].cells.everyItem().contents
If you have some text selected which is outside the table and have the table selected as well. then the following will get you contents of all the cells in the selected table
app.selection[0].tables.everyItem().cells.everyItem().contents
If the extire frame is selected then the following would work
app.selection[0].tables.everyItem().cells.everyItem().contents
-Manan
Link in Zwischenablage kopieren
Kopiert
HI
The rest basically worked.
But this seems wrong. I only want to change the currently selected "te666xt b", not "chose".
The constructor.name here also seems uncertain. It could be Text, Word, Character, all numbers, or TextStyleRange.
My target audience seems to be wrong.
alert(app.selection[0].constructor.name);
if (app.selection[0].constructor.name == "Text") {
selWord();
}
function selWord() {
app.selection[0].texts[0].appliedParagraphStyle = parStn;
}
What is TextStyleRange? TextStyleRange? It's not called "number"?
Link in Zwischenablage kopieren
Kopiert
The constructor.name here also seems uncertain.
You have more than a word and less than a paragraph selected so its constructor name is Text
The constructor name depends on what is selected:
alert(sp.constructor.name)
Link in Zwischenablage kopieren
Kopiert
I also feel that the code is repetitive and verbose. Can we represent the target object using parameters?
selTextFrame():
function selTextFrame() {app.selection[0].tables.everyItem().cells.everyItem().texts[0].appliedParagraphStyle = bodyParStn;
}
I also want to change it to the following, so that several possibilities can share one function: General, It seems like it won't work.
selGeneral(app.selection[0].tables.everyItem().cells.everyItem().texts[0],ps);
function selTextFrame(tg,ps) {
tg.appliedParagraphStyle = ps;
}
Link in Zwischenablage kopieren
Kopiert
You will run into problems if you assume the selection includes a table. If I wrap the selection in a try statement :
try {
alert(app.selection[0].tables.everyItem().cells.everyItem().texts[0])
}catch(e) {
alert(e)
}
Link in Zwischenablage kopieren
Kopiert
No, everything is normal.
if (app.selection[0].constructor.name == "Cell") {
selCells();
}
function selCells(){
app.selection[0].tables.everyItem().cells.everyItem().appliedCellStyle = bodyStn;
}
Link in Zwischenablage kopieren
Kopiert
Thank you very much, both of you.
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen