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

Prompting without prompting and direct selection

Advisor ,
Dec 23, 2016 Dec 23, 2016

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
2.0K
Translate
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

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;

  }

}) ();

Translate
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

What is _isTextMode ?

Translate
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

when

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

Translate
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

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.

Translate
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

o-marat, Are isTextMode & _isNoSel variables ?

Translate
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

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

Translate
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

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

Translate
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

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

Translate
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

Maybe I misunderstood something...

for example:

if (selection[0].typename == 'MeshItem') // true or false

Is not that what you want?

Translate
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

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;

  }

}

Translate
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

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 ?

Translate
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

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.

Translate
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

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

Translate
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

it's this?

var GrdntMesh = mDoc.meshItems[0];

GrdntMesh.selected = true; 

Translate
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

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

}

  }

};

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

//  } 

}; 

Translate
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