Copy link to clipboard
Copied
I need a hint:
Prompts a message when no correct selection is made:
Please select an image frame.
Please select the text.
Please place the cursor in the frame
Please select the top two rows of the table.
Please place the cursor in the table row.
Thank you very much.
Hi @dublove have a look at this:
(function () {
var doc = app.activeDocument,
item = doc.selection[0];
if (!item)
alert('You have nothing selected.');
if ('Image' === item.constructor.name)
alert('You have selected a graphic.');
if (
item.hasOwnProperty('graphics')
&& 1 === item.graphics.length
)
alert('You have selected an image frame.');
if ('TextFrame' === item.constructor.name)
alert('You have selected a tex
...
Copy link to clipboard
Copied
Hi @dublove have a look at this:
(function () {
var doc = app.activeDocument,
item = doc.selection[0];
if (!item)
alert('You have nothing selected.');
if ('Image' === item.constructor.name)
alert('You have selected a graphic.');
if (
item.hasOwnProperty('graphics')
&& 1 === item.graphics.length
)
alert('You have selected an image frame.');
if ('TextFrame' === item.constructor.name)
alert('You have selected a text frame.');
if (
item.hasOwnProperty('texts')
&& 1 === item.texts.length
)
alert('You have selected something with text.');
if ('InsertionPoint' === item.constructor.name)
alert('Your cursor is in the text');
if (
'InsertionPoint' === item.constructor.name
&& 'Cell' === item.parent.constructor.name
)
alert('Your cursor is in a table row.');
if (
// table cell selections are always 'Cell'
'Cell' === item.constructor.name
// two rows
&& 2 === item.rows.length
// rows are first and second
&& 0 === item.rows[0].index
&& 1 === item.rows[1].index
// both whole rows are selected
&& item.cells.length == item.rows.everyItem().cells.length
)
alert('You have selected the top two rows of the table.');
})();
Copy link to clipboard
Copied
Hi m1b.
Thank you very much
Very useful reference for learning.
Copy link to clipboard
Copied
(Please select the top two rows of the table)
This sentence I have tabulated is not correct, it should read:
Please drag and drop from the first row to select one or more rows.
Copy link to clipboard
Copied
I tested it and found these problems.
The others are correct.
test();
function test() {
var doc = app.activeDocument,
item = doc.selection[0];
if ('Image' === item.constructor.name)
alert('You have selected a graphic.');
}
I have selected the image and run the script.
The alert doesn't pop up anything.
test();
function test() {
var doc = app.activeDocument,
item = doc.selection[0];
if (
item.hasOwnProperty('texts')
&& 1 === item.texts.length
)
alert('You have selected something with text.');
}
I have selected the text and run the script.
The alert does not pop up
test();
function test() {
var doc = app.activeDocument,
item = doc.selection[0];
if (
// table cell selections are always 'Cell'
'Cell' === item.constructor.name
// two rows
&& 2 === item.rows.length
// rows are first and second
&& 0 === item.rows[0].index
&& 1 === item.rows[1].index
// both whole rows are selected
&& item.cells.length == item.rows.everyItem().cells.length
)
alert('You have selected the top two rows of the table.');
}
No matter what you choose, this one doesn't pop up with a bail alert message either.
This one asked for it, and I initially indicated an error.
Now corrected:
is only a hint: you should drag and drop to select multiple rows from the first row.
(If you drag and drop the selection from another row, or just place the cursor in the row, this pops up as a hint: you should drag and drop from the first row to select the table header row. It doesn't matter how many rows you select)
If you didn't choose like this, prompt.
Copy link to clipboard
Copied
@dublove I don't understand any of your comments very well but I'll have a try
1. I don't know what "no hint" means here. Tell me when this doesn't work.
if ('Image' === item.constructor.name)
alert('You have selected a graphic.');
2. we can add a check to see if it is an insertion point only:
if (
(item.hasOwnProperty('texts')
&& 1 === item.texts.length)
|| 'InsertionPoint' === item.constructor.name
)
alert('You have selected something with text.');
3. Do you mean that you don't care if the whole row is selected... just any cell on both 1st and 2nd rows? If so, then just comment out the predicate for it:
if (
// table cell selections are always 'Cell'
'Cell' === item.constructor.name
// two rows
&& 2 === item.rows.length
// rows are first and second
&& 0 === item.rows[0].index
&& 1 === item.rows[1].index
// both whole rows are selected
//&& item.cells.length == item.rows.everyItem().cells.length
)
alert('You have selected the top two rows of the table.');
Copy link to clipboard
Copied
I'll modify my point above.
Copy link to clipboard
Copied
If you're not sure what you have selected, try run this script (and keep it handy):
alert(app.activeDocument.selection[0].constructor.name);
Copy link to clipboard
Copied
I still don't understand your points.
Copy link to clipboard
Copied
I'll modify my point above.
It should be understandable this time.
Thank you very much.
Copy link to clipboard
Copied
Hello,
that fits a situation where the user is supposed to select something — but hasn’t selected anything at all.
"Please select an image frame." – Very specific, applies only to images.
"Please select the text." – Generic, but only applies to a text selection.
"Please place the cursor in the frame." – Requires cursor placement, not selection.
"Please select the top two rows of the table." – Very specific again, not general.
"Please place the cursor in the table row." – Again about cursor, not selection.
Best Regard,
Sally
Find more inspiration, events, and resources on the new Adobe Community
Explore Now