Copy link to clipboard
Copied
Good Morning Everyone,
I'm wondering how I can go about Selecting Inverse within a Script.
Thanks for your help with this!
Copy link to clipboard
Copied
Copy link to clipboard
Copied
There are more useful commands here:
https://community.adobe.com/t5/illustrator-discussions/js-cs6-executemenucommand/td-p/5904747
Copy link to clipboard
Copied
@jduncan 's solution is the best one.. For the sake of completeness, here's the worst solution i could come up with on the spot:
https://www.youtube.com/watch?v=6TgC1jWDQOs
function selectInverse ()
{
var nonSelectedItems = [];
for ( var x = 0; x < app.activeDocument.pageItems.length; x++ )
{
alert( "Checking item " + x + " of " + app.activeDocument.pageItems.length );
alert( "Testing whether item " + x + " is selected" );
if ( !confirm( "Do you want to continue?" ) ) return;
if ( app.activeDocument.pageItems[ x ].selected == false )
{
alert( "Item " + x + " is not selected" );
alert( "Adding item " + x + " to array of non-selected items" );
if ( !confirm( "Do you want to continue?" ) ) return;
app.activeDocument.pageItems[ x ].note = x;
nonSelectedItems.push( app.activeDocument.pageItems[ x ] );
}
else
{
alert( "Item " + x + " is selected" );
alert( "This item will be deselected." );
if ( !confirm( "Do you want to continue?" ) ) return;
}
app.redraw();
}
alert( "Successfully added all non-selected items to array" );
alert( "Deselecting all items" );
for ( var x = 0; x < app.activeDocument.pageItems.length; x++ )
{
alert( "Deselecting item " + x + " of " + app.activeDocument.pageItems.length );
if ( !confirm( "Do you want to continue?" ) ) return;
app.activeDocument.pageItems[ x ].selected = false;
app.redraw();
}
alert( "Successfully deselected all items" );
for ( var x = 0; x < app.activeDocument.pageItems.length; x++ )
{
alert( "Checking item " + x + " to see whether it should be selected." );
if ( !confirm( "Do you want to continue?" ) ) return;
for ( var y = 0; y < nonSelectedItems.length; y++ )
{
alert( "Checking item " + x + " against item " + y + " of non selected items array" );
if ( !confirm( "Do you want to continue?" ) ) return;
if ( app.activeDocument.pageItems[ x ] === nonSelectedItems[ y ] )
{
alert( "Item " + x + " is the same as item " + y + " in the non-selected items array" );
alert( "Selecting item " + x );
if ( !confirm( "Do you want to continue?" ) ) return;
app.activeDocument.pageItems[ x ].selected = true;
}
else
{
alert( "Item " + x + " is not the same as item " + y + " in the non-selected items array" );
alert( "Item " + x + " will not be selected" );
if ( !confirm( "Do you want to continue?" ) ) return;
}
}
}
}
selectInverse();