Highlighted

JavaScript Script: Trigger Action through ENTER key of Path Deselection

Community Beginner ,
Nov 06, 2020

Copy link to clipboard

Copied

[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, Problem or error

Views

78

Likes

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

JavaScript Script: Trigger Action through ENTER key of Path Deselection

Community Beginner ,
Nov 06, 2020

Copy link to clipboard

Copied

[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, Problem or error

Views

79

Likes

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
Nov 06, 2020 0
Community Beginner ,
Nov 06, 2020

Copy link to clipboard

Copied

To clarify:

jaschag_0-1604679695972.png

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

Likes

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
Reply
Loading...
Nov 06, 2020 0
Enthusiast ,
Nov 06, 2020

Copy link to clipboard

Copied

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')
}

 

Likes

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
Reply
Loading...
Nov 06, 2020 0
Adobe Community Professional ,
Nov 06, 2020

Copy link to clipboard

Copied

Save above script (without targeting it) in:

 

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

 

Then launch Ps, o 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.

 

 

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

 

 

Likes

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
Reply
Loading...
Nov 06, 2020 1