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

JavaScript Script: Trigger Action through ENTER key of Path Deselection

Explorer ,
Nov 06, 2020 Nov 06, 2020

[Using PS 2019 on Windows 10]

 

What I am trying to achieve is to rasterize the current path when it is confirmed.

if(app.currentTool == "penTool") {
//when path is "confirmed", through hitting ENTER or pressing ctrl+LMB
app.activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}

 This could also be achieved by checking: 

if(/*amount of pathPoints>0 && no pathPoint selected*/) {
app.activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
}

Unfortunately, I haven't been successful with either method. Any pointers? I am very new to PS scripting.

 

Hope this makes sense!

TOPICS
Actions and scripting
624
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 2 Correct answers

Guide , Nov 06, 2020 Nov 06, 2020

Use notifications to activate the script at the right moment (the code must be saved to disk before running, since the path to the script file is used when adding a notification).

So I understand that we are not talking about paths, but about the shape layer. This imposes certain quirks, since the shape layer is a layer, not a path.
The example rasterizes the unfinished shape layer path by pressing enter. When deselecting a layer, the common for layers notification "selectNoLayers" is used, howeve

...
Translate
LEGEND , Nov 06, 2020 Nov 06, 2020

 

if (name.split('Photoshop').length - 1 && !$.getenv('not')) $.setenv('not', 1), notifiers.add('slct', File($.fileName), 'Path')
else if(arguments && currentTool == 'penTool') arguments = runMenuItem(stringIDToTypeID('rasterizeShape'))

 

Save above script (without targeting it) in:

\c\Program Files (x86)\Common Files\Adobe\Startup Scripts CC\Adobe Photoshop

 

Then launch Ps, so it will be taken to notifiers memory automatically. It will work on layer when Pen Tool is chosen, and shape closed, l

...
Translate
Adobe
Explorer ,
Nov 06, 2020 Nov 06, 2020

To clarify:

jaschag_0-1604679695972.pngexpand image

I have a path as seen above. As soon as I confirm it through Enter or deselection I want the path to be rasterized.

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
Guide ,
Nov 06, 2020 Nov 06, 2020

Use notifications to activate the script at the right moment (the code must be saved to disk before running, since the path to the script file is used when adding a notification).

So I understand that we are not talking about paths, but about the shape layer. This imposes certain quirks, since the shape layer is a layer, not a path.
The example rasterizes the unfinished shape layer path by pressing enter. When deselecting a layer, the common for layers notification "selectNoLayers" is used, however, additional logic is required to track which layer was deselected from (try to do it yourself - at the moment I don't have enough free time).

#target photoshop

try { var evt = arguments[0] } catch (e) { }

if (evt) {
    if (app.currentTool == "penTool") {
        app.activeDocument.activeLayer.rasterize(RasterizeType.ENTIRELAYER);
    }
} else {
    app.notifiersEnabled = true
    var f = File($.fileName)
    app.notifiers.add('slct', f, '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 ,
Nov 06, 2020 Nov 06, 2020
LATEST

 

if (name.split('Photoshop').length - 1 && !$.getenv('not')) $.setenv('not', 1), notifiers.add('slct', File($.fileName), 'Path')
else if(arguments && currentTool == 'penTool') arguments = runMenuItem(stringIDToTypeID('rasterizeShape'))

 

Save above script (without targeting it) in:

\c\Program Files (x86)\Common Files\Adobe\Startup Scripts CC\Adobe Photoshop

 

Then launch Ps, so it will be taken to notifiers memory automatically. It will work on layer when Pen Tool is chosen, and shape closed, lastly an enter hit. You may also save the script at end of other location, to which (or folder it's in) you'll link from said path, or include the path to your script(s), or else use $.evalFile() instead with that other 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