• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Prompting without prompting and direct selection

Advisor ,
Dec 23, 2016 Dec 23, 2016

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 {

};

TOPICS
Scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Engaged ,
Dec 24, 2016 Dec 24, 2016

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;

  }

}) ();

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 24, 2016 Dec 24, 2016

Copy link to clipboard

Copied

What is _isTextMode ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 24, 2016 Dec 24, 2016

Copy link to clipboard

Copied

when

selection.typename == 'TextRange'; // true

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 24, 2016 Dec 24, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 24, 2016 Dec 24, 2016

Copy link to clipboard

Copied

o-marat, Are isTextMode & _isNoSel variables ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 24, 2016 Dec 24, 2016

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...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 24, 2016 Dec 24, 2016

Copy link to clipboard

Copied

Ah you're calling the functions isTextMode function within the selectionCases function

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 24, 2016 Dec 24, 2016

Copy link to clipboard

Copied

How can you verify if a meshItem is selected since it doesn't have a property or method ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 24, 2016 Dec 24, 2016

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 24, 2016 Dec 24, 2016

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;

  }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 25, 2016 Dec 25, 2016

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 ?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 25, 2016 Dec 25, 2016

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 25, 2016 Dec 25, 2016

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 26, 2016 Dec 26, 2016

Copy link to clipboard

Copied

it's this?

var GrdntMesh = mDoc.meshItems[0];

GrdntMesh.selected = true; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 26, 2016 Dec 26, 2016

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");

}

  }

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 26, 2016 Dec 26, 2016

Copy link to clipboard

Copied

LATEST

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"); 

//  } 

}; 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines