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

Script to select next path in the Paths panel and use Insert Path menu item from Actions panel

Community Expert ,
Feb 10, 2022 Feb 10, 2022

I need script for very boring task if possible to automate at least something in this work which consist of several thousand repeats multiplied by 5 steps. In essence I am replacing Set Work Path step with new path. Here are steps I am taking to accomplish task:

 

  • Select Set Work Path step in action
  • Select next path in Paths panel
  • Use Insert Path from Actions panel menu
  • Select previous action step Set Work Path
  • Delete Set Work Path
  • Select next Set Work Path step in action
  • Repeat....

select next path and insert path item.jpg

TOPICS
Actions and scripting , Windows
3.2K
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

correct answers 1 Correct answer

Community Expert , Feb 10, 2022 Feb 10, 2022
// select next path;
// 2020, use it at your own risk;
if (app.documents.length > 0) {
var thisPathIndex = selectedPath ();
if (thisPathIndex != null) {
    if (thisPathIndex == activeDocument.pathItems.length) {thisPathIndex = 1}
    else {thisPathIndex++};
    var desc28 = new ActionDescriptor();
        var ref5 = new ActionReference();
        ref5.putIndex( stringIDToTypeID( "path" ), thisPathIndex );
    desc28.putReference( stringIDToTypeID( "null" ), ref5 );
executeAction( stringIDToType
...
Translate
Adobe
Community Expert ,
Feb 10, 2022 Feb 10, 2022

@Bojan Živković – I'd like to help, but I don't know where/how to start?

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 ,
Feb 10, 2022 Feb 10, 2022

Please watch just posted video explanation.

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 ,
Feb 10, 2022 Feb 10, 2022

One could include the »Insert Path«-paths into a Script, how many different Paths are there? 

Do you use them just for creating Selections or something else, too? 

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 ,
Feb 10, 2022 Feb 10, 2022

I am replacing exactly 100 paths. Thats one action which serves as template. Everything is the same beside paths. I am replacing paths or recording new path outline using Insert Path and deleting old path outline or existing Set Work Path step.

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 ,
Feb 10, 2022 Feb 10, 2022

Sorry, I do not understand. 

 

What about the Work Path? 

Which paths exist? 

What do they get replaced with? 

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 ,
Feb 10, 2022 Feb 10, 2022

I just posted video explanation.

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

No showed action set and not explained which 'Set Work Path' items are previous / next to each other.

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 ,
Feb 10, 2022 Feb 10, 2022

I have action which serves as template. There are 100 Set Work Path steps and 100 path outlines in the Paths panel. Each time I am selecting next or below Set Work Path step, also selecting below path outline in Paths panel then using Insert Path to record new Set Work Path step which will be recorded just below existing Set Work Path step. I must select and delete original Set Work Path step....

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

It'll be easier to help if you share the action with a file to try it on.

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 ,
Feb 10, 2022 Feb 10, 2022

Of course I will, watch this video and if you still need action and file will upload https://www.screencast.com/t/9DikEWrmN2

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

Combining it with action makes it harder to do. The sole script would be sufficient.

Which repetable steps of your manual doings you would like to be written to script?

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 ,
Feb 10, 2022 Feb 10, 2022

You mean it is difficult to select step in action and delete it? I would like, as mentioned in video, to have script that will:

 

  • Select next or below path in Paths panel
  • Use Insert Path menu item to insert curently selected path into action step
  • Select previous step in action
  • Delete curently selected step in action

 

At least 2 adjacent steps of above 4 must be included because there is shortcut for Insert Path menu item.

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

It's harder, so I mean what (not actions) steps you'd include as another commands of script.

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 ,
Feb 10, 2022 Feb 10, 2022

None, that is enough, 4 steps above mentioned.

Ideally, 5th step will be to select next below instance of Set Work Path and repeat but that is probably too much and it needs to stop with loop at some point. There are actually 100 Set Work Path steps but that would be tooo much. I need only to insert paths nothing else shoould be changed, all other steps remains the same all the time and nothing else is needed.

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

I don't need to know what action steps are. Forget about them, just say what steps starting from 3rd are your manual doings to make from them a looped code.

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 ,
Feb 10, 2022 Feb 10, 2022

After inserting path using Insert Path which will create new step Set Work Path. Now I have 2 steps Set Work Path one below another where bottom one is selected. My manual doing is:

  • Select previous step in action (that is Set Work Path)
  • Delete curently selected step in action
  • Select next actually first below instance of step: Set Work Path
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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

You don't understand me 🙂 I don't want to do it involving the action, only the script and nothing else. So if you'll describe single sequence, I'm going to make the script from. Imagine you do it without action, all manually within one path item yet, step by step (with no action).

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 ,
Feb 10, 2022 Feb 10, 2022

I do not understand you. I am recording action, action steps, without action and action steps involved script can't do much for me.

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

I wanted to avoid combining script with action, especially when you didn't share it to make it easier to recrate what you do. The script can do much more and easier than action so there is no need to use action together with script. Maybe someone else will explain what I mean...

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 ,
Feb 10, 2022 Feb 10, 2022

I asked for script to help me record action step if that is possible. I do not want script instead of action. 

I saw in scripting reference Next path so it is probably possible to select next or below path via script. Why not to use Insert Path menu item via script? I guess and that is possible. Not sure if script can select previous/next step in action but it should be able to delete step in action.

 

Above is presented only 1,4% of entire action and it has 100 Set Work Path steps. I am recording 100 by 100 steps. I will merge later all parts. I must record action, script instead of action is not an option. 

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
LEGEND ,
Feb 10, 2022 Feb 10, 2022

Okay, so you want to do it by action, replace indicated items. That's possible to do by script how ever I don't play with actions anymore, so I would have to refresh my memory. Instead that I can propose you simple script that takes to memory all (100) paths and for each execute short 4 steps codes. That let you make one repetitive loop for all your paths. As to the Action & Script I'm sure 2 other participants of this thread help you soon 😉

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 ,
Feb 10, 2022 Feb 10, 2022

It would need more complex scripting to loop through action steps and to connect 2 loops. Do not waste time, I do not think this will go that far. I would be satisfied with simple script which I will run over and over without complex loops.

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 ,
Feb 10, 2022 Feb 10, 2022

@Bojan Živković wrote:

 

I saw in scripting reference Next path so it is probably possible to select next or below path via script.


 

Bojan, what is this JS method for selecting next path?

 

I am not aware of a (relative) way to select paths in JS, I am only aware of the ability to select path by (absolute) name or by (absolute) index number.

 

Is there a keyboard shortcut as there is with layers?

 

P.S. It is probably easy for those with AM code knowledge to get the active path item index number, then +1 increment this value to select the next path index number in order to create a "relative select next path function", however, that is beyond my knowledge.

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 ,
Feb 10, 2022 Feb 10, 2022

 

I'm sure that this is more complex and verbose than it needs to be, however, I was happy to get this relative path selection function working:

 

Select Next Path:

 

selectNextPath();

function selectNextPath() {
    /* https://stackoverflow.com/questions/60677948/photoshop-javascript-get-selected-pathitem */
    var ref = new ActionReference();
    ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("TrgP"));
    ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref);
    desc.getInteger(charIDToTypeID("TrgP"));
    // Relative path selection
    try {
        var currPath = desc.getInteger(charIDToTypeID("TrgP"));
        $.writeln(currPath);
        var incr = desc.getInteger(charIDToTypeID("TrgP"));
                incr++;
        $.writeln(incr);
        app.activeDocument.pathItems[incr].select();
    } catch (error) {}
}

 

Select Previous Path:

 

selectPrevPath();

function selectPrevPath() {
    /* https://stackoverflow.com/questions/60677948/photoshop-javascript-get-selected-pathitem */
    var ref = new ActionReference();
    ref.putProperty(charIDToTypeID("Prpr"), charIDToTypeID("TrgP"));
    ref.putEnumerated(charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    var desc = executeActionGet(ref);
    desc.getInteger(charIDToTypeID("TrgP"));
    // Relative path selection
    try {
        var currPath = desc.getInteger(charIDToTypeID("TrgP"));
        $.writeln(currPath);
        var incr = desc.getInteger(charIDToTypeID("TrgP"));
		incr--;
        $.writeln(incr);
        app.activeDocument.pathItems[incr].select();
    } catch (error) {}
}

 

P.S. It would be nice to be able to do the same for channels as well, how to get channel id?

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