Copy link to clipboard
Copied
Is it possible to check in the background if the user has selected a gradient mesh without prompting the user to select a gradient mesh and only prompt the user to
select a gradient mesh once ? I can't find in the reference guide how to select the direct selection tool ?
var GrdntMesh = mDoc.meshItems.selection = 0;
if (GrdntMesh == 0); {
prompt("Choose a Gradient Mesh Shape");
} else {};
Copy link to clipboard
Copied
test 'what is selected'
(function selectionCases() {
if ( _isTextMode () && _isNoSel () ) {
alert ( 'mode editing text, nothing is selected' );
} else if ( _isTextMode () && !_isNoSel () ) {
alert ( 'mode editing text, something is selected' );
} else if ( !_isTextMode () && _isNoSel () ) {
alert ( 'mode editing objects, nothing is selected' );
} else if ( !_isTextMode () && !_isNoSel () ) {
alert ( 'mode editing objects, something selected' );
alert (selection[0]);
}
function _isTextMode () { // mode editing text
return typeof selection.contents == 'string';
}
function _isNoSel () { // nothing is selected
return selection.length === 0;
}
}) ();
Copy link to clipboard
Copied
What is _isTextMode ?
Copy link to clipboard
Copied
when
selection.typename == 'TextRange'; // true
Copy link to clipboard
Copied
StrongBeaver , you want to catch the event, at the time when the user has selected something by a Selection Tool?
New
Or run a script that checks which object is selected at the time of launch?
Using Illustrator ExtendScript perhaps only the second variant.
Copy link to clipboard
Copied
o-marat, Are isTextMode & _isNoSel variables ?
Copy link to clipboard
Copied
In JavaScript 'function is a value'.
This functions return values of type Boolean (all function that name begins to 'is' must returns boolean value);
Function is not a variable, it's a Object of class Function, but when function completed it becomes the returned value. In this case boolean true or false.
Like that... ![]()
Copy link to clipboard
Copied
Ah you're calling the functions isTextMode function within the selectionCases function ![]()
Copy link to clipboard
Copied
How can you verify if a meshItem is selected since it doesn't have a property or method ?
Copy link to clipboard
Copied
Maybe I misunderstood something...
for example:
if (selection[0].typename == 'MeshItem') // true or false
Is not that what you want?
Copy link to clipboard
Copied
If rewrite the function in your first post:
try {
duplicateAndMoveMesh(selection[0]);
} catch (e) {
alert(e); // something errors case
}
function duplicateAndMoveMesh(sel) {
var msg = 'Select Gradient Mesh object and run script again';
if (!_isTextMode() && !_isNoSel()) {
if (sel.typename == 'MeshItem') { // mode editing objects, something selected
// do something with mesh
var dpl = sel.duplicate();
dpl.translate(sel.width + 10, 0, true, true, true, true);
}
} else if (_isTextMode() && !_isNoSel()) { // mode editing text, something is selected
alert(msg);
} else if (!_isTextMode() && _isNoSel()) { // mode editing objects, nothing is selected
alert(msg);
} else if (_isTextMode() && _isNoSel()) { // mode editing text, nothing is selected
alert(msg);
}
function _isTextMode() { // mode editing text
return typeof selection.contents == 'string';
}
function _isNoSel() { // nothing is selected
return selection.length === 0;
}
}
Copy link to clipboard
Copied
Gradient Mesh has a method for selected but can you not assign a Boolean and leave it empty and let a condition or try clause let that be the decision maker whether it's true or false ?
Copy link to clipboard
Copied
I think now I'm not understand what is needed and what targets... %\
Perhaps will answer the one who understood.
I need more detailed and simple description of your workflow.
Copy link to clipboard
Copied
I can't use the following code;
var GrdntMesh = mDoc.meshItems.selected;
because the method selected requires a Boolean property. I was wondering if I could leave the above line but let the Boolean property of selected be decided based on a condition / try clause ? If I'm approaching this wrong, sorry ![]()
Copy link to clipboard
Copied
it's this?
var GrdntMesh = mDoc.meshItems[0];
GrdntMesh.selected = true;
Copy link to clipboard
Copied
Hrm, Sill that may have worked, and I say may as I don't know whether I can nest a condition into a try clause, I keep getting an error ?
var GrdntMesh = mDoc.meshItems[0];
try {
if (GrdntMesh.selected = 1) {
alert("Gradient Mesh is selected");
} else {
catch{
(GrdntMesh.selected = 0); {
alert("Please Select a Gradient Mesh");
}
}
};
Copy link to clipboard
Copied
Wrong syntax
var GrdntMesh = app.activeDocument.meshItems[0];
//try {
if (GrdntMesh.selected == true) {
alert("Gradient Mesh is selected");
} else {
//catch{
if (GrdntMesh.selected == false); {
alert("Please Select a Gradient Mesh");
}
// }
};
Find more inspiration, events, and resources on the new Adobe Community
Explore Now