Skip to main content
Participating Frequently
June 27, 2022
Question

Script ran via actions does not select properly

  • June 27, 2022
  • 8 replies
  • 6411 views

Dear community,

 

I've written a small script which transforms text to outline and afterwards unites the paths via pathfinder. This works as intended when ran via File > Scripts. However, when I run the script via an action the text-path group isn't selected and thus pathfinder doesn't work.

 

var docRef = app.activeDocument;
var textFrames = docRef.textFrames;

// Failsafe
if (textFrames.length != 0) {
    text_to_path_and_unite(textFrames);
}

// Text to path and unite path
function text_to_path_and_unite(textFrames) {
    while (textFrames.length != 0) {
        // Deselect all layers
        app.executeMenuCommand("deselectall");

        // Select text && transform to path
        textFrames[0].selected = true;
        textFrames[0].createOutline();

        // Unite path via pathfinder
        app.executeMenuCommand("group");
        app.executeMenuCommand("Live Pathfinder Add");
        app.executeMenuCommand("expandStyle");
    }
}

 

Any suggestions on how to select the text-path group is appreciated.

 

Thanks in regards.

This topic has been closed for replies.

8 replies

Community Expert
June 29, 2022

@Muurstickerstunter  said: "Would any of you two know where I can report this bug to the Adobe team?"

 

Go to Illustrator UserVoice, log in with a new password and your Adobe ID and write a bug report there.

Provide a link to this discussion here for all the details. Feel free to use any of my screenshots…

https://illustrator.uservoice.com/forums/601447-illustrator-desktop-bugs

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Participating Frequently
June 29, 2022

Dear Laubender,

 

Many thanks for your response once again. I have created a post about the issue which can be found here:

https://illustrator.uservoice.com/forums/601447-illustrator-desktop-bugs/filters/new?category_id=209077

 

Lets hope the issue will be resolved soon.

 

Kind regards.

Community Expert
June 28, 2022

Hi @femkeblanco ,

how exactly did you test the action?

I did it this way:

[1] Recorded the action ( at this point all was working as expected. )

[2] Closed the document without saving.

[3] Opened the document and ran the action for testing:

Here I had the issue with that Info message and the wrong result.

 

I also quit Illustrator, opened Illustrator again, opened the document and ran the saved action again.

This time I had no info message, but unfortunately the same wrong results:

In one case it worked, not so in the other two ones of the test document.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

femkeblanco
Brainiac
June 28, 2022

Hi @Laubender 

 

I have the script in the Scripts folder, such that it appears on the list of scripts in File > Scripts. (If it was a new script, I would have had to close and open Illustrator for it to appear on the list.)  To record the script in an action, I select the action in the Action panel, click the panel menu in the upper right corner, click "Insert Menu Item..." and enter the name of the script. Then I play the action. At this point, closing and opening the document shouldn't affect things.

Community Expert
June 28, 2022

Thanks. That's exactly the same that I did.

 

After recording and saving the action I quit Illustrator, opened it again and tested the action on the OP's test document that is attached with the wrong suffix *.pdf here:

https://community.adobe.com/t5/illustrator-discussions/script-ran-via-actions-does-not-select-properly/m-p/13034791#M326450

Download the file, rename it to *.ai and you are good to go for testing. Well, had to activate a fonts style from Adobe Fonts before I actually did my tests.

 

That all said:

What is your localized version of Illustrator 2022 on what operating system?

Perhaps we see a difference because of that?

I'm with the German Illustrator 2022 version 26.3.1 on Windows 10.

 

Thanks,
Uwe Laubender
( Adobe Community Professional )

 

Community Expert
June 28, 2022

Hi @femkeblanco ,

tested your script code on my German Illustrator 2022 on Windows 10.

Running the script from menu File > Scripts > scriptname

was successful.

 

When I executed an action for this menu command I went into trouble.

Info message is reading:

"Now another instance of this effect will be applied. You can edit the current effect if you double-click on the effect in the Appearance panel". Blue button is reading: "Apply new effect".

 

If I do this and apply the new effect by pressing the blue button, the result is this:

 

In one case the desired result was achieved!

Not so in the other two cases.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Community Expert
June 28, 2022

Hi Muurstickerstunter,

thank you very much for your sample files.

 

I can confirm your issue.

If I execute your script code or mine using the GUI with

File > Scripts > nameOfScript

it works as expected:

 

 

As soon as I record a new action using a menu command that points to the menu nameOfScript the result is different. The menu commands "Live Pathfinder Add" and also "expandStyle" are not executed.

 

 

Note: My guess is that we should use ExtendScript DOM commands instead of menu commands to achieve what you want. But I still cannot see any DOM support for pathfinder and expand style. I hope, I'm wrong on this…

 

So I am out of ideas now.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

 

femkeblanco
Brainiac
June 28, 2022

Selecting and deselecting everything at the beginning of the script (as in the script I posted) solves the problem for me, producing the same result both ways. 

femkeblanco
Brainiac
June 27, 2022

I presume this is a bug with actions.  See if this works. 

app.executeMenuCommand("selectall");
app.selection = null;

var docRef = app.activeDocument;
var textFrames = docRef.textFrames;

// Failsafe
if (textFrames.length != 0) {
    text_to_path_and_unite(textFrames);
}

// Text to path and unite path
function text_to_path_and_unite(textFrames) {
    while (textFrames.length != 0) {
        // Deselect all layers
        // app.executeMenuCommand("deselectall");

        // Select text && transform to path
        // textFrames[0].selected = true;
        // textFrames[0].createOutline();
        var outline = textFrames[0].createOutline();
        outline.selected = true;

        // Unite path via pathfinder
        // app.executeMenuCommand("group");
        app.executeMenuCommand("Live Pathfinder Add");
        app.executeMenuCommand("expandStyle");
        app.selection = null;
    }
}
Participating Frequently
June 28, 2022

Dear Femkeblanco,

 

Thank you for your response! Sadly your script doesn't seem to fix my issue. I have written a detailed response to the commenter above.

 

I am open to all ideas and suggestions on how to fix this issue.

 

Thank you in regards.

Community Expert
June 27, 2022

textFrames[0].createOutline() should return a group if the text frame is not empty.

So the following code will grab the group and select it:

 

		// Select text && transform to path
		textFrames[0].selected = true;
		var returnedGroup = textFrames[0].createOutline();

		returnedGroup.selected = true;

 

See DOM documentation:

https://www.indesignjs.de/extendscriptAPI/illustrator-latest/#TextFrameItem.html#d1e59890__d1e60312

 

However, I think we can run into issues if a text frame is empty.

In that case, should the script do something to a frame like that?

 

If you still try to createOutlines() on an empty frame you will provoke an info message to the user.

To tackle this you have to set the app.userInteractionLevel to value UserInteractionLevel.DONTDISPLAYALERTS and set it back again after all text frames are visited and converted. The empty ones will be missing after that!

 

Note: If you prevent the function to work at all with empty text frames, you will get into deep trouble with your while loop, because the number of text frames in the document will never become zero. The same will be true, if Illustrator is not able to convert a frame to outlines for whatever reasons and the frame will still exist in the document after createOutlines() was done. Risky…

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Participating Frequently
June 28, 2022

Dear Laubender,

 

Thank you for your responses and excuse me for my late reply. The script indeed runs perfectly via File > Scripts. However, it doesn't seem to run correctly via actions. At least, partly. I would like to keep the text (or rather pathfinded path) on the same layer as it was originally and seperated from each other. The main issue I run into currently is the pathfinder not working.

 

I have added 4 files as requested:

  • The original file;
  • The wanted outcome (ran via File > Scripts);
  • The outcome I get when the main layer is selected;
  • The outcome I get when no or one of the sub-layers is selected.

 

Please note that you might need to download the font "Great Vibes", this font overlays letters and thus shows the wished outcome. It seems to me like a script ran via the actions menu doesn't select and deselect layers properly. But this is only a hypothesis.

 

Also thank you for your note, I didn't think of that! I'll definitely be sure to add some kind of check when we have found the issue.

 

Thank you for your time.

Community Expert
June 28, 2022

Can we assume that the attached pdf files are indeed ai files?

( Because the forum software has trouble to attach ai files ?! )

 

Thanks,

Uwe Laubender
( Adobe Community Professional )

Community Expert
June 27, 2022

Hi Muurstickerstunter,

tested your code on a very simple Illustrator document with some text frames on the artboard.

It ran without any problems.

 

Before:

 

After the script run:

When nothing is selected:

 

So I think we need a sample file from you where you see an issue.

 

Regards,
Uwe Laubender
( Adobe Community Professional )

Community Expert
June 27, 2022

Hi Muurstickerstunter,

can you post a small sample document where your code went wrong?

Also one with the desired result.

 

I'd like to test something…

 

Thanks,
Uwe Laubender
( Adobe Community Professional )